 ;; Also note: new input can have subset of variables of old. (=-state-sets does ntthis now).
 (defn- make-state-abstracted-subproblem [fs inner-sp inp-set]
   (when inner-sp
-   (make-wrapped-subproblem
-    (sa-name (:name inner-sp)) inp-set (fs/transfer-effects inp-set (:output-set inner-sp)) #{:OC} inner-sp
-    (fn [sp child-sp] (publish-child! sp (make-state-abstracted-subproblem fs child-sp inp-set))) 
-    (fn [sp ni] (if (fs/=-state-sets ni inp-set) sp (make-state-abstracted-subproblem fs (refine-input inner-sp ni) ni))))))
+    (let [ret (make-subproblem 
+               (sa-name (:name inner-sp))
+               inp-set (fs/transfer-effects inp-set (:output-set inner-sp))
+               (sp-ts inner-sp)
+               (fn [_] (throw (RuntimeException.)))
+               (fn [sp ni]
+                 (if (fs/=-state-sets ni inp-set) sp
+                     (let [log-ni (fs/get-logger fs ni)]                      
+                       (make-state-abstracted-subproblem fs (refine-input inner-sp log-ni) ni))))
+               sg/or-summary)]      
+      (connect-and-watch! ret inner-sp 
+       #(publish-child! ret (make-state-abstracted-subproblem fs % inp-set)))
+      ret)))
+
 
 (defmethod get-subproblem :SA [[_ inner-n :as n] inp-set]
-  (let [fs (atomic-name-fs (second inner-n))] 
-    (make-state-abstracted-subproblem fs (get-subproblem inner-n inp-set) inp-set)))
+  (let [fs (atomic-name-fs inner-n)] 
+    (make-state-abstracted-subproblem fs
+      (get-subproblem inner-n (fs/get-logger fs inp-set))
+      inp-set)))
+
+(defn log-input [fs inp-set] (if *state-abstraction* (fs/get-logger fs inp-set) inp-set))
+
+
+
 
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(declare refinement-names)

(defn- make-atomic-subproblem [fs inp-set]
  (let [[out-set reward status] (fs/apply-opt fs inp-set)]
    (when out-set
     (let [nm         (atomic-name fs)
	   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)))))))

(defmethod get-subproblem :Atomic [[_ fs :as n] inp-set] 
  (make-atomic-subproblem fs inp-set))          






;; (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))

