Ranges
Integer ranges are fundamental in OPL, since they are often used in arrays and variable declarations, as well as in aggregate operators, queries, and quantifiers.
Declaring ranges
To specify an integer range, you give its lower and upper bounds, as in
range Rows = 1..10;
which declares the range value 1..10.
The lower and upper bounds can also be given by expressions, as in
int n = 8;
range Rows = n+1..2*n+1;
Once a range has been defined, you can use it as an array indexer.
Whenever a range is empty,
i.e. its upper bound is less than its lower bound, it is automatically
normalized to 0..-1 (in other words, all
empty ranges are equal).
The range declaration
An integer range is typically used:
as an array index in an array initialization expression
range R = 1..100; int A[R]; // A is an array of 100 integersas an iteration range
range R = 1..100; forall(i in R) { //element of a loop ... }as the domain of an integer decision variable
dvar int i in R;
The range float declaration
A range float data
type consists of a couple of float values specifying an interval.
It is typically used as the domain of a floating-point decision variable.
range float X = 1.0..100.0;
dvar float x in X;