 ;; TODO: summaries making it into child-pointers
 
 
-(defn osn-plan-summary [osn] (apply max-summary (map :summary (:plans osn))))
-(defn osn-child-summary [osn ecs] (apply max-summary (map full-osp-summary (remove ecs (:child-pointers osn)))))
-(defn osn-summary [osn ecs] (max-summary (osn-plan-summary osn) (osn-child-summary osn ecs)))
-
-(def osn-child-pointers :child-pointers)
-(defn osn-add-plans [osn plans] (update-in osn [:plans] concat plans))
+(defn osn-plan-summary 
+  "Summary of the plans stored directly at this osn"
+  [osn] (apply max-summary (map :summary (:plans osn))))
+
+(defn osn-child-summary
+  "Summary of non-excluded descendents of this osn"
+  [osn ecs] (apply max-summary (map full-osp-summary (remove ecs (:child-pointers osn)))))
+
+(defn osn-summary [osn ecs]
+  "Summary of direct plans plus non-excluded descendents."
+  (max-summary (osn-plan-summary osn) (osn-child-summary osn ecs)))
+
+
+(defn osn-add-plans [osn plans]
+  "Return a new OSN with the new plans added.  Presumed mutex output sets."
+  (update-in osn [:plans] concat plans))
 
 ;; osn/osp
 (defn merge-children


(defn make-live-for-split [sub-osp ecs summary]
  (if (and (blocked? summary) (can-split-osp? sub-osp ecs))
    (make-live-summary (max-reward summary))
    summary))


(defn compute-plan-node-output-summary [input-summary sub-output-set-pointer ecs summary-bound]
  (->> (full-osp-summary sub-output-set-pointer)
       (min-summary summary-bound)
       (make-live-for-split sub-output-set-pointer ecs)
       (add-summaries input-summary)))

(defn make-plan-node [input-set input-summary sub-output-set-pointer
                      excluded-child-set output-constraint summary-bound]
  (PlanNode. sub-output-set-pointer excluded-child-set output-constraint summary-bound
             (compute-plan-node-output-set input-set sub-output-set-pointer output-constraint)
             (compute-plan-node-output-summary input-summary sub-output-set-pointer excluded-child-set summary-bound)))

(defn make-initial-plan-node [action [input-set input-summary]]
  (let [sub (get-subproblem-root-pointer input-set action (constantly is/pos-inf))]
    (make-plan-node input-set input-summary sub #{} {} +best-summary+)))

(defn plan-node-output-set-and-summary [pn]
  [(:output-set pn) (:output-summary pn)])

(def +worst-osp+ (TerminalOutputSetPointer. +worst-summary+ state-set/empty-lfss))

(declare active-osp-summary)
(defrecord OutputSetPointer [subproblem parent-pointer output-set node-atom reward-bound]
  OSP
  (osp-summary [osp ecs] (active-osp-summary osp ecs))
  (osp-output-set [osp] output-set))


(defn make-child-osp [parent-osp output-set plans]
  (OutputSetPointer. (:subproblem parent-osp) parent-osp output-set (OutputSetNode. plans nil) is/pos-inf))

(defn osp-ancestors [osp]
  (when-let [p (:parent-pointer osp)]
