 
 
 ;;; Making final maps.  TODO: precompile?
-(defn make-permuter [args var-ordering]
-  (let [arg-positions (map vector (iterate inc 1) (map #(util/position % var-ordering) args))
-	arg-permutation (map first (sort-by second arg-positions))]
-    (fn permute [#^clojure.lang.APersistentVector tuple] 
-      (map (fn [ind] (.get tuple ind)) arg-permutation))))
+;(defn make-permuter [args var-ordering]
+;  (let [arg-positions (map vector (iterate inc 1) (map #(util/position % var-ordering) args))
+;	arg-permutation (map first (sort-by second arg-positions))]
+;    (fn permute [#^clojure.lang.APersistentVector tuple] 
+;      (util/vec-map (fn [ind] (.get tuple ind)) arg-permutation))))
+
+(defn get-permutation [args var-ordering]
+  (let [arg-positions (map vector (iterate inc 1) (map #(util/position % var-ordering) args))]
+    (vec (map first (sort-by second arg-positions)))))
+
+
+; TODO: be smarter about map sizes?
+(defn my-assoc-in [#^HashMap m #^clojure.lang.APersistentVector key-vec #^clojure.lang.APersistentVector perm ind]
+;  (println m key-vec perm ind)
+  (if (< (inc ind) (count perm))
+      (let [key (.get key-vec (.get perm ind))
+	    #^HashMap m2 
+             (or (.get m key) 
+		 (let [#^HashMap m2 (HashMap.)]
+		   (.put m key m2)
+		   m2))]
+	(recur m2 key-vec perm (inc ind)))
+    (.put m (.get key-vec (.get perm ind)) true)))
 
   
 ;; TODO: filter based on domains?


; Returns new-domain
; TODO: change to use keyset
(defn filter-pos-domain [map pred domain]
  (util/intersection-coll domain (keys (get map pred {}))))

;; TODO: make smarter?
(defn filter-neg-domain [map pred domain]
;  (println map pred domain)
   (reduce (fn [domain val] (if (true? (get (get map pred) val)) (disj domain val) domain)) domain domain))
;  (util/difference domain (util/keyset (get map pred {}))))

(defn simplify-map [map preds val]
  (reduce (fn [map pred] (assoc map pred (get (get map pred) val)))
	  map preds))


(defn- all-solutions [vars-left initial-domains var-map const-map clause-maps inst-map]
;  (println vars-left initial-domains var-map const-map clause-maps inst-map "\n\n")
  (if (empty? vars-left) [inst-map]
    (let [[var arg?]    (first vars-left)
	  [pos-const neg-const pos-fluent neg-fluent] (util/safe-get var-map var)
	  const-domain 

(ns edu.berkeley.ai.search.smart-csps
 (:refer-clojure)
 (:import [java.util HashMap Map ArrayList])
 (:require [edu.berkeley.ai.util :as util] 
	   [edu.berkeley.ai.util.propositions :as props]
	   )
