alternative

OPL constraint (scheduling) used to create an exclusive alternative interval

Purpose

OPL constraint (scheduling) used to model the selection of one or more intervals from a set of optional intervals.

context type
Model files (.mod)
boolean (1 if the constraint is true, 0 otherwise)

Syntax

alternative(a, B);
alternative(a, B, c);

Where
dvar interval a;
dvar interval B[];
dexpr int c;

Description

The constraint alternative(a, {b1, .., bn}) models an exclusive alternative between {b1, .., bn}. If interval a is present then exactly one of intervals {b1, .., bn} is present and a starts and ends together with this chosen one.

The constraint alternative(a, {b1, .., bn},c) models a selection of c intervals in the set {b1, .., bn}. If interval a is present then exactly c intervals in {b1, .., bn} are present and a starts and ends together with these selected ones. If a is absent, then all b intervals are absent. This constraint is typically used to model the selection of 1 resource (or c resources) among a set of candidate ones. It can also be used in more complex cases to model alternative execution modes for activities or alternative time-windows for executing a task.

The array B must be a one-dimensional array; for greater complexity, use the keyword all.

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

Example

The following code sample defines two interval variables a1 and a2 that represent the execution of two tasks on some processors. There are two available processors p1 and p2. The possibility to execute task ai on processor pj is represented by an optional interval aij. The duration of the tasks depends on the processor they execute on as defined by a table pij. Task a1 must be performed before a2 and the result of a1 is used as input to a2. The communication delay between two processors j and k are given by a table djk.

dvar interval a1;
dvar interval a1p[i in 1..2] optional size p[1,i];
dvar interval a2;
dvar interval a2p[i in 1..2] optional size p[2,i];
subject to {
  alternative(a1, a1p);
  alternative(a2, a2p);
  forall (j in 1..2, k in 1..2)
    endBeforeStart(a1p[j],a2p[k],d[j,k]);
};

Use of the keyword all with an array on alternative follows. For the full example see sched_optional.mod in <Install_dir>/opl/examples/opl/sched_optional.

alternative(tasks[h] [t], all(s in Skills: s.task==t) wtasks[h] [s]);