Constraints available in constraint programming
Arithmetic constraints and expressions
The following arithmetic constraints and expressions are available for OPL CP models. The references point to the OPL Language Quick Reference.
Arithmetic operations
addition
subtraction
multiplication
scalar products
integer division
floating-point division
modular arithmetic
Arithmetic expressions for use in constraints.
Arithmetic constraints
equal to
not equal to
strictly less than
strictly greater than
less than or equal to
greater than or equal to
Logical constraints for CP
Logical operators, such
as logical-and, logical-or, implication, negation (not
),
difference, and equivalence are available in constraint programming.
The following logical constraints are available for OPL CP models.
Symbol | Meaning |
---|---|
&& | Logical AND |
| | | Logical OR |
! | Logical NOT |
=> | Imply |
!= | Different from |
== | Equivalence |
With the C++ API you should use the symbol <= to express implication.
Element constraints
The following subscripting operators return constrained integer or floating-point expressions, also known as element expressions.
-
A[X], where A is an array of integer values (with one or several dimensions) and X is a dexpr int, returns a dexpr int such that: when X is fixed to the value i, the value of the expression is A[i].
-
A[X], where A is an array of floating-point values (with one or several dimensions) and X is a dexpr int, returns a dexpr float such that: when X is fixed to the value i, the value of the expression is A[i].
More generally, the domain of the expression is the set of values A[i], where i is in the domain of X.
In both of the previous cases, the expression can include several indices (A[X][k], A[X][Y], A[X][k]{Y], ...).
- For constant indices, all the usual index types are available (int, float, string, tuple).
- For a decision expression index, only the integer type is available (dvar int or dexpr int).
Compatibility constraints
The CP Optimizer engine supports allowed and forbidden assignments for OPL CP models. See allowedAssignments and forbiddenAssignments in the Language Quick Reference.
Scheduling constraints
This section lists the scheduling constraints available for OPL CP scheduling models and provides links to the reference documentation for these constraints. For a more detailed description of these constraints, please refer to the Scheduling section of this manual.
The following constraints are available for OPL CP scheduling models:
Precedence constraint: endAtEnd
Precedence constraint: endAtStart
Precedence constraint: endBeforeEnd
Precedence constraint: endBeforeStart
Precedence constraint: startAtEnd
Precedence constraint: startAtStart
Precedence constraint: startBeforeEnd
Precedence constraint: startBeforeStart
Interval grouping constraint: alternative
Interval grouping constraint: span
Interval grouping constraint: synchronize
Interval presence constraint: presenceOf
Sequence constraint: first (scheduling)
Sequence constraint: last (scheduling)
Sequence constraint: before
Sequence constraint: prev
Sequence constraint: noOverlap
Cumulative or state function constraint: <= (scheduling), alwaysIn
State function constraint: alwaysConstant
State function constraint: alwaysEqual
State function constraint: alwaysNoState
Specialized constraints
The CP Optimizer engine also accepts some powerful combinatorial constraints known as specialized constraints. For these constraints, some powerful propagation algorithms are used to reduced the decision variable domains.
allDifferent
: constrains variables within advar
array to all take different valuesallMinDistance
: constrains variables within advar
array to all take values that are one-to-one different by at least a given gapinverse
: takes two arrays of integer variables that must be indexed by an integer and be one-dimensionallex
: states that the first array of variables is less than or equal to the second array of variables in the alphabetical orderpack
: represents some simple but powerful one-dimensional packing constraint
See the individual entries under OPL functions in Language Quick Reference for a complete description of each constraint.