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

auc at codespeak.net auc at codespeak.net
Thu Apr 13 14:00:14 CEST 2006


Author: auc
Date: Thu Apr 13 14:00:12 2006
New Revision: 25779

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


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 14:00:12 2006
@@ -98,6 +98,7 @@
             self.distributor.find_distribution_variable(self)
         except: # FIXME: indexError ?
             self.status = self._space.newint(1)
+            self.w_print_state()
             return self.status
         self.status = self._space.newint(self.distributor.fanout)
         return self.status
@@ -105,14 +106,19 @@
     def w_clone(self):
         new = newspace(self._space)
         new.distributor = self.distributor
+        # copy the domains only
         for var, dom in self.var_dom.items():
             new.var_dom[var] = dom.w_copy()
-        # !! be sure to not put state in constraints
-        new.constraints = self.constraints
+        # keep track of constraint check-list
         for const in self.to_check:
             new.to_check[const] = True
+        # copy the var->const mapping
         for var, const in self.var_const.items():
             new.var_const[var] = const
+        # share other stateless stuff
+        new.constraints = self.constraints
+        new.name_var = self.name_var
+        new.sol_set = self.sol_set
         return new
 
     def w_commit(self, w_choice):

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 14:00:12 2006
@@ -118,3 +118,17 @@
         csp.define_problem(problem)
         assert csp.ask() == 1
         assert csp.merge() == (1, 2, 3)
+
+    def test_clone_and_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(AllDistinct([x, y, z]))
+            return [x, y, z]
+        csp.define_problem(problem)
+        csp.print_state()
+        csp = csp.clone()
+        assert csp.ask() == 1
+        assert csp.merge() == (1, 2, 3)



More information about the Pypy-commit mailing list