Globals (cpmpy.tools.xcsp3.globals)
Additional global constraints which are not (yet) part of the standard CPMpy collection.
This file contains all the missing global constraints in order to support XCSP3-core, which is a restricted scope of the complete XCSP3 specification (as used for the competitions).
Currently, version 3.2 is supported.
List of classes
Ensures none of the lists given are exactly the same. |
|
Ensures none of the lists given are exactly the same. |
|
The sequence of variables form a subcircuit, where x[i] = j means that j is the successor of i. |
|
The sequence of variables form a subcircuit, where x[i] = j means that j is the successor of i. |
|
Inverse (aka channeling / assignment) constraint. |
|
Inverse (aka channeling / assignment) constraint but with only one array. Equivalent to Inverse(x,x) arr[i] == j <==> arr[j] == i. |
|
Channeling constraint. Channeling integer representation of a variable into a representation with boolean indicators for all 0<=i<len(arr) : arr[i] = 1 <=> value = i exists 0<=i<len(arr) s.t. arr[i] = 1. |
|
The values of the variables in 'array' correspond to a row in 'table'. |
|
Extension of the Table constraint where the table matrix may contain wildcards (STAR), meaning there are no restrictions for the corresponding variable in that tuple. |
|
The values of the variables in 'array' do not correspond to any row in 'table' |
|
MDD-constraint: an MDD (Multi-valued Decision Diagram) is an acyclic layerd graph starting from a single node and ending in one. |
|
Regular-constraint (or Automaton-constraint) Takes as input a sequence of variables and a automaton representation using a transition table. |
|
The "NotInDomain" constraint, defining non-interval domains for an expression |
|
2D-version of the NoOverlap constraint. |
|
Function returning x if b is True and otherwise y |
|
Global cumulative constraint. |
List of Solver-native classes
OR-Tools native NoOverlap2D global constraint. |
|
OR-Tools native SubCircuit global constraint. |
|
OR-Tools native SubCircuitWithStart global constraint. |
|
Choco's native SubCircuit global constraint. |
|
Minizinc's native SubCircuit global constraint. |
|
Minizinc's native SubCircuitWithStart global constraint. |
- class cpmpy.tools.xcsp3.globals.AllDifferentLists(lists)[source]
Ensures none of the lists given are exactly the same. Called ‘lex_alldifferent’ in the global constraint catalog: https://sofdem.github.io/gccat/gccat/Clex_alldifferent.html#uid24923
- property args
- deepcopy(memodict={})
- get_bounds()
Returns the bounds of a Boolean global constraint. Numerical global constraints should reimplement this.
- has_subexpr()
Does it contains nested
Expressions(anything other than a_NumVarImplor a constant)? Is of importance when deciding whether certain transformations are needed along particular paths of the expression tree. Results are cached for future calls and reset when the expression changes (in-place argument update).
- implies(other)
- is_bool() bool
Returns whether the global constraint is a Boolean (return type) Operator.
- Returns:
True, global constraints are Boolean
- Return type:
bool
- negate()
Returns the negation of this global constraint. Defaults to ~self, but subclasses can implement a better version, > Fages, François, and Sylvain Soliman. Reifying global constraints. Diss. INRIA, 2012.
- set_description(txt, override_print=True, full_print=False)
- update_args(args)
Allows in-place update of the expression’s arguments. Resets all cached computations which depend on the expression tree.
- class cpmpy.tools.xcsp3.globals.AllDifferentListsExceptN(lists, n)[source]
Ensures none of the lists given are exactly the same. Excluding the tuples given in N Called ‘lex_alldifferent’ in the global constraint catalog: https://sofdem.github.io/gccat/gccat/Clex_alldifferent.html#uid24923
- property args
- deepcopy(memodict={})
- get_bounds()
Returns the bounds of a Boolean global constraint. Numerical global constraints should reimplement this.
- has_subexpr()
Does it contains nested
Expressions(anything other than a_NumVarImplor a constant)? Is of importance when deciding whether certain transformations are needed along particular paths of the expression tree. Results are cached for future calls and reset when the expression changes (in-place argument update).
- implies(other)
- is_bool() bool
Returns whether the global constraint is a Boolean (return type) Operator.
- Returns:
True, global constraints are Boolean
- Return type:
bool
- negate()
Returns the negation of this global constraint. Defaults to ~self, but subclasses can implement a better version, > Fages, François, and Sylvain Soliman. Reifying global constraints. Diss. INRIA, 2012.
- set_description(txt, override_print=True, full_print=False)
- update_args(args)
Allows in-place update of the expression’s arguments. Resets all cached computations which depend on the expression tree.
- class cpmpy.tools.xcsp3.globals.Channel(arr, v)[source]
Channeling constraint. Channeling integer representation of a variable into a representation with boolean indicators
for all 0<=i<len(arr) : arr[i] = 1 <=> value = i exists 0<=i<len(arr) s.t. arr[i] = 1
- property args
- decompose()[source]
Returns a decomposition into (a conjunction of) smaller constraints.
The decomposition might create auxiliary variables, it can also use other global constraints as long as it does not create a circular dependency.
To ensure equivalence of decomposition, we split into constraints determining the value of the global constraint, and defining-constraints. Defining constraints (totally) define new auxiliary variables needed for the decomposition, and can always be enforced at top-level.
Tip: avoid creating auxiliary variables and use nested expressions instead! (especially, don’t create Booleans but use (iv == v) expressions instead, better for common subexpression elimination!)
- Returns:
A tuple containing the constraints representing the constraint value and the defining constraints
- Return type:
tuple[Sequence[Expression], Sequence[Expression]]
- deepcopy(memodict={})
- get_bounds()
Returns the bounds of a Boolean global constraint. Numerical global constraints should reimplement this.
- has_subexpr()
Does it contains nested
Expressions(anything other than a_NumVarImplor a constant)? Is of importance when deciding whether certain transformations are needed along particular paths of the expression tree. Results are cached for future calls and reset when the expression changes (in-place argument update).
- implies(other)
- is_bool() bool
Returns whether the global constraint is a Boolean (return type) Operator.
- Returns:
True, global constraints are Boolean
- Return type:
bool
- negate()
Returns the negation of this global constraint. Defaults to ~self, but subclasses can implement a better version, > Fages, François, and Sylvain Soliman. Reifying global constraints. Diss. INRIA, 2012.
- set_description(txt, override_print=True, full_print=False)
- update_args(args)
Allows in-place update of the expression’s arguments. Resets all cached computations which depend on the expression tree.
- class cpmpy.tools.xcsp3.globals.ChocoSubcircuit(arguments)[source]
Choco’s native SubCircuit global constraint.
A subcircuit is a Hamiltonian path between a subset of the nodes of a graph. When a node i is not part of the circuit, it should self-loop with an arc i -> i.
- property args
- callSolver(CPMpy_solver, Native_solver)[source]
Call the directname() function of the native solver, with stored arguments replacing CPMpy variables with solver variables as needed.
SolverInterfaces will call this function when this constraint is added.
- Parameters:
CPMpy_solver – a CPM_solver object, that has a solver_vars() function
Native_solver – the python interface to some specific solver
- Returns:
the response of the solver when calling the function
- deepcopy(memodict={})
- get_bounds()
- has_subexpr()
Does it contains nested
Expressions(anything other than a_NumVarImplor a constant)? Is of importance when deciding whether certain transformations are needed along particular paths of the expression tree. Results are cached for future calls and reset when the expression changes (in-place argument update).
- implies(other)
- is_bool() bool
is it a Boolean (return type) Operator?
- set_description(txt, override_print=True, full_print=False)
- update_args(args)
Allows in-place update of the expression’s arguments. Resets all cached computations which depend on the expression tree.
- value()
- class cpmpy.tools.xcsp3.globals.DynamicCumulative(start, duration, end, demand, capacity)[source]
Global cumulative constraint. Used for resource aware scheduling. Ensures that the capacity of the resource is never exceeded. When decomposed, dynamically switches between time-resource and task-resource decompositions depending on size of domains. Equivalent to
NoOverlapwhen demand and capacity are equal to 1. Supports both varying demand across tasks or equal demand for all jobs.- property args
- decompose()[source]
Decomposition from: Schutt, Andreas, et al. “Why cumulative decomposition is not as bad as it sounds.” International Conference on Principles and Practice of Constraint Programming. Springer, Berlin, Heidelberg, 2009.
Heuristically switches between time-resource and task-resource decomposition depending on the relative size of the time horizon and the number of tasks.
- If
n = number of tasks t = size of time horizon
- then
time-resource decomposition scales with n*t task-resource decomposition scales with 3n(n-1)
- thus
switch when t > 3*n
- deepcopy(memodict={})
- get_bounds()
Returns the bounds of a Boolean global constraint. Numerical global constraints should reimplement this.
- has_subexpr()
Does it contains nested
Expressions(anything other than a_NumVarImplor a constant)? Is of importance when deciding whether certain transformations are needed along particular paths of the expression tree. Results are cached for future calls and reset when the expression changes (in-place argument update).
- implies(other)
- is_bool() bool
Returns whether the global constraint is a Boolean (return type) Operator.
- Returns:
True, global constraints are Boolean
- Return type:
bool
- negate()
Returns the negation of this global constraint. Defaults to ~self, but subclasses can implement a better version, > Fages, François, and Sylvain Soliman. Reifying global constraints. Diss. INRIA, 2012.
- set_description(txt, override_print=True, full_print=False)
- update_args(args)
Allows in-place update of the expression’s arguments. Resets all cached computations which depend on the expression tree.
- class cpmpy.tools.xcsp3.globals.IfThenElseNum(b, x, y)[source]
Function returning x if b is True and otherwise y
- property args
- decompose() tuple[Expression, list[Expression]]
Returns a decomposition into smaller constraints as a tuple of (numerical expression, list of constraints defining auxiliary variables)
The first one will replace the GlobalFunction expression in-place, the second one will be added to the list of top-level constraints.
The decomposition might create auxiliary variables and use other global constraints as long as it does not create a circular dependency.
- Returns:
A tuple containing the numerical expression and a list of constraints defining auxiliary variables
- Return type:
tuple[Expression, list[Expression]]
- decompose_comparison(cmp_op, cpm_rhs)[source]
DEPRECATED: returns a list of constraints representing the decomposed comparison of the global function (and any auxiliary variables introduced).
- Parameters:
cmp_op (str) – Comparison operator
cmp_rhs (Expression) – Right-hand side expression for the comparison
- Returns:
A tuple containing two lists: constraints representing the comparison, and constraints defining auxiliary variables
- Return type:
tuple[list[Expression], list[Expression]]
- deepcopy(memodict={})
- get_bounds()[source]
Returns the bounds of the global function
- Returns:
A tuple of (lower bound, upper bound)
- Return type:
tuple[int, int]
- has_subexpr()
Does it contains nested
Expressions(anything other than a_NumVarImplor a constant)? Is of importance when deciding whether certain transformations are needed along particular paths of the expression tree. Results are cached for future calls and reset when the expression changes (in-place argument update).
- implies(other)
- is_bool() bool
- Returns:
False, global functions are numeric
- Return type:
bool
- is_total() bool
Returns whether it is a total function. If true, its value is defined for all arguments
TODO: I do not find anywhere where we set it dynamically to False? TODO: REMOVE??
- set_description(txt, override_print=True, full_print=False)
- update_args(args)
Allows in-place update of the expression’s arguments. Resets all cached computations which depend on the expression tree.
- class cpmpy.tools.xcsp3.globals.InverseOne(arr)[source]
Inverse (aka channeling / assignment) constraint but with only one array. Equivalent to Inverse(x,x)
arr[i] == j <==> arr[j] == i
- property args
- decompose()[source]
Returns a decomposition into (a conjunction of) smaller constraints.
The decomposition might create auxiliary variables, it can also use other global constraints as long as it does not create a circular dependency.
To ensure equivalence of decomposition, we split into constraints determining the value of the global constraint, and defining-constraints. Defining constraints (totally) define new auxiliary variables needed for the decomposition, and can always be enforced at top-level.
Tip: avoid creating auxiliary variables and use nested expressions instead! (especially, don’t create Booleans but use (iv == v) expressions instead, better for common subexpression elimination!)
- Returns:
A tuple containing the constraints representing the constraint value and the defining constraints
- Return type:
tuple[Sequence[Expression], Sequence[Expression]]
- deepcopy(memodict={})
- get_bounds()
Returns the bounds of a Boolean global constraint. Numerical global constraints should reimplement this.
- has_subexpr()
Does it contains nested
Expressions(anything other than a_NumVarImplor a constant)? Is of importance when deciding whether certain transformations are needed along particular paths of the expression tree. Results are cached for future calls and reset when the expression changes (in-place argument update).
- implies(other)
- is_bool() bool
Returns whether the global constraint is a Boolean (return type) Operator.
- Returns:
True, global constraints are Boolean
- Return type:
bool
- negate()
Returns the negation of this global constraint. Defaults to ~self, but subclasses can implement a better version, > Fages, François, and Sylvain Soliman. Reifying global constraints. Diss. INRIA, 2012.
- set_description(txt, override_print=True, full_print=False)
- update_args(args)
Allows in-place update of the expression’s arguments. Resets all cached computations which depend on the expression tree.
- class cpmpy.tools.xcsp3.globals.MDD(array, transitions)[source]
MDD-constraint: an MDD (Multi-valued Decision Diagram) is an acyclic layerd graph starting from a single node and ending in one. Each edge layer corresponds to a variables and each path corresponds to a solution The values of the variables in ‘array’ correspond to a path in the mdd formed by the transitions in ‘transitions’. Root node is the first node used as a start in the first transition (i.e. transitions[0][0])
- Parameters:
array – an array of CPMpy expressions (integer variable, global functions,…)
transitions – an array of tuples (nodeID, int, nodeID) where nodeID is some unique identifiers for the nodes (int or str are fine)
Example
The following transitions depict a 3 layer MDD, starting at ‘r’ and ending in ‘t’ (“r”, 0, “n1”), (“r”, 1, “n2”), (“r”, 2, “n3”), (“n1”, 2, “n4”), (“n2”, 2, “n4”), (“n3”, 0, “n5”), (“n4”, 0, “t”), (“n5”, 1, “t”) Its graphical representation is:
r 0/ |1 \2 X n1 n2 n3 2| /2 /O Y n4 n5 0\ /1 Z tIt has 3 paths, corresponding to 3 solution for (X,Y,Z): (0,2,0), (1,2,0) and (2,0,1)
- property args
- decompose()[source]
Returns a decomposition into (a conjunction of) smaller constraints.
The decomposition might create auxiliary variables, it can also use other global constraints as long as it does not create a circular dependency.
To ensure equivalence of decomposition, we split into constraints determining the value of the global constraint, and defining-constraints. Defining constraints (totally) define new auxiliary variables needed for the decomposition, and can always be enforced at top-level.
Tip: avoid creating auxiliary variables and use nested expressions instead! (especially, don’t create Booleans but use (iv == v) expressions instead, better for common subexpression elimination!)
- Returns:
A tuple containing the constraints representing the constraint value and the defining constraints
- Return type:
tuple[Sequence[Expression], Sequence[Expression]]
- deepcopy(memodict={})
- get_bounds()
Returns the bounds of a Boolean global constraint. Numerical global constraints should reimplement this.
- has_subexpr()
Does it contains nested
Expressions(anything other than a_NumVarImplor a constant)? Is of importance when deciding whether certain transformations are needed along particular paths of the expression tree. Results are cached for future calls and reset when the expression changes (in-place argument update).
- implies(other)
- is_bool() bool
Returns whether the global constraint is a Boolean (return type) Operator.
- Returns:
True, global constraints are Boolean
- Return type:
bool
- negate()
Returns the negation of this global constraint. Defaults to ~self, but subclasses can implement a better version, > Fages, François, and Sylvain Soliman. Reifying global constraints. Diss. INRIA, 2012.
- set_description(txt, override_print=True, full_print=False)
- update_args(args)
Allows in-place update of the expression’s arguments. Resets all cached computations which depend on the expression tree.
- class cpmpy.tools.xcsp3.globals.MinizincSubcircuit(arguments)[source]
Minizinc’s native SubCircuit global constraint.
A subcircuit is a Hamiltonian path between a subset of the nodes of a graph. When a node i is not part of the circuit, it should self-loop with an arc i -> i.
- property args
- callSolver(CPMpy_solver, Native_solver)[source]
Call the directname() function of the native solver, with stored arguments replacing CPMpy variables with solver variables as needed.
SolverInterfaces will call this function when this constraint is added.
- Parameters:
CPMpy_solver – a CPM_solver object, that has a solver_vars() function
Native_solver – the python interface to some specific solver
- Returns:
the response of the solver when calling the function
- deepcopy(memodict={})
- get_bounds()
- has_subexpr()
Does it contains nested
Expressions(anything other than a_NumVarImplor a constant)? Is of importance when deciding whether certain transformations are needed along particular paths of the expression tree. Results are cached for future calls and reset when the expression changes (in-place argument update).
- implies(other)
- is_bool() bool
is it a Boolean (return type) Operator?
- set_description(txt, override_print=True, full_print=False)
- update_args(args)
Allows in-place update of the expression’s arguments. Resets all cached computations which depend on the expression tree.
- value()
- class cpmpy.tools.xcsp3.globals.MinizincSubcircuitWithStart(arguments)[source]
Minizinc’s native SubCircuitWithStart global constraint.
This global is the same as SubCircuit, only can a additional start_index be provided which is ensure to be part of the subcircuit.
- property args
- callSolver(CPMpy_solver, Native_solver)[source]
Call the directname() function of the native solver, with stored arguments replacing CPMpy variables with solver variables as needed.
SolverInterfaces will call this function when this constraint is added.
- Parameters:
CPMpy_solver – a CPM_solver object, that has a solver_vars() function
Native_solver – the python interface to some specific solver
- Returns:
the response of the solver when calling the function
- deepcopy(memodict={})
- get_bounds()
- has_subexpr()
Does it contains nested
Expressions(anything other than a_NumVarImplor a constant)? Is of importance when deciding whether certain transformations are needed along particular paths of the expression tree. Results are cached for future calls and reset when the expression changes (in-place argument update).
- implies(other)
- is_bool() bool
is it a Boolean (return type) Operator?
- set_description(txt, override_print=True, full_print=False)
- update_args(args)
Allows in-place update of the expression’s arguments. Resets all cached computations which depend on the expression tree.
- value()
- class cpmpy.tools.xcsp3.globals.NegativeShortTable(array, table)[source]
The values of the variables in ‘array’ do not correspond to any row in ‘table’
- property args
- decompose()[source]
Returns a decomposition into (a conjunction of) smaller constraints.
The decomposition might create auxiliary variables, it can also use other global constraints as long as it does not create a circular dependency.
To ensure equivalence of decomposition, we split into constraints determining the value of the global constraint, and defining-constraints. Defining constraints (totally) define new auxiliary variables needed for the decomposition, and can always be enforced at top-level.
Tip: avoid creating auxiliary variables and use nested expressions instead! (especially, don’t create Booleans but use (iv == v) expressions instead, better for common subexpression elimination!)
- Returns:
A tuple containing the constraints representing the constraint value and the defining constraints
- Return type:
tuple[Sequence[Expression], Sequence[Expression]]
- deepcopy(memodict={})
- get_bounds()
Returns the bounds of a Boolean global constraint. Numerical global constraints should reimplement this.
- has_subexpr()
Does it contains nested
Expressions(anything other than a_NumVarImplor a constant)? Is of importance when deciding whether certain transformations are needed along particular paths of the expression tree. Results are cached for future calls and reset when the expression changes (in-place argument update).
- implies(other)
- is_bool() bool
Returns whether the global constraint is a Boolean (return type) Operator.
- Returns:
True, global constraints are Boolean
- Return type:
bool
- negate()
Returns the negation of this global constraint. Defaults to ~self, but subclasses can implement a better version, > Fages, François, and Sylvain Soliman. Reifying global constraints. Diss. INRIA, 2012.
- set_description(txt, override_print=True, full_print=False)
- update_args(args)
Allows in-place update of the expression’s arguments. Resets all cached computations which depend on the expression tree.
- class cpmpy.tools.xcsp3.globals.NoOverlap2d(start_x, dur_x, end_x, start_y, dur_y, end_y)[source]
2D-version of the NoOverlap constraint. Ensures a set of rectangles is placed on a grid such that they do not overlap.
- property args
- decompose()[source]
Returns a decomposition into (a conjunction of) smaller constraints.
The decomposition might create auxiliary variables, it can also use other global constraints as long as it does not create a circular dependency.
To ensure equivalence of decomposition, we split into constraints determining the value of the global constraint, and defining-constraints. Defining constraints (totally) define new auxiliary variables needed for the decomposition, and can always be enforced at top-level.
Tip: avoid creating auxiliary variables and use nested expressions instead! (especially, don’t create Booleans but use (iv == v) expressions instead, better for common subexpression elimination!)
- Returns:
A tuple containing the constraints representing the constraint value and the defining constraints
- Return type:
tuple[Sequence[Expression], Sequence[Expression]]
- deepcopy(memodict={})
- get_bounds()
Returns the bounds of a Boolean global constraint. Numerical global constraints should reimplement this.
- has_subexpr()
Does it contains nested
Expressions(anything other than a_NumVarImplor a constant)? Is of importance when deciding whether certain transformations are needed along particular paths of the expression tree. Results are cached for future calls and reset when the expression changes (in-place argument update).
- implies(other)
- is_bool() bool
Returns whether the global constraint is a Boolean (return type) Operator.
- Returns:
True, global constraints are Boolean
- Return type:
bool
- negate()
Returns the negation of this global constraint. Defaults to ~self, but subclasses can implement a better version, > Fages, François, and Sylvain Soliman. Reifying global constraints. Diss. INRIA, 2012.
- set_description(txt, override_print=True, full_print=False)
- update_args(args)
Allows in-place update of the expression’s arguments. Resets all cached computations which depend on the expression tree.
- class cpmpy.tools.xcsp3.globals.NonReifiedTable(array, table)[source]
The values of the variables in ‘array’ correspond to a row in ‘table’. This global represents the non-reified version, meaning that it does not support occuring reified when decomposing. Look at
globalconstraints.Table <cpmpy.expressions.globalconstraints.Tablefor a formulation that does support reification.- property args
- deepcopy(memodict={})
- get_bounds()
Returns the bounds of a Boolean global constraint. Numerical global constraints should reimplement this.
- has_subexpr()[source]
Does it contains nested
Expressions(anything other than a_NumVarImplor a constant)? Is of importance when deciding whether certain transformations are needed along particular paths of the expression tree. Results are cached for future calls and reset when the expression changes (in-place argument update).
- implies(other)
- is_bool() bool
Returns whether the global constraint is a Boolean (return type) Operator.
- Returns:
True, global constraints are Boolean
- Return type:
bool
- negate()
Returns the negation of this global constraint. Defaults to ~self, but subclasses can implement a better version, > Fages, François, and Sylvain Soliman. Reifying global constraints. Diss. INRIA, 2012.
- set_description(txt, override_print=True, full_print=False)
- update_args(args)
Allows in-place update of the expression’s arguments. Resets all cached computations which depend on the expression tree.
- property vars
- class cpmpy.tools.xcsp3.globals.NotInDomain(expr, arr)[source]
The “NotInDomain” constraint, defining non-interval domains for an expression
- property args
- deepcopy(memodict={})
- get_bounds()
Returns the bounds of a Boolean global constraint. Numerical global constraints should reimplement this.
- has_subexpr()
Does it contains nested
Expressions(anything other than a_NumVarImplor a constant)? Is of importance when deciding whether certain transformations are needed along particular paths of the expression tree. Results are cached for future calls and reset when the expression changes (in-place argument update).
- implies(other)
- is_bool() bool
Returns whether the global constraint is a Boolean (return type) Operator.
- Returns:
True, global constraints are Boolean
- Return type:
bool
- negate()
Returns the negation of this global constraint. Defaults to ~self, but subclasses can implement a better version, > Fages, François, and Sylvain Soliman. Reifying global constraints. Diss. INRIA, 2012.
- set_description(txt, override_print=True, full_print=False)
- update_args(args)
Allows in-place update of the expression’s arguments. Resets all cached computations which depend on the expression tree.
- class cpmpy.tools.xcsp3.globals.OrtNoOverlap2D(arguments)[source]
OR-Tools native NoOverlap2D global constraint.
Ensures that all provided rectangles are positioned within a plane whilst not overlapping. The rectangles have their sides aligned with the perpendicular x- and y-axis.
- property args
- callSolver(CPMpy_solver, Native_solver)[source]
Call the directname() function of the native solver, with stored arguments replacing CPMpy variables with solver variables as needed.
SolverInterfaces will call this function when this constraint is added.
- Parameters:
CPMpy_solver – a CPM_solver object, that has a solver_vars() function
Native_solver – the python interface to some specific solver
- Returns:
the response of the solver when calling the function
- deepcopy(memodict={})
- get_bounds()
- has_subexpr()
Does it contains nested
Expressions(anything other than a_NumVarImplor a constant)? Is of importance when deciding whether certain transformations are needed along particular paths of the expression tree. Results are cached for future calls and reset when the expression changes (in-place argument update).
- implies(other)
- is_bool() bool
is it a Boolean (return type) Operator?
- set_description(txt, override_print=True, full_print=False)
- update_args(args)
Allows in-place update of the expression’s arguments. Resets all cached computations which depend on the expression tree.
- value()
- class cpmpy.tools.xcsp3.globals.OrtSubcircuit(arguments)[source]
OR-Tools native SubCircuit global constraint.
A subcircuit is a Hamiltonian path between a subset of the nodes of a graph. When a node i is not part of the circuit, it should self-loop with an arc i -> i.
- property args
- callSolver(CPMpy_solver, Native_solver)[source]
Call the directname() function of the native solver, with stored arguments replacing CPMpy variables with solver variables as needed.
SolverInterfaces will call this function when this constraint is added.
- Parameters:
CPMpy_solver – a CPM_solver object, that has a solver_vars() function
Native_solver – the python interface to some specific solver
- Returns:
the response of the solver when calling the function
- deepcopy(memodict={})
- get_bounds()
- has_subexpr()
Does it contains nested
Expressions(anything other than a_NumVarImplor a constant)? Is of importance when deciding whether certain transformations are needed along particular paths of the expression tree. Results are cached for future calls and reset when the expression changes (in-place argument update).
- implies(other)
- is_bool() bool
is it a Boolean (return type) Operator?
- set_description(txt, override_print=True, full_print=False)
- update_args(args)
Allows in-place update of the expression’s arguments. Resets all cached computations which depend on the expression tree.
- value()
- class cpmpy.tools.xcsp3.globals.OrtSubcircuitWithStart(arguments, start_index: int = 0)[source]
OR-Tools native SubCircuitWithStart global constraint.
This global is the same as SubCircuit, only can a additional start_index be provided which is ensure to be part of the subcircuit.
- property args
- callSolver(CPMpy_solver, Native_solver)[source]
Call the directname() function of the native solver, with stored arguments replacing CPMpy variables with solver variables as needed.
SolverInterfaces will call this function when this constraint is added.
- Parameters:
CPMpy_solver – a CPM_solver object, that has a solver_vars() function
Native_solver – the python interface to some specific solver
- Returns:
the response of the solver when calling the function
- deepcopy(memodict={})
- get_bounds()
- has_subexpr()
Does it contains nested
Expressions(anything other than a_NumVarImplor a constant)? Is of importance when deciding whether certain transformations are needed along particular paths of the expression tree. Results are cached for future calls and reset when the expression changes (in-place argument update).
- implies(other)
- is_bool() bool
is it a Boolean (return type) Operator?
- set_description(txt, override_print=True, full_print=False)
- update_args(args)
Allows in-place update of the expression’s arguments. Resets all cached computations which depend on the expression tree.
- value()
- class cpmpy.tools.xcsp3.globals.Regular(array, transitions, start, accepting)[source]
Regular-constraint (or Automaton-constraint) Takes as input a sequence of variables and a automaton representation using a transition table. The constraint is satisfied if the sequence of variables corresponds to an accepting path in the automaton.
The automaton is defined by a list of transitions, a starting node and a list of accepting nodes. The transitions are represented as a list of tuples, where each tuple is of the form (id1, value, id2). An id is an integer or string representing a state in the automaton, and value is an integer representing the value of the variable in the sequence. The starting node is an integer or string representing the starting state of the automaton. The accepting nodes are a list of integers or strings representing the accepting states of the automaton.
Example
an automaton that accepts the language 0*10* (exactly 1 variable taking value 1) is defined as:
cp.Regular(array = cp.intvar(0,1, shape=4), transitions = [("A",0,"A"), ("A",1,"B"), ("B",0,"C"), ("C",0,"C")], start = "A", accepting = ["C"])
- property args
- decompose()[source]
Returns a decomposition into (a conjunction of) smaller constraints.
The decomposition might create auxiliary variables, it can also use other global constraints as long as it does not create a circular dependency.
To ensure equivalence of decomposition, we split into constraints determining the value of the global constraint, and defining-constraints. Defining constraints (totally) define new auxiliary variables needed for the decomposition, and can always be enforced at top-level.
Tip: avoid creating auxiliary variables and use nested expressions instead! (especially, don’t create Booleans but use (iv == v) expressions instead, better for common subexpression elimination!)
- Returns:
A tuple containing the constraints representing the constraint value and the defining constraints
- Return type:
tuple[Sequence[Expression], Sequence[Expression]]
- deepcopy(memodict={})
- get_bounds()
Returns the bounds of a Boolean global constraint. Numerical global constraints should reimplement this.
- has_subexpr()
Does it contains nested
Expressions(anything other than a_NumVarImplor a constant)? Is of importance when deciding whether certain transformations are needed along particular paths of the expression tree. Results are cached for future calls and reset when the expression changes (in-place argument update).
- implies(other)
- is_bool() bool
Returns whether the global constraint is a Boolean (return type) Operator.
- Returns:
True, global constraints are Boolean
- Return type:
bool
- negate()
Returns the negation of this global constraint. Defaults to ~self, but subclasses can implement a better version, > Fages, François, and Sylvain Soliman. Reifying global constraints. Diss. INRIA, 2012.
- set_description(txt, override_print=True, full_print=False)
- update_args(args)
Allows in-place update of the expression’s arguments. Resets all cached computations which depend on the expression tree.
- class cpmpy.tools.xcsp3.globals.RowSelectingShortTable(array, table)[source]
Extension of the Table constraint where the table matrix may contain wildcards (STAR), meaning there are no restrictions for the corresponding variable in that tuple. This global skips typechecks on the table and has a different decomposition than the standard
globalconstraints.ShortTable.- property args
- decompose()[source]
Alternative decomposition, similar to element from Gleb’s paper: “Improved Linearization of Constraint Programming Models”
- deepcopy(memodict={})
- get_bounds()
Returns the bounds of a Boolean global constraint. Numerical global constraints should reimplement this.
- has_subexpr()
Does it contains nested
Expressions(anything other than a_NumVarImplor a constant)? Is of importance when deciding whether certain transformations are needed along particular paths of the expression tree. Results are cached for future calls and reset when the expression changes (in-place argument update).
- implies(other)
- is_bool() bool
Returns whether the global constraint is a Boolean (return type) Operator.
- Returns:
True, global constraints are Boolean
- Return type:
bool
- negate()
Returns the negation of this global constraint. Defaults to ~self, but subclasses can implement a better version, > Fages, François, and Sylvain Soliman. Reifying global constraints. Diss. INRIA, 2012.
- set_description(txt, override_print=True, full_print=False)
- update_args(args)
Allows in-place update of the expression’s arguments. Resets all cached computations which depend on the expression tree.
- class cpmpy.tools.xcsp3.globals.SafeOnlyInverse(fwd, rev)[source]
Inverse (aka channeling / assignment) constraint. ‘fwd’ and ‘rev’ represent inverse functions; that is,
- The symmetric version (where len(fwd) == len(rev)) is defined as:
fwd[i] == x <==> rev[x] == i
- The asymmetric version (where len(fwd) < len(rev)) is defined as:
fwd[i] == x => rev[x] == i
The included decomposition only covers the “safe” variant, meaning that the expressions in fwd are assumed to have a domain within [0, len(rev)[. To also handle the “unsafe” variant, have a look at
globalconstraints.Inverse.- property args
- decompose()[source]
Returns a decomposition into (a conjunction of) smaller constraints.
The decomposition might create auxiliary variables, it can also use other global constraints as long as it does not create a circular dependency.
To ensure equivalence of decomposition, we split into constraints determining the value of the global constraint, and defining-constraints. Defining constraints (totally) define new auxiliary variables needed for the decomposition, and can always be enforced at top-level.
Tip: avoid creating auxiliary variables and use nested expressions instead! (especially, don’t create Booleans but use (iv == v) expressions instead, better for common subexpression elimination!)
- Returns:
A tuple containing the constraints representing the constraint value and the defining constraints
- Return type:
tuple[Sequence[Expression], Sequence[Expression]]
- deepcopy(memodict={})
- get_bounds()
Returns the bounds of a Boolean global constraint. Numerical global constraints should reimplement this.
- has_subexpr()
Does it contains nested
Expressions(anything other than a_NumVarImplor a constant)? Is of importance when deciding whether certain transformations are needed along particular paths of the expression tree. Results are cached for future calls and reset when the expression changes (in-place argument update).
- implies(other)
- is_bool() bool
Returns whether the global constraint is a Boolean (return type) Operator.
- Returns:
True, global constraints are Boolean
- Return type:
bool
- negate()
Returns the negation of this global constraint. Defaults to ~self, but subclasses can implement a better version, > Fages, François, and Sylvain Soliman. Reifying global constraints. Diss. INRIA, 2012.
- set_description(txt, override_print=True, full_print=False)
- update_args(args)
Allows in-place update of the expression’s arguments. Resets all cached computations which depend on the expression tree.
- class cpmpy.tools.xcsp3.globals.SubCircuit(*args)[source]
The sequence of variables form a subcircuit, where x[i] = j means that j is the successor of i. Contrary to Circuit, there is no requirement on all nodes needing to be part of the circuit. Nodes which aren’t part of the subcircuit, should self loop i.e. x[i] = i. The subcircuit can be empty (all stops self-loop). A length 1 subcircuit is treated as an empty subcircuit. Global Constraint Catalog: https://sofdem.github.io/gccat/gccat/Cproper_circuit.html
- property args
- decompose()[source]
Decomposition for SubCircuit A mix of the above Circuit decomposition, with elements from the Minizinc implementation for the support of optional visits: https://github.com/MiniZinc/minizinc-old/blob/master/lib/minizinc/std/subcircuit.mzn
- deepcopy(memodict={})
- get_bounds()
Returns the bounds of a Boolean global constraint. Numerical global constraints should reimplement this.
- has_subexpr()
Does it contains nested
Expressions(anything other than a_NumVarImplor a constant)? Is of importance when deciding whether certain transformations are needed along particular paths of the expression tree. Results are cached for future calls and reset when the expression changes (in-place argument update).
- implies(other)
- is_bool() bool
Returns whether the global constraint is a Boolean (return type) Operator.
- Returns:
True, global constraints are Boolean
- Return type:
bool
- negate()
Returns the negation of this global constraint. Defaults to ~self, but subclasses can implement a better version, > Fages, François, and Sylvain Soliman. Reifying global constraints. Diss. INRIA, 2012.
- set_description(txt, override_print=True, full_print=False)
- update_args(args)
Allows in-place update of the expression’s arguments. Resets all cached computations which depend on the expression tree.
- class cpmpy.tools.xcsp3.globals.SubCircuitWithStart(*args, start_index: int = 0)[source]
The sequence of variables form a subcircuit, where x[i] = j means that j is the successor of i. Contrary to Circuit, there is no requirement on all nodes needing to be part of the circuit. Nodes which aren’t part of the subcircuit, should self loop i.e. x[i] = i. The size of the subcircuit should be strictly greater than 1, so not all stops can self loop (as otherwise the start_index will never get visited). start_index will be treated as the start of the subcircuit. The only impact of start_index is that it will be guaranteed to be inside the subcircuit. Global Constraint Catalog: https://sofdem.github.io/gccat/gccat/Cproper_circuit.html
- property args
- decompose()[source]
Decomposition for SubCircuitWithStart. SubCircuitWithStart simply gets decomposed into SubCircuit and a constraint enforcing the start_index to be part of the subcircuit.
- deepcopy(memodict={})
- get_bounds()
Returns the bounds of a Boolean global constraint. Numerical global constraints should reimplement this.
- has_subexpr()
Does it contains nested
Expressions(anything other than a_NumVarImplor a constant)? Is of importance when deciding whether certain transformations are needed along particular paths of the expression tree. Results are cached for future calls and reset when the expression changes (in-place argument update).
- implies(other)
- is_bool() bool
Returns whether the global constraint is a Boolean (return type) Operator.
- Returns:
True, global constraints are Boolean
- Return type:
bool
- negate()
Returns the negation of this global constraint. Defaults to ~self, but subclasses can implement a better version, > Fages, François, and Sylvain Soliman. Reifying global constraints. Diss. INRIA, 2012.
- set_description(txt, override_print=True, full_print=False)
- update_args(args)
Allows in-place update of the expression’s arguments. Resets all cached computations which depend on the expression tree.