changeset 328:35960b03693f

improved delayed-difference with memoization
author Robert McIntyre <rlm@mit.edu>
date Thu, 05 Apr 2012 15:05:08 -0500
parents fe6fd2323264
children a452deec2882
files clojure/com/aurellem/run/util.clj save-states/current-save.sav
diffstat 2 files changed, 4 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/run/util.clj	Thu Apr 05 12:59:30 2012 -0500
     1.2 +++ b/clojure/com/aurellem/run/util.clj	Thu Apr 05 15:05:08 2012 -0500
     1.3 @@ -62,17 +62,18 @@
     1.4                (recur test high)
     1.5                (recur low test))))))))
     1.6  
     1.7 +
     1.8  (defn delayed-difference
     1.9    [base alt delay difference-metric [moves root :as script]]
    1.10    (let [generator
    1.11          (memoize
    1.12 -         (fn [n]
    1.13 +         (fn gen [n] 
    1.14             (run-moves
    1.15              root
    1.16              (repeat n base))))
    1.17          len
    1.18          (binary-search
    1.19 -         (fn [n]
    1.20 +         (memoize (fn [n]
    1.21             (= (difference-metric
    1.22                 (run-moves
    1.23                  (generator n)
    1.24 @@ -80,7 +81,7 @@
    1.25                (difference-metric
    1.26                 (run-moves
    1.27                  (generator n)
    1.28 -                (repeat (inc delay) base))))))
    1.29 +                (repeat (inc delay) base)))))))
    1.30          new-moves (concat moves (repeat len base) [alt])
    1.31          new-state (run-moves (generator len) [alt])]
    1.32      [new-moves new-state]))
     2.1 Binary file save-states/current-save.sav has changed