 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Cached Search ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 ;; TODO: split refine into PartialResult type, always give new reward -- more accurate.
-;; TODO: 
 
 (defn make-cached-search-factory
   "Return a cache-fn, where (cache-fn) returns fresh IncrementalSearch views on

  SearchNode
  (extract-goal-state []  nil)
  (expand-node        [min-reward]
    (let [result (next-solution-or-cutoff subproblem min-reward)]
      (if (number? result) 
          [[this result]]
        [[this (nth result 1)]
         (make-sp-recursive-node result remaining-actions)]))))

;; TODO: lazy
(defn make-initial-sp-nodes [state action]
  (if (env/primitive? action)
    (when-let [[ss sr] (and (env/applicable? action state) (env/successor action state))]

     (let [context          (env/precondition-context f state)
           state-in-context (env/extract-context state context)
           sub-name         [state-in-context (env/action-name f)]
           sup-name         [state-in-context (map env/action-name remaining-actions)]]
       (SPRecursiveNode sup-name
         (delay 
          (make-search-in-context 
           (get-cached-search sub-name 
             (make-incremental-dijkstra-search
              (make-initial-sp-nodes (env/get-logger state context) f)))
           state reward))
         r))
     (GoalNode state))
   reward])

