 
 (defn sahucs-simple [henv]
   (hierarchical-search henv nil make-recursive-search))
+
+(defn sahucs-inverted [henv]
+  (hierarchical-search henv nil make-inverted-search))
 
 (defn saha-simple [henv]
   (hierarchical-search henv nil make-saha-search))

  (first (recursively-searchify-hfs (make-root-hfs state action))))



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SAHA ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Here, subsearches should only generate goal nodes. So, we only have to deal with 
; expanding the initial nodes we populate the search with.  These can be dummies. 

; Worry about refactoring later.


;; TODO: these should all be single-solution .
;; These caches cache erfinements, optimsitic descriptions, and solve final-state connection probelm
; Refinements and valuation for abstracted SA

(declare get-saha-sps-search)

;; TODO: smarter about failed searches...
(defn get-inner-sa-cache "Get a map from inner final states to SAS nodes."[hfs]
  (let [[name abstract-hfs-fn] (drop-hfs hfs)]
    (util/cache-with *problem-cache* name

(defn lift-hfs 
  "Lift child-solution into the context of parent-node."
  [parent child-solution]
  (assert (:opt-sol child-solution))
  (HierarchicalForwardState
   (lift-state        (:state parent)   (:state child-solution))
   (+                 (:reward parent)  (:reward child-solution))
   (concat            (:opt-sol parent) (:opt-sol child-solution))
   (next (:remaining-actions parent))))

(defn adjust-hfs-reward [h r]
  (HierarchicalForwardState (:state h) (+ r (:reward h)) (:opt-sol h) (:remaining-actions h)))

(defn sa-node-name 
  ([state action] (sa-node-name state action (env/precondition-context action state)))
