sequence
Constrains occurences of specified values in an array of expressions.
Syntax
constraint sequence(int vmin, int vmax, int width, intExprArray exprs, intArray values, intExprArray cards)
Parameters
-
vmin: The minimum number of allowable values. -
vmax: The maximum number of allowable values. -
width: The size of the sequences of consecutive expressions. -
exprs: The array of expressions. -
values: The array of values. -
cards: The array of cardinality expressions.
Description
This constraint ensures that:
-
cards[i]will be equal to the number of occurrences of the valuevalues[i]in the arrayexprs. -
Each consecutive sub-sequence of
width(likeexprs[j+1],exprs[j+2], ...,exprs[j+width]) takes at leastvminand at mostvmaxvalues of the arrayvalues.
Example
For example, there are at least 2 days off during each sequence of 7
consecutive days. Let 0 be the value that represents a day off, let
workingDays be an array of variables for a worker for a given year.
cardDaysOff = intVar(0..100);
sequence(2, 7, 7, workingDays, [0], [cardDaysOff]);
Requirements
-
Arrays
valuesandcardsmust have the same length.