[pypy-svn] r25778 - in pypy/dist/pypy/objspace/constraint: . test

auc at codespeak.net auc at codespeak.net
Thu Apr 13 12:34:09 CEST 2006


Author: auc
Date: Thu Apr 13 12:34:07 2006
New Revision: 25778

Modified:
   pypy/dist/pypy/objspace/constraint/computationspace.py
   pypy/dist/pypy/objspace/constraint/test/test_computationspace.py
Log:
merge


Modified: pypy/dist/pypy/objspace/constraint/computationspace.py
==============================================================================
--- pypy/dist/pypy/objspace/constraint/computationspace.py	(original)
+++ pypy/dist/pypy/objspace/constraint/computationspace.py	Thu Apr 13 12:34:07 2006
@@ -100,7 +100,6 @@
             self.status = self._space.newint(1)
             return self.status
         self.status = self._space.newint(self.distributor.fanout)
-        print "duh ?"
         return self.status
 
     def w_clone(self):
@@ -118,6 +117,7 @@
 
     def w_commit(self, w_choice):
         self.distributor.w_distribute(self, w_choice)
+        self.status = None
 
     def w_set_distributor(self, w_distributor):
         self.distributor = w_distributor
@@ -153,11 +153,19 @@
         return self._space.newlist(self.dependant_constraints(w_var))
 
     def w_define_problem(self, w_problem):
-        print "there"
-        self.sol_set = self._space.call(w_problem, self)
+        self.sol_set = self._space.call(w_problem, self._space.newlist([self]))
 
-    def w_set_root(self, w_solution_list):
-        self.sol_set = w_solution_list
+    def w_merge(self):
+        res = []
+        for var in self.sol_set.wrappeditems:
+            res.append(self.var_dom[var].get_values()[0])
+        return self._space.newtuple(res)
+
+    def w_print_state(self):
+        print "VARS  :", self.name_var.keys()
+        print "CONST :", self.var_const.values()
+        print "DOMS  :", self.var_dom.values()
+        print "CHK   :", self.to_check
 
     #-- everything else ---------------
 
@@ -197,7 +205,7 @@
                 # we should also remove the constraint from
                 # the set of satifiable constraints of the space
                 if const in affected_constraints:
-                    affected_constraints.remove(const)
+                    del affected_constraints[const]
         
 
 W_ComputationSpace.typedef = typedef.TypeDef(
@@ -209,10 +217,10 @@
     ask = interp2app(W_ComputationSpace.w_ask),
     clone = interp2app(W_ComputationSpace.w_clone),
     commit = interp2app(W_ComputationSpace.w_commit),
+    merge = interp2app(W_ComputationSpace.w_merge),
     dependant_constraints = interp2app(W_ComputationSpace.w_dependant_constraints),
     define_problem = interp2app(W_ComputationSpace.w_define_problem),
-    set_root = interp2app(W_ComputationSpace.w_set_root))
-
+    print_state = interp2app(W_ComputationSpace.w_print_state))
 
 def newspace(object_space):
     return W_ComputationSpace(object_space)

Modified: pypy/dist/pypy/objspace/constraint/test/test_computationspace.py
==============================================================================
--- pypy/dist/pypy/objspace/constraint/test/test_computationspace.py	(original)
+++ pypy/dist/pypy/objspace/constraint/test/test_computationspace.py	Thu Apr 13 12:34:07 2006
@@ -104,3 +104,17 @@
         csp.tell(make_expression([y, z], 'y<z'))
         csp.tell(make_expression([x, z], 'x<z'))
         assert csp.ask() > 1
+
+    def test_merge(self):
+        csp = newspace()
+        def problem(csp):
+            x = csp.var('x', FiniteDomain([1]))
+            y = csp.var('y', FiniteDomain([1, 2]))
+            z = csp.var('z', FiniteDomain([1, 2, 3]))
+            csp.tell(make_expression([x, y], 'x<y'))
+            csp.tell(make_expression([y, z], 'y<z'))
+            csp.tell(make_expression([x, z], 'x<z'))
+            return [x, y, z]
+        csp.define_problem(problem)
+        assert csp.ask() == 1
+        assert csp.merge() == (1, 2, 3)



More information about the Pypy-commit mailing list