Constraints available in constraint programming

Lists the types of constraints and expressions available in OPL for constraint programming models. See the OPL Language Quick Reference and the CP Optimizer User’s Manual for further details.

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
Note:

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:

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 a dvar array to all take different values

  • allMinDistance : constrains variables within a dvar array to all take values that are one-to-one different by at least a given gap

  • inverse : takes two arrays of integer variables that must be indexed by an integer and be one-dimensional

  • lex : states that the first array of variables is less than or equal to the second array of variables in the alphabetical order

  • pack : 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.