 
 (def *vars* nil)
 (def *reverse-dtgs* nil)
-(def #^HashMap *hla-cache* nil) ; a map from [action-name] to map from init-sets to action.
+(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])
-;  (init-sets       [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 var val])
+    (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)

    (if (and (util/singleton? refs-results) (util/singleton? (ffirst refs-results)))
        (first (ffirst refs-results))
      (when (seq refs-results)
        (SAS-VV-HLA var goal-val 
                    (set (for [[ref _] refs-results, a ref, v (precond-var-set a)] v))
                    init-sets 
                    (apply merge-with clojure.set/union (map second refs-results))
                    (map first refs-results))))))

(defn induce-action-hla [a init-sets ]
  (println "Inducing HLA for preconds + action" (:name a))
  (let [first-bits (for [[pvar pval] (:precond-map a)
                         :when (not (= (init-sets pvar) #{pval}))]
                     (induce-vv-hla pvar pval init-sets ))]
;    (doall first-bits)
;    (doseq [b first-bits] (println "\n" b "\n\n"))
    (when (every? identity first-bits)
     (if (empty? first-bits)
         a

        extended-rdtgs              (make-extended-reverse-dtgs vars actions)]
    (filter
     (fn [[[var1 val1] [var2 val2]]]
       (when (< (.compareTo #^Comparable var1 #^Comparable var2) 0)
         (every? (fn [[var val other-var other-val]]
                   (every? (fn [a] (not (= (get (:effect-map a) other-var other-val) other-val)))
                           (apply concat (vals ((extended-dtgs var) val)))))
