ordered

OPL keyword to order index pairs

Purpose

OPL keyword to express the order of index pairs compactly.

context
Model files (.mod)

Syntax

Qualifier: . SimpleQualifier
         | . "ordered" Locations "in" Expression Filter_opt
         | . Locations "in" Expression Filter_opt


SetTypeModifier: "ordered"
               | "sorted"
               | "reversed"

Description

The ordered instruction combines several parameters to produce a more compact statement. Practically, the keyword applies to the i,j pair of indices, not to the set. Therefore, you can use an ordered index pair with any set.

Compact form


int s = sum(ordered i,j in 1..n) i*j; 

is equivalent to the following excerpts and illustrates the use of the ordered instruction, often useful in practical applications.

On ranges

The declaration:


int s = sum(i,j in 1..n: i<j) i*j; 

is equivalent to:


int s = sum(i in 1..n) sum(j in 1..n: i<j) i*j; 

which is less readable than, and equivalent to:


int s = sum(i in 1..n, j in 1..m: i<j) i*j; 

On sets

se being a set of integers such as {int} se={3,2,1};

int s = sum(ordered i,j in se) i div j;

is equivalent to

int s = sum(i,j in se: ord(se,i)<ord(se,j)) i div j; 

See Sorted and ordered sets for more information on the different types of sets in OPL.