The Constraint Programming Solver

Common Syntax Components

The following syntax components are used in multiple predicates. They depend on the definition of an identifier-expression. For more information, see the section Identifier Expressions in Chapter 9, The OPTMODEL Procedure. For information about other syntactic components, see the section that describes the corresponding predicate.

data-item

is a single element of constant data for a predicate argument. It is resolved to a list of zero or more constant values. Each data-item must conform to one of the following syntax forms:

  • a number

  • an identifier-expression, but excluding suffixes

  • the name of a numeric array

  • ( expression ), which must evaluate to a number

An array name resolves to a list of the element values in the array. The other forms resolve to a single list value.

Each of the preceding syntax forms can also be prefixed by an index set in braces ({}). This form produces a list that contains a value for each member in the index set. An array name that is prefixed by an indexing set is expanded using the member indices to select the array elements.

data-list

is a space-separated list of data-items. The values from the data-items are juxtaposed into a single list.

For example, the first three constraints in the following statements refer to valid data-lists, whereas the last four do not. Each incorrect constraint is preceded by a comment that explains why the constraint is incorrect.

var X integer, Y integer, Z integer;
num n;
con CorrectDataList1:   element(X, 1 2 3 4, Y);
con CorrectDataList2:   element(X, 1 2 3 4 n, Y);
con CorrectDataList3:   element(X, {i in 1..4} i n, Y);
/* The parentheses imply a scalar expression */
con IncorrectDataList1: element(X, ({i in 1..4} i) n, Y);
/* [1 2 3 4] is an array initializer, not an array name */
con IncorrectDataList2: element(X, [1 2 3 4], Y);
/* Z is a variable */
con IncorrectDataList3: element(X, 1 2 3 4 Z, Y);
/* Impossible to distinguish Z.sol from [ Z . sol ] */
con IncorrectDataList4: element(X, 1 2 3 4 Z.sol, Y);
scalar-variable

is an identifier-expression that refers to a single variable (that is, not to an array of variables).

variable-item

is a single element of variable data for a predicate argument. It is resolved to a list of zero or more variable values. This item is like a data-item, except that it can resolve to a variable, variable array, linear expression, or constant numeric value.

Each variable-item must conform to one of the following syntax forms:

  • a number

  • an identifier-expression (but excluding suffixes) that specifies a variable, implicit variable, objective, or numeric parameter

  • the name of a variable, implicit variable, objective, or numeric array

  • ( expression ), which must evaluate to a linear equation or numeric constant

An array name resolves to a list of the element values in the array. The other forms resolve to a single list value.

Each of the preceding syntax forms can also be prefixed by an index set in braces ({}). This form produces a list that contains a value for each member in the index set. An array name that is prefixed by an indexing set is expanded using the member indices to select the array elements.

When the value of a variable-item refers to a linear equation or numeric constant, it is handled like a solver variable equal to the value.

variable-list

is a space-separated list of variable-items. The values from the items are juxtaposed into a single list.

As an example, the first four constraints in the following statements refer to valid variable-lists, whereas the last two do not. Each incorrect constraint is preceded by a comment that explains why the constraint is incorrect.

var X{1..3} integer, A integer, B integer;
impvar IX{i in 1..3} = X[i] + i;
num n init 2;
con CorrectVariableList1: alldiff({j in 1..3} X[j]);
con CorrectVariableList2: alldiff(A B);
con CorrectVariableList3: alldiff({j in 1..3} X[j] A B);
con CorrectVariableList4: alldiff(1 n (n+1) IX);
/* Indexing is not distributive in variable lists */
var Y{1..3} integer;
con IncorrectVariableList1: alldiff({j in 1..3} (X[j] Y[j]));
/* Expressions and suffixed ids must appear in parentheses */
con IncorrectVariableList2: alldiff(A.dual);

Last updated: September 09, 2026