Basic types
Each expression in the CPO file format has an automatically computed type (it is not possible to specify the type of an expression explicitly).
Note that there are no user-defined types in CPO file format.
This section describes only basic types. Additional types are described in sections Scheduling types, Arrays, More types and Types in search section.
Numerical types
Numerical constants in CPO files have type int or float:
int- Integer in range
intmin..intmax. floatfloatfor floating-point constants. It corresponds todoubletype in C.
The type int is preferred. That is, whenever the number can be represented
as int in the range intmin..intmax then the type int is used, otherwise the type is float is used. Note that it does not matter
whether the number is written with or without a decimal point, for example the type of constant 4.0 is also int.
Certain functions require int arguments within a certain range.
In this case the function may require a parameter of one of the
following types:
uint- Non-negative integer in range
0..intmax sint- Integer in range
intervalmin..intervalmax. Used in scheduling. bit- Bit constant. Possible values are only
0and1.
Conversions from type int to types uint, sint and bit are
automatic, however if the provided value is not within the requested range
then an error is raised.
Example
pi = 3.14159265359; // Constant, type float
n = 10; // Constant, type int
q = 5.0; // Constant, type int
zero = 0; // Constant, type int
// Function stepAt takes sint and uint parameters:
step = stepAt(10, q);
Basic expression types
Variables and constants can be combined together using functions and operators into compound expressions. The most common expression types are:
intExpr- Integer expressions. The simplest integer expressions are
integer variables such as
intVar(1, 3, 7). Furthermore, assuming thatxandyare integer variables,x+1,y-2and(x+1)*(y-2)are also integer expressions. floatExpr- floating point expressions such as
x + 0.5. boolExpr- Boolean expressions, for example
x < 5,y == 7andx < 5 || y == 7. When a Boolean expression is true then its value is 1, otherwise 0.
Note that constant propagation is not carried out when a CPO file is read.
Instead, such expressions are evaluated by CP Optimizer during presolve.
Therefore 1+2 is integer expression, not an integer constant.
For complete list of supported operators and functions see Operator expressions and Functions.
Example
x = intVar(1..10); // type intVar
y = intVar(1..10); // type intVar
halfx1 = x / 2; // type floatExpr
halfx2 = x div 2; // type intExpr
total = x + y; // type intExpr
Type constraint
The constraint type represents a condition that is required to hold in
every solution. Any boolExpr can be turned into constraint.
Additionally there are functions such as alldiff that return constraint. Therefore alldiff([x, y, z]) is a valid constraint however
alldiff([x, y, z]) or alldiff([a, b, c]) is invalid (operator or
requires two boolExpr arguments).
Example
"x[0]" = intVar(0..2);
"x[1]" = intVar(0..2);
"x[2]" = intVar(0..2);
x = ["x[0]", "x[1]", "x[2]"]; // x is an array of three integer variables
"y[0]" = intVar(0..2);
"y[1]" = intVar(0..2);
"y[2]" = intVar(0..2);
y = ["y[0]", "y[1]", "y[2]"]; // y is an array of three integer variables
alldiff(x); // constraint: each x[i] must take different value
alldiff(y); // constraint: each y[i] must take different value
inverse(x, y); // constraint: for each i in 0..2: x[y[i]] == i
