[pypy-svn] r40890 - pypy/dist/pypy/module/_cslib
auc at codespeak.net
auc at codespeak.net
Wed Mar 21 12:17:20 CET 2007
Author: auc
Date: Wed Mar 21 12:17:19 2007
New Revision: 40890
Modified:
pypy/dist/pypy/module/_cslib/constraint.py
pypy/dist/pypy/module/_cslib/fd.py
pypy/dist/pypy/module/_cslib/propagation.py
Log:
small adaptations
Modified: pypy/dist/pypy/module/_cslib/constraint.py
==============================================================================
--- pypy/dist/pypy/module/_cslib/constraint.py (original)
+++ pypy/dist/pypy/module/_cslib/constraint.py Wed Mar 21 12:17:19 2007
@@ -48,8 +48,6 @@
W_AbstractConstraint.typedef = typedef.TypeDef(
"W_AbstractConstraint")
-
-
class _Expression(rc.Expression):
"""A constraint represented as a python expression."""
@@ -74,8 +72,7 @@
for var, value in kwargs.items():
dom = self.doms[var]
assert isinstance( dom, _FiniteDomain )
- #print '!!!!', dom.w_values, value
- w_val = space.getitem( dom.w_values, space.wrap(value) )
+ w_val = dom.vlist[value]
w_kwargs.content[space.wrap(var)] = w_val
return space.is_true(space.call(self.w_filter_func,
space.newlist([]),
@@ -85,7 +82,6 @@
def __repr__(self):
return '<%s>' % self.formula
-
class _BinaryExpression(rc.BinaryExpression):
"""A constraint represented as a python expression."""
@@ -117,11 +113,11 @@
w_kwargs = space.newdict()
dom = self.doms[var1]
- w_val = space.getitem( dom.w_values, space.wrap(arg1) )
+ w_val = dom.vlist[arg1]
w_kwargs.content[space.wrap(var1)] = w_val
dom = self.doms[var2]
- w_val = space.getitem( dom.w_values, space.wrap(arg2) )
+ w_val = dom.vlist[arg2]
w_kwargs.content[space.wrap(var2)] = w_val
res = space.is_true(space.call(self.w_filter_func,
@@ -179,7 +175,6 @@
W_AllDistinct.typedef = typedef.TypeDef(
"W_AllDistinct", W_AbstractConstraint.typedef)
-#function bolted into the space to serve as constructor
def make_alldistinct(space, w_variables):
return space.wrap(W_AllDistinct(space, w_variables))
Modified: pypy/dist/pypy/module/_cslib/fd.py
==============================================================================
--- pypy/dist/pypy/module/_cslib/fd.py (original)
+++ pypy/dist/pypy/module/_cslib/fd.py Wed Mar 21 12:17:19 2007
@@ -13,30 +13,43 @@
Variable Domain with a finite set of possible values
"""
- def __init__(self, w_values, values):
- """values is a list of values in the domain
- This class uses a dictionnary to make sure that there are
+ def __init__(self, vlist, values):
+ """vlist is a list of values in the domain
+ values is a dictionnary to make sure that there are
no duplicate values"""
- assert isinstance(w_values, W_ListObject)
- self.w_values = w_values
+ #assert isinstance(w_values, W_ListObject)
+ self.vlist = vlist
self._values = {}
if values is None:
- for k in range(len(w_values.wrappeditems)):
+ for k in range(len(vlist)):
self._values[k] = True
else:
self._values = values.copy()
self._changed = False
+ def get_wvalues_in_rlist(self):
+ w_vals = self.vlist
+ return [w_vals[idx] for idx in self._values]
+
def copy(self):
- return _FiniteDomain(self.w_values, self._values)
+ return _FiniteDomain(self.vlist, self._values)
+
+ def intersect(self, other):
+ v1 = self.get_wvalues_in_rlist()
+ v2 = other.get_wvalues_in_rlist()
+ inter = [v for v in v1
+ if v in v2]
+ return _FiniteDomain(inter, None)
+
class W_FiniteDomain(baseobjspace.Wrappable):
def __init__(self, w_values, values):
assert isinstance(w_values, W_ListObject)
- self.domain = _FiniteDomain( w_values, values )
+ self.domain = _FiniteDomain(w_values.wrappeditems, values)
+
def make_fd(space, w_values):
if not isinstance(w_values, W_ListObject):
Modified: pypy/dist/pypy/module/_cslib/propagation.py
==============================================================================
--- pypy/dist/pypy/module/_cslib/propagation.py (original)
+++ pypy/dist/pypy/module/_cslib/propagation.py Wed Mar 21 12:17:19 2007
@@ -72,7 +72,7 @@
domain = w_repo.repo._domains[var]
assert isinstance( domain, fd._FiniteDomain )
w_var = space.wrap(var)
- w_value = space.getitem( domain.w_values, space.wrap(value) )
+ w_value = domain.vlist[value]
space.setitem( w_dict, w_var, w_value )
sols_w.append( w_dict )
return space.newlist(sols_w)
More information about the Pypy-commit
mailing list