 
 
 
-;; (do (use 'angelic.util '[angelic env hierarchy] 'angelic.domains.nav-switch  'angelic.domains.discrete-manipulation 'angelic.search.implicit.dash-astar-opt-simple) (require '[angelic.search.summary-graphs :as sg] '[angelic.search.summary :as summary]) (defn s [x]  (sg/summarize x)) (defn sc [x] (summary/children x))  (defn src [x] (summary/source x)) (defn nc [x] (sg/child-nodes x)))
+;; (do (use 'angelic.util '[angelic env hierarchy] 'angelic.domains.nav-switch  'angelic.domains.discrete-manipulation 'angelic.search.implicit.dash-astar-opt-simple) (require '[angelic.search.summary-graphs-new :as sg] '[angelic.search.summary :as summary]) (defn s [x]  (sg/summarize x)) (defn sc [x] (summary/children x))  (defn src [x] (summary/source x)) (defn nc [x] (sg/child-nodes x)))
+
+;; (require '[angelic.search.implicit.dash-astar-opt :as dao])
 
 ;; (do (use 'clojure.test) (use 'angelic.test.search.implicit.dash-astar-opt-simple) (run-tests 'angelic.test.search.implicit.dash-astar-opt-simple))
 

(declare *state-abstraction*     ) ;; Use state abstraction?  Requires *decompose-cache*
(declare *propagate-subsumption* ) ;; Automatically propagate subsumption links to corresponding children


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;       Utilities      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(declare refinement-names)

(defn get-input-key [fs inp-set]
  (if *state-abstraction* (fs/extract-context fs inp-set) inp-set))

(defn- make-atomic-subproblem [fs inp-set]
  (let [nm (atomic-name fs)]
    (cache-under [nm (get-input-key fs inp-set)]
     (let [[out-set reward status] (fs/apply-opt fs inp-set)]
       (when out-set
         (let [summary-fn (atom #(make-summary reward status %))
               set-sf!    (fn [s f] (reset! summary-fn f) (schedule-decrease! s))] 
           (make-subproblem
            nm inp-set out-set nil
            (fn expand! [s]
              (util/print-debug 1 "expand" nm)
              (set-sf! s sg/or-summary) 
              (if-let [subsuming-sps (seq (remove terminal? (subsuming-sps s)))]
                (connect-and-watch! s (apply min-key (comp sg/get-bound sp-ts) subsuming-sps)
                  (fn [sub-child] (publish-child! s (refine-input sub-child inp-set)))) 
                (doseq [ref-name (refinement-names fs inp-set)] 
                  (publish-child! s (get-subproblem ref-name inp-set)))))     
            (fn [s ri]  #_ (assert (not *collect-equal-outputs*))  
              (if (= ri inp-set) s (get-subproblem nm  ri)))
            (fn summarize [s] (@summary-fn s)))))))))


;; TODO: handle state abstraction
;; TODO: should wrap pairs like this too?
(defmethod get-subproblem :Atomic [[_ fs] inp-set]
  (make-atomic-subproblem fs inp-set))          


