[pypy-svn] r22627 - pypy/dist/pypy/lib/logic

auc at codespeak.net auc at codespeak.net
Wed Jan 25 10:16:45 CET 2006


Author: auc
Date: Wed Jan 25 10:16:42 2006
New Revision: 22627

Added:
   pypy/dist/pypy/lib/logic/test_computationspace.py
Modified:
   pypy/dist/pypy/lib/logic/computationspace.py
   pypy/dist/pypy/lib/logic/unification.py
Log:
(ale, auc)
* first test on computation space
* CS creation


Modified: pypy/dist/pypy/lib/logic/computationspace.py
==============================================================================
--- pypy/dist/pypy/lib/logic/computationspace.py	(original)
+++ pypy/dist/pypy/lib/logic/computationspace.py	Wed Jan 25 10:16:42 2006
@@ -184,11 +184,12 @@
         self.program = program
         self.parent = parent
         self.store = Store()
-        self.root = var('root')
+        self.root = self.store.var('root')
         self.store.bind(self.root, program(self.store))
 
-        
-    
-
+    def branch(self):
+        return ComputationSpace(self.program, parent=self)
 
 
+    def ask(self):
+        pass

Added: pypy/dist/pypy/lib/logic/test_computationspace.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/lib/logic/test_computationspace.py	Wed Jan 25 10:16:42 2006
@@ -0,0 +1,32 @@
+import unification as u
+import variable as v
+import constraint as c
+import computationspace as cs
+from py.test import raises
+
+
+class TestComputationSpace:
+
+    def setUp(self):
+        pass
+
+    def test_bind_cs_root(self):
+
+        def dummy_problem(store):
+            s = store # i'm lazy
+            x, y, z, w = (s.var('x'), s.var('y'),
+                          s.var('z'), s.var('w'))
+            s.set_domain(x, c.FiniteDomain([2, 6]))
+            s.set_domain(y, c.FiniteDomain([2, 3]))
+            s.set_domain(z, c.FiniteDomain([4, 5]))
+            s.set_domain(w, c.FiniteDomain([1, 4, 5]))
+            s.add_constraint(c.Expression([x, y, z], 'x == y + z'))
+            s.add_constraint(c.Expression([z, w], 'z < w'))
+            # we don't know yet how to
+            # set up a distribution strategy
+            return (x, y, z) 
+
+        spc = cs.ComputationSpace(dummy_problem)
+        assert 'root' in spc.store.names
+        assert ['x', 'y', 'z'] == [var.name for var
+                                   in spc.root.val]

Modified: pypy/dist/pypy/lib/logic/unification.py
==============================================================================
--- pypy/dist/pypy/lib/logic/unification.py	(original)
+++ pypy/dist/pypy/lib/logic/unification.py	Wed Jan 25 10:16:42 2006
@@ -178,8 +178,17 @@
         self.in_transaction = False
         self.lock = threading.RLock()
 
+    #-- Variables ----------------------------
+
+    def var(self, name):
+        """creates a variable of name name and put
+           it into the store"""
+        v = Var(name, self)
+        self.add_unbound(v)
+        return v
+
     def add_unbound(self, var):
-        # register globally
+        """add unbound variable to the store"""
         if var in self.vars:
             raise AlreadyInStore(var.name)
         print "adding %s to the store" % var
@@ -188,9 +197,8 @@
         # put into new singleton equiv. set
         var.val = EqSet([var])
 
-    #-- Bind var to domain --------------------
-
     def set_domain(self, var, dom):
+        """bind variable to domain"""
         assert(isinstance(var, Var) and (var in self.vars))
         if var.is_bound():
             raise AlreadyBound



More information about the Pypy-commit mailing list