 (defn make-incremental-dijkstra-search [initial-nodes]
   (let [q (make-queue initial-nodes)]
     (reify IncrementalSearch
-      (next-partial-solution [min-reward]
-        (incremental-dijkstra q min-reward expand-node extract-goal-state)))))
+           (next-partial-solution [min-reward]
+             (incremental-dijkstra q min-reward expand-node extract-goal-state)))))
+
 
 
 ;; TODO: need "generalized-goal" dijkstra search.  
+;; TODO: single-goal.
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Exhaustive Search ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Outcome maps ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(defn make-descendents [state action prim-constructor ref-constructor]
  (if (env/primitive? action)
      (when-let [[ss sr] (and (env/applicable? action state) (env/successor action state))]
        [(prim-constructor (vary-meta ss assoc :opt [action]) sr)])
    (map ref-constructor (hierarchy/immediate-refinements action state))))

(defn generalize-outcome-pair [[outcome-state reward] gen-state reward-to-gen-state]
  [(vary-meta (env/apply-effects gen-state (env/extract-effects outcome-state)) assoc 
              :opt (concat (:opt (meta gen-state)) (:opt (meta outcome-state))))

  (hashCode [] (hash name))
  SearchNode
  (extract-goal-state []  nil)
  (expand-node        [min-reward] (expand-fn this min-reward)))


(defn make-node-descendant [parent & args]
  (apply make-search-node :recursive args))

(defn make-recursive-expander [sp more-actions]
  (fn sp-recursive-expand [this min-reward]
      (let [{:keys [result-pairs max-reward]} (next-partial-solution (force sp) min-reward)]
        (PartialResult (map #(make-node-descendant this % more-actions) result-pairs) max-reward))))

;(def #^IFn node-type-policy)

(defn make-search-node [type [state reward :as result] remaining-actions]
  [(if-let [[f & r] (seq remaining-actions)]
       (NamedNode [state (map env/action-name remaining-actions)]
         (case type
          :transparent          
            (fn sp-transparent-expand [this min-reward]
              (PartialResult
               (if (env/primitive? f)
                 (when-let [[ss sr] (and (env/applicable? f state) (env/successor f state))]
                   [(make-node-descendant this [(vary-meta ss assoc :opt [f]) (+ sr reward)] r)])
                 (for [ref (hierarchy/immediate-refinements f state)]
                   (make-node-descendant this [state reward] (concat ref r))))
               Double/NEGATIVE_INFINITY))
          :recursive            
            (make-recursive-expander 
             (delay (make-abstracted-incremental-dijkstra-sa-search state reward f)) r)          
          :recursive-exhaustive 
            (make-recursive-expander 
             (delay (make-abstracted-exhaustive-dijkstra-sa-search state reward f)) r)))
     (GoalNode state))
   reward])






;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Semi-Transparent Node ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
