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

Type BacktrackingSolver

object --+    
         |    
    Solver --+
             |
            BacktrackingSolver


Problem solver with backtracking capabilities

Examples:
>>> result = [[('a', 1), ('b', 2)],
...           [('a', 1), ('b', 3)],
...           [('a', 2), ('b', 3)]]
>>> problem = Problem(BacktrackingSolver())
>>> problem.addVariables(["a", "b"], [1, 2, 3])
>>> problem.addConstraint(lambda a, b: b > a, ["a", "b"])
>>> solution = problem.getSolution()
>>> sorted(solution.items()) in result
True
>>> for solution in problem.getSolutionIter():
...     sorted(solution.items()) in result
True
True
True
>>> for solution in problem.getSolutions():
...     sorted(solution.items()) in result
True
True
True

Method Summary
  __init__(self, forwardcheck)
  getSolution(self, domains, constraints, vconstraints)
Return one solution for the given problem
  getSolutionIter(self, domains, constraints, vconstraints)
Return an iterator for the solutions of the given problem
  getSolutions(self, domains, constraints, vconstraints)
Return all solutions for the given problem
    Inherited from object
  __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

__init__(self, forwardcheck=True)
(Constructor)

Parameters:
forwardcheck - If false forward checking will not be requested to constraints while looking for solutions (default is true)
           (type=bool)
Overrides:
__builtin__.object.__init__

getSolution(self, domains, constraints, vconstraints)

Return one solution for the given problem
Parameters:
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)
Overrides:
constraint.Solver.getSolution (inherited documentation)

getSolutionIter(self, domains, constraints, vconstraints)

Return an iterator for the solutions of the given problem
Parameters:
domains - Dictionary mapping variables to 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)
Overrides:
constraint.Solver.getSolutionIter (inherited documentation)

getSolutions(self, domains, constraints, vconstraints)

Return all solutions for the given problem
Parameters:
domains - Dictionary mapping variables to 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)
Overrides:
constraint.Solver.getSolutions (inherited documentation)

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