 
 
 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Seq Subproblem ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-;; Tree summarizer represents semantic (stateless) bound on best solution of SP.
-;; Inner of SP represents best possible bound on any descendent subproblem not outputted yet.,
-;;   i.e., tree of any child subproblem
-;; Stub represents best possible tree of any output (not outputted yet!).
-
-;; TODO TODO: think about who connects to who'se tree.
-;; TODO: increase is OK as long as tree doesn't ? 
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;   Sequences    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 ;; This subproblem is allowed to die, (incl. tree?!), replaced by refinements at sp1. 
-(defn- make-right-subproblem [stub sp1 sp2]
+(defn- make-pair-subproblem [stub sp1 sp2]
   (make-simple-subproblem
    [::Pair (subproblem-name sp1) (subproblem-name sp2)]
    (input-set sp1) (output-set sp2)

;; A version of eval subproblems where we explicitly represent the relationships
;; between subproblems, and allow "listeners" that wait for a subproblem to be
;; evaluated.
;; Subproblems where the expand operation evaluates the output set, and generates
;; the children.  Putting the focus on evaluation gives us finer granularity,
;; allowing full utilizatino of subsumption, plus is more natural in a decomposed
;; setting where we also have to "evaluate" existing actions in new contexts.

;; TODO: assuming consistency and evaluation s.t. no bounding is necessary. Otherwise, downwards would be better anyway?

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Subproblem Protocol ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; A subproblem should also implement Summarizable and Refinable implementations.
;; The non-viable (pre-refinement) subproblem is always represented as nil.

;; Here, get-child and refine-input always return subproblems,
;; but output-set can return "nil"
;; get-child and refine-input are allow to return nil


(defprotocol OutputWatched
  (add-watcher!   [s w] "Add a watcher to be notified of all outputs to this.
                         A watcher is just a fn of [watched-sp/stub new-subproblem]."))

(defprotocol Evaluable
  (evaluate!      [s]))

(defn can-evaluate? [s]  (satisfies? Evaluable s))

(defprotocol Subproblem
  (subproblem-name   [s])
  (input-set         [s])
  (output-set        [s])
  (tree-summarizer   [s] "Summarizer that includes children."))

(defn sp-str [sp] (format  "#<Subproblem$%h %s>" (System/identityHashCode sp) (subproblem-name sp)) )
(defmethod print-method angelic.search.implicit.fah_astar_eval2.Subproblem [ss o] (print-method (sp-str ss) o))


(comment ; TODO: refine-input must go somewhere
  (refine-input      [s maybe-refined-input-set])  
  (refine-input-   [s refined-input-set] "must be a strict subset of input-set."))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Summarizers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

#_ (def  ^{:private true} cache-trait summaries/uncached-summarizer-node)
 (def ^{:private true} cache-trait summaries/eager-cached-summarizer-node)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Planning ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defn- choose-leaf [verified-summary]
;  (println "VS"  verified-summary) #_ (def *sum* verified-summary) (Thread/sleep 10)
  (->> (summary/extract-leaf-seq verified-summary (comp empty? summary/children))
;       util/prln
