 ;; TODO: more generic propagation?  (We know: names, subs. relationships on sets.  Efficient lookups?)
 ;; TODO: children wait on one (or more) subsumption parents.
 
-
 ;;;;; Pessimistic
-;; TODO: add pessimistic variants (shared primitives)
-;; TODO: bounding pressimistic descritpions (assume consistency for now)
 ;; TODO: hook up pess/opt with same input set?
-;; TODO: pruning. 
+;; TODO: pruning. ?
+;; --> TODO: empty-set subproblems for pessimistic.
+;; --> TODO: Cannot propagate upper bounds from pessimistic subproblems
+;;           in the presence of sharing, since they may reflect other opt SPs.
 
 ;;;;; Tree construction
+;; -> TODO: dijkstra variants for cyclic actions ??
 ;; TODO: smarter output-collector (semantic) -- problems here though.
 ;; TODO: don't always split-left?
 ;; TODO: don't release children until they have lower reward or are primitive? 
+;;--> TODO: alternative child release strategies, e.g. wait 'til solved
 ;; TODO: make sure dead stuff can be GC'd
-;; TODO: alternative child release strategies, e.g. wait 'til solved
+;; TODO: note no difference between syntax and semantics for single state ...
 
 ;;;;; Summaries and solving 
 ;; TODO: lazy/pseudo-solve (regular seems impossible; bounds mean apparent decrease may be increase.

   #(let [n (fs/fs-name (second (sp-name %)))] (when-not (= (first n) :noop) n))))

;; ???
(defn solve-pess [opt-root choice-fn local?]
  (let [pess-root (sp-ts (refine-input (ts-sp opt-root) [:pess (second (input-set (ts-sp opt-root)))]))
        counter   (atom 0)]
    (def *pess-root* pess-root)

     (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 %))) 
       (add-sp-child! sp (make-output-collecting-subproblem fs inp-key child-sp) :irrelevant))) 
   (fn oc-refine-input [s ni]
     (let [ninp-key (get-input-key fs ni)]
       (cond (= inp-key ninp-key) s
             (and *share-terminal* (solved-terminal? inner-sp))
               (let [r (summary/max-reward (sg/summary inner-sp))
                     ret (make-subproblem (oc-name (sp-name inner-sp)) ni nil
                           (fn [_] (throw (RuntimeException.)))
                           (fn [_ _] (throw (RuntimeException.)))
                           (fn [s] (make-summary ni r :solved s r)))]
                 (assert (and (= :opt (first inp-key)) (= :pess (first ni))))
                 (set-output-set! ret [:pess (second (get-output-set! inner-sp))])
                 ret)               
             (= :Atomic (first (sp-name inner-sp)))
               (let [ret (get-ocs (sp-name inner-sp) fs ninp-key ni)]
                 (util/assert-is (not (identical? (canonicalize ret) inner-sp)) "%s" [(def *bad* [s inner-sp (input-set s) ni])])
                 (add-subsuming-sp! (canonicalize ret) inner-sp)
                 ret)  
             :else (make-output-collecting-subproblem fs ninp-key (refine-input inner-sp (log-input fs ni))))))))

(defn get-ocs [inner-n fs inp-key inp-set]
  (let [make-sp #(make-output-collecting-subproblem fs inp-key (get-subproblem inner-n (log-input fs inp-set)))]
