           (when (seq @(:init-sets-atom sn)) (println "Warning: adding outgoing edges! (sas_hierarchy_induction)"))
           (swap! @(:successor-map-atom sn) assoc t
             (doall (for [a (util/safe-get-in *extended-dtgs* var s t)] 
-                     [(get-current-action-hla a) (get-current-vv-hla var t dst-val)])))
+                     [(get-current-action-hla a var) (get-current-vv-hla var t dst-val)])))
           (doseq [e (util/safe-get @(:successor-map-atom sn) t)]
             (extend-vv-hla-edge! sn e @(:init-sets sn))))))))
 


;; TODO: special treatment for "free"  vars without self-loops.

(defn vv-hla-name [var src-val dst-val] [:!VV src-var dst-val])

; successor-map is a map from dst-val to list of [ap-hla next-vv-hla] pairs. 
(deftype SAS-VV-HLA  [var src-val dst-val src?-atom init-sets-atom precond-vars-atom effect-sets-atom successor-map-atom]

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Top Level  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(def *vars* nil)
(def *extended-dtgs* nil) ; Map from var to map from prev val to map from post val to list of actions.
(def *simple-dtgs* nil)   ; Map from var to edge list.
(def *var-val-sets* nil)  ; Map from var name to set of all vals.
(def #^HashMap *hla-cache* nil) ; a map from [action-name] to map from init-sets to action.

(defn induce-hierarchy [sas-problem]
  (let [{:keys [vars actions init]} sas-problem]
    (binding [*vars*          vars
              *extended-dtgs* (sas-analysis/domain-transition-graphs vars actions)
              *simple-dtgs*   (util/map-vals (fn [dtg] (for [[pval emap] dtg, [eval _] emap] [pval eval])) *extended-dtgs*)
              *var-val-sets*  (util/map-map (juxt :name :vals) vars)
              *hla-cache*     (HashMap.)]
      (let [goal-action (util/safe-singleton (get-in *extended-dtgs* [sas/goal-var-name sas/goal-false-val sas/goal-true-val]))
            goal-hla    (get-current-action-hla goal-action sas/goal-var-name)]
        (extend-action-hla! goal-hla (util/map-vals (fn [x] #{x}) init))
        (hierarchy/SimpleHierarchicalEnv sas-problem [goal-hla])))))



