 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; State-Abstracted Search ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
+(defn lift-partial-result [partial-result context-state context-reward]
+  (let [{:keys [result-pairs max-reward]} partial-result]
+    (PartialResult (map #(generalize-outcome-pair % context-state context-reward) result-pairs)
+                   (+ max-reward context-reward))))
+
 (defn make-search-in-context [subsearch context-state context-reward]
   (reify IncrementalSearch
-    (next-solution-or-cutoff [min-reward]
-      (let [result (next-solution-or-cutoff subsearch (- min-reward context-reward))]
-        (if (number? result) (+ result context-reward)
-          (generalize-outcome-pair result context-state context-reward))))))
+    (next-partial-solution [min-reward]
+      (lift-partial-result (next-partial-solution subsearch (- min-reward context-reward))
+                           context-state context-reward))))
 
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

          init (env/initial-logging-state e)
          tla  (hierarchy/TopLevelAction e [(hierarchy/initial-plan henv)])
          top  (make-incremental-dijkstra-search (make-initial-sp-nodes init tla)) 
          result (next-solution-or-cutoff top Double/NEGATIVE_INFINITY)]
      (when (not (number? result))
        (second result)))))

;; For SAHA, nothing is open.
;  Or strcture is same.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defprotocol IncrementalSearch 
  (next-partial-solution [sp min-reward]
     "Output is PartialResult, where results are states."))

(declare extract-goal-state expand-node)

