sequence

OPL keyword (CP, scheduling) to define a sequence of interval variables.

Purpose

OPL keyword (CP, scheduling) to define a sequence of interval variables.

context
Model files (.mod)

Syntax

dvar sequence p in A [types T];

Where:

dvar interval A[];
int T[];

Description

A sequence variable represents a total order over a set of interval variables. If a sequence seq is defined over a set of interval variables { a1, a2, a3, a4 }, a value for this sequence at a solution can be: (a1, a4, a2, a3). A non-negative integer (the type) can be associated with each interval variable in the sequence. This integer is used by some constraints on the sequence (see noOverlap). Basically, from the perspective of the constraints on the sequence variable, intervals with the same type share some common features. Note that absent interval variables are not considered in the ordering.

Constraints available to restrict the ordering of the intervals in a possible sequence include before, first (scheduling), last (scheduling), and prev (scheduling).

Note that the sequence variable alone does not completely define the temporal relations that may exist between two intervals in a sequence. For example, noOverlap can be used to state that within a sequence, one interval must end before the next may begin.

sequence is a CP keyword and is still accepted as a CPLEX identifier.

Example

A set of 2*n activities to be sequenced on a unary resource such that A[2*i-1] is constrained to be executed immediately prior to A[2*i].

dvar interval A[i in 1..2*n] size d[i];
dvar sequence p in A;

subject to {
  noOverlap(p);
  forall (i in 1..n)
    prev(p, A[2*i-1], A[2*i]);
};

A set of n activities A[i] of integer type T[i] to be sequenced on a machine with a sequence dependent set up time abs(ti-tj) to switch from activity type ti to activity type tj with no activity overlap.

{int} Types = {T[i] | i in 1..n};
tuple triplet {int id1; int id2; int value;};
{triplet} M = {<i,j,ftoi(abs(i-j))> | i in Types, j in Types};

dvar interval A[i in 1..n] size d[i];
dvar sequence p in A types T; 

subject to {
  noOverlap(p, M);
};

A sample model that illustrates the use of sequence arrays can be found in your installation directory:

<Install_dir>\opl\examples\opl\sched_sequence\sched_sequence.mod.