lex

OPL function to sort in lexicographic order

Purpose

Returns a constraint that maintains two arrays to be lexicographically ordered.

context type
Model files (.mod) - Not allowed in a CPLEX constraint block
boolean (1 if the constraint is true, 0 otherwise)

Syntax

lex(int[ ],int[ ]);

Description

The lexicographic constraint states that the first array of variables is less than or equal to the second array of variables in the lexicographic order. More specifically, lex(x, y) maintains that x is less than or equal to y in the lexicographical sense of the term. This means that either both arrays are equal or that there exists i < size(x) such that for all j < i, x[j] = y[j] and x[i] < y[i]. Note that the size of the two arrays must be the same.

This function also works for integer arrays outside constraint blocks both in CP and CPLEX models.

You can use this function within IBM ILOG Script statements by specifying the OPL namespace:

(Opl.xxx())

Note: This constraint cannot be used in a meta-constraint.

Example

using CP;

range R = 1..10;

dvar int+ x[R] in 1..10;
dvar int+ y[R] in 1..10;

subject to {

  forall (i in R) x[i] == i;
  lex(x, y);

}