Module constraint :: Class Constraint
[show private | hide private]
[frames | no frames]

Type Constraint

object --+
         |
        Constraint

Known Subclasses:
AllDifferentConstraint, AllEqualConstraint, ExactSumConstraint, FunctionConstraint, InSetConstraint, MaxSumConstraint, MinSumConstraint, NotInSetConstraint, SomeInSetConstraint, SomeNotInSetConstraint

Abstract base class for constraints
Method Summary
bool __call__(self, variables, domains, assignments, forwardcheck)
Perform the constraint checking
bool forwardCheck(self, variables, domains, assignments, _unassigned)
Helper method for generic forward checking
  preProcess(self, variables, domains, constraints, vconstraints)
Preprocess variable domains
    Inherited from object
  __init__(...)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
x.__hash__() <==> hash(x)
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __repr__(x)
x.__repr__() <==> repr(x)
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value
  __str__(x)
x.__str__() <==> str(x)

Method Details

__call__(self, variables, domains, assignments, forwardcheck=False)
(Call operator)

Perform the constraint checking

If the forwardcheck parameter is not false, besides telling if the constraint is currently broken or not, the constraint implementation may choose to hide values from the domains of unassigned variables to prevent them from being used, and thus prune the search space.
Parameters:
variables - Variables affected by that constraint, in the same order provided by the user
           (type=sequence)
domains - Dictionary mapping variables to their domains
           (type=dict)
assignments - Dictionary mapping assigned variables to their current assumed value
           (type=dict)
forwardcheck - Boolean value stating whether forward checking should be performed or not
Returns:
Boolean value stating if this constraint is currently broken or not
           (type=bool)

forwardCheck(self, variables, domains, assignments, _unassigned=Unassigned)

Helper method for generic forward checking

Currently, this method acts only when there's a single unassigned variable.
Parameters:
variables - Variables affected by that constraint, in the same order provided by the user
           (type=sequence)
domains - Dictionary mapping variables to their domains
           (type=dict)
assignments - Dictionary mapping assigned variables to their current assumed value
           (type=dict)
Returns:
Boolean value stating if this constraint is currently broken or not
           (type=bool)

preProcess(self, variables, domains, constraints, vconstraints)

Preprocess variable domains

This method is called before starting to look for solutions, and is used to prune domains with specific constraint logic when possible. For instance, any constraints with a single variable may be applied on all possible values and removed, since they may act on individual values even without further knowledge about other assignments.
Parameters:
variables - Variables affected by that constraint, in the same order provided by the user
           (type=sequence)
domains - Dictionary mapping variables to their domains
           (type=dict)
constraints - List of pairs of (constraint, variables)
           (type=list)
vconstraints - Dictionary mapping variables to a list of constraints affecting the given variables.
           (type=dict)

Generated by Epydoc 2.1 on Thu Jul 7 02:05:09 2005 http://epydoc.sf.net