sequenceVar

Creates new sequence variable.

Note: this section describes the function sequenceVar. There is also a type with the same name, see sequenceVar. The semantics of the sequence variable are also described elsewhere, see Interval variable sequencing in CP Optimizer.

Syntax


sequenceVar sequenceVar(intervalVarArray intervals, intArray types = null)

Parameters

  • intervals: an array of interval variables.
  • types: an optional array of integers representing the type of each interval variable in the sequence.

Description

An interval sequence variable (or sequence variable in short) is defined on a set of interval variables {a1,...,an}. Informally speaking, the value of an interval sequence variable represents a total ordering of the interval variables {a1,...,an}. Absent interval variables are not considered in the ordering.

The sequence variable alone does not enforce any constraint on the relative position of interval start and end points. For instance, an interval variable a could be sequenced before an interval variable b in a sequence without any impact on the relative position between the start/end points of a and b (a could still be fixed to start after the end of b). This is because different semantics can be used to define how a sequence constrains the positions of intervals. One of these semantics is implemented by the constraint noOverlap that ensures that interval variables in the sequence do not overlap and that the order of the sequence corresponds with the order of the interval start and end points.

Each interval variable in a sequence variable can be given a non-negative integer type which is local to the sequence variable. This integer type is used by some constraints on the sequence variable (see noOverlap).

Example


a = intervalVar(present);
b = intervalVar(present);
c = intervalVar();
// A sequence variable defined on {a,b,c} with types {0,1,2}
sequence = sequenceVar([a,b,c],[0,1,2]);
// The interval variables of the sequence cannot overlap
noOverlap(sequence);
// If c is present it is the first interval of the sequence
first(sequence,c);
// The type of the interval variable next to a in the sequence should be 2 or a should be last
typeOfNext(sequence,a,2)==2;

Requirements

  • intervals and types must have the same length.