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 value values[i] in the array exprs.
  • Each consecutive sub-sequence of width (like exprs[j+1], exprs[j+2], ..., exprs[j+width]) takes at least vmin and at most vmax values of the array values.

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 values and cards must have the same length.