Constraint Satisfaction¶
Variables¶
Variables are derived from a common baseclass
- class constrainingorder.variables.Variable(name, **kwargs)[source]¶
Abstract baseclass for variables.
Variables describe the variables of a CSP. The instances are immutable and only make sense in connection with a Space.
- description = None¶
description of the variable
- discrete = None¶
whether the variable is discrete or continuous
- domain = None¶
domain of the variable
- name = None¶
name of the variable
Constrainingorder at the moment contains two types of Variables, DiscreteVariables and RealVariables
- class constrainingorder.variables.DiscreteVariable(name, **kwargs)[source]¶
Discrete variable with values from a DiscreteSet of elements.
Constraints¶
Constraints are derived from a common baseclass
- class constrainingorder.constraints.Constraint(domains)[source]¶
- consistent(lab)[source]¶
check whether the labeling is consistent with this constraint
Parameters: lab (dict) – A dictionary with parameter names and values Return type: bool
- domains = None¶
Domains imposed by node consistency for this constraint
- satisfied(lab)[source]¶
check whether the labeling satisfies this constraint
Parameters: lab (dict) – A dictionary with parameter names and values Return type: bool
- vnames = None¶
Names of the variables affected by this constraint
Constrainingorder ships with a selection of constraints, but it is easy to add custom ones
- class constrainingorder.constraints.FixedValue(variable, value)[source]¶
Constraint that fixes a variable to a value
- __init__(variable, value)[source]¶
Create a new FixedValue constraint. It enforces that a variable takes on a particular, fixed value.
Parameters: - variable (Variable) – Variable whose value is fixed
- value – Value to which it is fixed
Raises ValueError: if the value is not in the domain of the variable
- class constrainingorder.constraints.AllDifferent(variables)[source]¶
Constraint enforcing different values between a number of variables
- class constrainingorder.constraints.Domain(variable, domain)[source]¶
Constraint that ensures that value of a variable falls into a given domain
- __init__(variable, domain)[source]¶
Create a new Domain constraint. It enforces that a variable takes on values from a specified set.
Parameters: - variable (DiscreteVariable or RealVariable) – Variable whose value is restricted
- domain (DiscreteSet or IntervalSet) – Set of values to which variable is restricted
Binary relations are an important class of constraints. In Constraining Order they are derived from a common baseclass. New binary relations only need to implement the relation function. These relations can be used on Variables with values that offer the corresponding relations in the python data model.
- class constrainingorder.constraints.BinaryRelation(var1, var2)[source]¶
Abstract Base class for constraint the describe a binary relation between two variables.
Constraining Order ships with the standard relations.
For DiscreteVariables, another way to represent relations is by the set of tuples that are fulfilling this relation. This is represented by the DiscreteBinaryRelation constraint
- class constrainingorder.constraints.DiscreteBinaryRelation(var1, var2, tuples)[source]¶
General binary relation between discrete variables represented by the tuples that are in this relation
- __init__(var1, var2, tuples)[source]¶
Create a new DiscreteBinaryRelation constraint. It restricts the values of the two variables to a set of possible combinations.
Parameters: - var1 (DiscreteVariable or RealVariable) – The first variable
- var2 (DiscreteVariable or RealVariable) – The second variable
- tuples (sequence of tuples with values) – The allowed value combinations
Space¶
- class constrainingorder.Space(variables, constraints)[source]¶
A space is a description of the computation space for a specific CSP.
- __init__(variables, constraints)[source]¶
Create a new Space for a CSP
Parameters: - variables (sequence of Variables) – The variables of the CSP
- constraints (sequence of Constraints) – The constraints of the CSP
- constraints = None¶
list of constraints
- domains = None¶
dictionary of variable names to DiscreteSet/IntervalSet with admissible values
- variables = None¶
dictionary of variable names to variable instances
Solvers¶
To obtain one or all solutions to a CSP, one needs to use a solver. Solvers operate on a space. For good performance it might be good to reduce the problem space first.
- constrainingorder.solver.ac3(space)[source]¶
AC-3 algorithm. This reduces the domains of the variables by propagating constraints to ensure arc consistency.
Parameters: space (Space) – The space to reduce
- constrainingorder.solver.solve(space, method=u'backtrack', ordering=None)[source]¶
Generator for all solutions.
Parameters: - method (str) – the solution method to employ
- ordering (sequence of parameter names) – an optional parameter ordering
Methods:
“backtrack”: simple chronological backtracking “ac-lookahead”: full lookahead