     (immediate-refinements- [s] refinements)
     (cycle-level-           [s] nil))
 
+(defn action-hla-name [action] [::A (env/action-name action)])
 (deftype SAS-Action-HLA [action  precond-vars init-sets effect-sets refinements]
   SAS-Induced-Action
     (precond-var-set [] precond-vars)
+    (initial-sets    [] init-sets)
     (effect-sets     [] effect-sets)
   env/Action
-    (action-name [] [::A (env/action-name action)])
+    (action-name [] (action-hla-name action))
     (primitive?  [] false)
   env/ContextualAction 
     (precondition-context [s] (assert (util/subset? (util/keyset effect-sets) precond-vars)) precond-vars)

          (merge (effect-sets bit) (util/map-vals (fn [x] #{x}) (:effect-map a)))
          [[bit a]]))))))

(defn induce-hierarchy [sas-problem]
  (let [{:keys [vars actions init]} sas-problem]
    (binding [*vars*         vars
              *reverse-dtgs* (make-extended-reverse-dtgs vars actions)]
      (hierarchy/SimpleHierarchicalEnv sas-problem 
        [(util/make-safe 
          (induce-action-hla (util/safe-singleton (get-in *reverse-dtgs* [:goal [:true] [:false]]))
                             (util/map-vals (fn [x] #{x}) init)))]))))

(defmulti pretty-print-action type)

(defn pretty-print-hla [h]
  (println (str "\nRefs for HLA" (env/action-name h)) (precond-var-set h) (effect-sets h))
  (doseq [ref (:refinements h)]
    (println " " (util/str-join ", " (map env/action-name ref))))
  (doseq [ref (:refinements h), a ref]


(def *vars* nil)
(def *reverse-dtgs* nil)
(def #^HashMap *hla-cache* (HashMap.)) ; a map from [action-name] to map from init-sets to action.

(defprotocol SAS-Induced-Action
  (precond-var-set [a])
  (initial-sets    [a])
  (effect-sets     [a]))

(extend ::env/FactoredPrimitive
  SAS-Induced-Action
    {:precond-var-set (fn [a] (util/keyset (:precond-map a)))
     :initial-sets    (fn [a] (util/map-vals (fn [x] #{x}) (:precond-map a)))
     :effect-sets     (fn [a] (util/map-vals (fn [x] #{x}) (:effect-map a)))})

(defn vv-hla-name [var val] [::VV var val])
(deftype SAS-VV-HLA     [var val precond-vars init-sets effect-sets refinements]
  SAS-Induced-Action
    (precond-var-set [] precond-vars)
    (initial-sets    [] init-sets)
    (effect-sets     [] effect-sets)
  env/Action
    (action-name [] (vv-hla-name var val))
    (primitive?  [] false)
  env/ContextualAction 
    (precondition-context [s] (assert (util/subset? (util/keyset effect-sets) precond-vars)) precond-vars)
