 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;    Top-level    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
+(defn pp [q xs]
+  ;(println "adding" (count xs)) 
+  (queues/pq-add-all! q xs))
 
 (defn sahucs-inverted [henv]
   (let [e     (hierarchy/env henv)

                                  cpa-val)
                    best-rew    (- 0 neg-rew (:reward-to-state best))
                    [good-parents bad-parents] (split-with #(= (second %) best-rew) cur-parents)]
                (util/assert-is (seq good-parents) "%s" [neg-rew (:reward-to-state best) best-rew (map second cur-parents) (env/action-name (:action (:sanode best)))])
                (reset! (:remaining-parents-atom best) bad-parents)
                (when (seq bad-parents)
                  (queues/pq-replace! queue best 
                                      (- 0 (:reward-to-state best) (second (first bad-parents)))))
                (doseq [[parent parent-reward] good-parents]
                  (queues/pq-add-all! queue
                    (update-parent cache parent parent-reward 
                                   (:effects best) (:reward-to-state best) (:sanode best))))
                (recur))))))))

    (loop []
      (if (queues/pq-empty? queue) nil
          (let [[best neg-rew] (queues/pq-remove-min-with-cost! queue)]
;            (assert (<= neg-rew 10))
;            (println neg-rew (queues/pq-size queue) (env/action-name (:action (:sanode best))) (:effects best) (spos (:state (first (:parent-set (:sanode best))))))
            (if (nil? (:sanode (first (:parent-set (:sanode best)))))
                (- neg-rew)
              (let [cpa-val     @(:remaining-parents-atom best)
