range

OPL keyword for ranges of integers

Purpose

OPL keyword to specify ranges of integers.

context
Model files (.mod)

Syntax

LiteralType: "int"
           | "float"
           | "boolean"
           | "int+"
           | "float+"
           | "string"
           | "range"
           | "range" "float"
           | "constraint"

Description

Integer ranges are fundamental in OPL, since they are often used in arrays and decision variable declarations, as well as in aggregate operators, queries, and quantifiers. An integer range is specified by giving its lower and upper bounds, as in


range Rows = 1..10;

which declares a range 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, it is possible to declare data taking their values in this range. In OPL 4.x, you must use one of the standard types when declaring data or a decision variable, as in:


range Workers = 1..nbWorkers;
{int} qualified[Tasks] = ...;
range Obj = 0..(n*n);
dvar int obj in Obj;

The declaration:


range float fr = 1.2..2.2; 

specifies the subset of the real numbers in the interval [1.2,2.2].

CAUTION:

If, in a model, you define a range such as a..b with b smaller than a (-2..-10, for example), that range is considered empty and OPL transforms it to 0..-1.

Example

A compilable example:

range Rows = 1..10;

int n = 8; 
range Rows2 = n+1..2*n+1; 

int nbWorkers=10;
range Workers = 1..nbWorkers;
range Obj = 0..(n*n);
dvar int obj in Obj;

range float fr = 1.2..2.2;