 
 
 (defn asplan-solution-name [sol]
-  (map second (filter #(= (first %) ::GreedyFire) sol)))
+  (map second (filter #(= (first %) ::Fire) sol)))
 
 (defn asplan-solution-pair-name [[sol rew]]
   [(asplan-solution-name sol) rew])

    (3)(b) sloppy:       If (action-var c) has precondition on p, value mismatch or action on p and reserved by o!=c, o --> c
    (3)(c) extra-sloppy: If (action-var c) has precondition on p, value mismatch and reserved by o!=c, o --> c"   
  [s child-map rule]
  (assert (contains? #{:naive :greedy :sloppy :extra-sloppy} rule))
  (assert (contains? #{:greedy} rule))  
  (apply concat
         (for [v (cons sas/goal-var-name (keys child-map))]
           (let [a (state/get-var s (action-var v))]

  env/FactoredEnv
    (goal-map      [e] g-map))

;(def *dead-count* (atom 0))

;; Recall: greedy helps the most when, e.g., lots of passengers and not much room.
(defn make-asplan-env
  "Make an actino-set planning environment.  Switches are:
    check-deadlock?: check for cycles in precedence graph above and beyond lack of sources
    check-components?: check for disconnected components, rule out sources outside of goal comp
    edge-rule: :naive, :greedy, :sloppy, or :extra-sloppy.
       Naive means we stick exactly to the simple semantics of the vanilla actions.
       Greedy means we forget about reserving preconditions when free and we can fire right now (less branching).
       Sloppy means we ignore if preconditions are free, but require no action on them.
       Extra-sloppy means anything goes -- if you can execute ignoring commitments, go for it."
  ([sas-problem] (make-asplan-env sas-problem true true :greedy))
  ([sas-problem check-deadlock? check-components? edge-rule]
  (assert (contains? #{:naive :greedy :sloppy :extra-sloppy} edge-rule))     
     (def *add-count* (util/sref 0))
;  (def *dead-count* (util/sref 0))
     (let [causal-graph  (remove #(apply = %) (sas-analysis/standard-causal-graph sas-problem))
           vars          (graphs/ancestor-set causal-graph [sas/goal-var-name])
           causal-graph  (filter (fn [[v1 v2]] (and (vars v1) (vars v2))) causal-graph)
           tsi           (graphs/topological-sort-indices causal-graph)
           av-map        (into {} (for [v vars] [v (graphs/ancestor-set causal-graph [v])]))
           child-var-map (util/map-vals #(map second %) (group-by first causal-graph))
                                        ;        vars          (keys (:vars sas-problem))
           dtgs          (sas-analysis/domain-transition-graphs sas-problem)
           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))
        (concat
         (for [v vars] (make-freeze-var-action v))
         (for [a (:actions sas-problem)] (make-add-action-action a))
         (for [[p cs] child-var-map, c cs] (make-set-parent-var-action p c))
         (for [a (:actions sas-problem)] (make-fire-action a)))

        (fn asplan-actions [s]
          ;;       (println "\n" s)
;          (println "\n" s #_(dead-end? s av-map child-var-map []))
          (when-let [sources (and (not (dead-end? s av-map child-var-map [])) ;; This is necessary to catch hanging edges, or need other checks.  i.e., look at top-down env.
                                  (seq (source-vars s child-var-map check-deadlock? check-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))
                (let [v     (apply min-key tsi sources)
                      c-val (state/get-var s v)
                      dtg   (get-in dtgs [v c-val])
                      child (current-child s child-var-map v)
                      d-val (-> (state/get-var s (action-var child)) :precond-map (util/safe-get v))]
                  (when (= edge-rule :greedy)
                    #_ (util/assert-is (not (= c-val d-val)) "%s" (def *s* s)))
                  (if (= c-val d-val)
                    [(make-freeze-var-action v)]
                    (for [n-val (acyclic-succ-fn v c-val d-val), a (dtg n-val)]
                      (make-add-action-action a))))               
                
                (seq (sources-by-type :bottom-up-activate))
                (possible-activation-actions s av-map child-var-map (apply max-key tsi sources)) ;; TODO: smarter sort!
                
                (seq (sources-by-type :top-down-activate))
                (let [v (first sources)]
                  (println "I!" v)
                  (possible-activation-actions s av-map child-var-map (first sources))) ;; TODO: sort?
                
                (seq (sources-by-type :top-down-action))
                (let [v (first sources)]
                  (println "A!" v) ;                         (state/get-var s x) (state/get-var s (parent-var x sas/goal-var-name))
                  (cons (make-freeze-var-action v)
                        (for [as (vals (get-in dtgs [v (state/get-var s v)])), a as]
                          (make-add-action-action a))))
                
                :else (assert "Unknown source type!")))
            #_ (do (util/sref-set! *dead-count* (inc (util/sref-get *dead-count*))) nil)))
        (env/goal-map sas-problem)
        causal-graph dtgs av-map child-var-map acyclic-succ-fn))))

(defn make-naive-asplan-env
  "Replace the actions-fn in asplan-env with one that generates all legal actions,
