            simple-dtgs   (util/map-vals (fn [dtg] (for [[pval emap] dtg, [eval _] emap] [pval eval])) dtgs)
            acyclic-succ-fn (partial possibly-acyclic-successors (HashMap.) simple-dtgs)]
        (assert (graphs/dag? causal-graph))    
-                                        ;    (clojure.inspector/inspect-tree child-var-map)
+
        (ASPlanEnv.
         sas-problem
         (expand-initial-state (env/initial-state sas-problem) child-var-map (goal-action dtgs))

                          c)))))


;; TODO: remove redundant dead-end check ?
(defn possible-activation-actions  
   "Return a list of possible activation actions for var v possible in state s.
   To be possible parent, must be supported from below. "
   [s ancestor-map child-map v]
;   (activation-actions child-map v) #_   
   (for [c (child-map v) :when (not (or (dead-end? s ancestor-map child-map [[ v c]])))]
     (make-set-parent-var-action v c)))
;   (or (deadlocked? s child-map [[v c]]))



         (for [a (:actions sas-problem)] (make-fire-action a)))

        (fn asplan-actions [s]
          (when-let [sources (and (or (not dead-vars?) (not (uses-dead-vars? s av-map child-var-map []))) 
                                  (seq (source-vars s child-var-map deadlock? components? edge-rule)))]
            (let [sources-by-type (group-by #(source-var-type s child-var-map %) sources)]
;              (println sources-by-type)
              (util/cond-let [sources]
                (seq (sources-by-type :fire))
                [(make-fire-action-type s  edge-rule (first sources))]

                (seq (sources-by-type :bottom-up-action))
                (if directed?
                  (add-directed-actions s (apply min-key tsi sources) dtgs child-var-map acyclic-succ-fn)
                  (add-actions s (apply min-key tsi sources) dtgs))               
                     
                (seq (sources-by-type :bottom-up-activate))
                (activation-actions child-var-map (apply max-key tsi sources)) ;; TODO: smarter sort!
                
                (seq (sources-by-type :top-down-activate))
                (do (println "I!") (activation-actions child-var-map (first sources)))
                
                (seq (sources-by-type :top-down-action))
                (do (println "A!") (add-actions s (first sources) dtgs))
                
                :else (assert "Unknown source type!")))))
        (env/goal-map sas-problem)
        causal-graph dtgs av-map child-var-map tsi acyclic-succ-fn))))

