 
 (defn- connect-and-watch-ts! [p c out-f]
   (summaries/connect! p (sp-ts c))
-  (if (get-output-set c)
-    (do (out-f) false)
-    (do (add-output-watcher! c out-f) true)))
-
-;; TODO: subsumption should prevent child from gettong output before parent ??
-(defn- add-sp-child! [sp child-sp up?]
-   (util/print-debug 2 "AC" sp child-sp)
-;  (println sp child-sp) (Thread/sleep 100)
-   (when (canonical? sp)
-     (schedule-subsumption! (sp-ts sp) (sp-ts child-sp))
-    ;; TODO: propagate!
-     )
-   (if (and (get-output-set sp) (get-output-set child-sp))
-    (add-sp-child!* sp child-sp)
-    (do (summaries/connect! sp (sp-ts child-sp)) ;; Be safe; child could have children before we get output.
-        (add-output-watcher! sp 
-          (fn [] (add-output-watcher! child-sp
-                   (fn [] (util/assert-is (get-output-set sp) "%s" [sp child-sp])
-;                     (assert (empty? (get-children child-sp)))
-                     (add-sp-child!* sp child-sp) 
-                     (summaries/disconnect! sp (sp-ts child-sp))
-                     (schedule-decrease! sp)))))
-        (when up? (schedule-increase! sp)))))
+  (add-output-watcher! c out-f))
+
+
+
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  Constructors  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 

   identity
   (fn child-watch [sp child-sp] ;     (println sp child-sp (def *bad* [sp child-sp]))
     (if (=-state-sets (get-output-set! inner-sp) (get-output-set! child-sp))
       (do (schedule-increase! sp) (connect-and-watch! sp child-sp nil #(child-watch sp %))) ;; TODO: ???
       (add-sp-child! sp (make-output-collecting-subproblem fs inp-key child-sp) false)))
   (fn refine-input [s ni]
     (let [ninp-key (get-input-key fs ni)]
       (if (= inp-key ninp-key)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  Generic Trait  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;(def *out-count* (atom 1))

;; Canonical SPs are Atomic and Pair; wrappers use TS of inner SP.
(defn canonicalize [sp] (ts-sp (sp-ts sp)))
(defn canonical? [sp] (identical? sp (ts-sp (sp-ts sp))))

(defn notify-output-set! [w s] #_ (println "NO" s w) (w))
(defn notify-child! [w s c] #_ (println "NC" s c w) (swap! *out-count* inc) (w c))


;; Note subsumption following is a bit tricky, since we want access to all children
;; (including unpublished ones).
;; TODO: remove all-children if it doesn't help?
;; What we need is a 3-way dependence:
;; Child, sub child, sub link.?


(traits/deftrait simple-subproblem
  [nm inp-set wrapped-ts eval!-fn ri-fn]
  [                 ts-atom          (atom wrapped-ts)
   ^PubSubHub       output-ps        (make-pubsubhub)
   ^PubSubHub       child-ps         (make-pubsubhub)
   ^PubSubHub       all-child-ps     (make-pubsubhub)
   ^IdentityHashMap subsuming-sp-set (IdentityHashMap.)]
  [summaries/simple-cached-node]
  Subproblem
