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

auc at codespeak.net auc at codespeak.net
Tue Apr 11 18:35:17 CEST 2006


Author: auc
Date: Tue Apr 11 18:35:15 2006
New Revision: 25704

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


Modified: pypy/dist/pypy/objspace/constraint/computationspace.py
==============================================================================
--- pypy/dist/pypy/objspace/constraint/computationspace.py	(original)
+++ pypy/dist/pypy/objspace/constraint/computationspace.py	Tue Apr 11 18:35:15 2006
@@ -74,11 +74,26 @@
         self.var_const = {}
         # freshly added constraints (tell -> propagate)
         self.to_check = {}
+        self.status = None
 
     #-- public interface ---------------
     
     def w_ask(self):
-        self.propagate()
+        if self.status is not None: return self.status
+        try:
+            if len(self.to_check) > 0:
+                self.propagate()
+        except: # FIXME: ConcistencyFailure
+            self.status = self._space.newint(0)
+            return self.status
+        try:
+            self.distributor.find_distribution_variable(self)
+        except: # FIXME: indexError ?
+            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):
         new = newspace(self._space)

Modified: pypy/dist/pypy/objspace/constraint/constraint.py
==============================================================================
--- pypy/dist/pypy/objspace/constraint/constraint.py	(original)
+++ pypy/dist/pypy/objspace/constraint/constraint.py	Tue Apr 11 18:35:15 2006
@@ -229,7 +229,6 @@
                 
         try:
             for varname, keep in result_cache.content.items():
-                print keep
                 domain = w_cs.w_dom(self._names_to_vars[self._space.str_w(varname)])
                 domain.w_remove_values(self._space.newlist([val
                                                             for val in domain._values

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	Tue Apr 11 18:35:15 2006
@@ -76,4 +76,32 @@
         csp.commit(2)
         assert csp.dom(z).size() == 2
 
-    
+    def test_ask_success(self):
+        csp = newspace()
+        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'))
+        assert csp.ask() == 1
+        
+    def test_ask_failure(self):
+        csp = newspace()
+        x = csp.var('x', FiniteDomain([1]))
+        y = csp.var('y', FiniteDomain([1, 2]))
+        z = csp.var('z', FiniteDomain([1, 2]))
+        csp.tell(make_expression([x, y], 'x<y'))
+        csp.tell(make_expression([y, z], 'y<z'))
+        csp.tell(make_expression([x, z], 'x<z'))
+        assert csp.ask() == 0
+
+    def test_ask_distributable(self):
+        csp = newspace()
+        x = csp.var('x', FiniteDomain([1, 2]))
+        y = csp.var('y', FiniteDomain([2, 3]))
+        z = csp.var('z', FiniteDomain([3, 4]))
+        csp.tell(make_expression([x, y], 'x<y'))
+        csp.tell(make_expression([y, z], 'y<z'))
+        csp.tell(make_expression([x, z], 'x<z'))
+        assert csp.ask() > 1



More information about the Pypy-commit mailing list