alternative

Creates an alternative constraint between interval variables.

Syntax


constraint alternative(intervalVar interval, intervalVarArray array, intExpr cardinality = 1)

Parameters

  • interval: interval variable.
  • array: array of interval variables.
  • cardinality: Cardinality of the alternative constraint. By default, when this optional argument is not specified, a unit cardinality is assumed (cardinality=1).

Description

This function creates an alternative constraint between interval variable interval and the set of interval variables in array. If no cardinality expression is specified, if interval is present, then one and only one of the intervals in array will be selected by the alternative constraint to be present and the start and end values of interval will be the same as the ones of the selected interval. If a cardinality expression is specified, cardinality intervals in array will be selected by the alternative constraint to be present and the selected intervals will have the same start and end value as interval variable interval. Interval variable interval is absent if and only if all interval variables in array are absent.

Example


a = intervalVar();
a_mode1 = intervalVar(optional, size=5);
a_mode2 = intervalVar(optional, size=4);
a_mode3 = intervalVar(optional, size=9);
// Task a can be executed in 3 alternative modes. As the task a is not optional, 
// one of the three possible modes will necessarily be selected
alternative(a, [a_mode1, a_mode2, a_mode3]);

Example


a = intervalVar(optional);
a_mode1 = intervalVar(optional, size=5);
a_mode2 = intervalVar(optional, size=4);
a_mode3 = intervalVar(optional, size=9);
// Task a can be executed in 3 alternative modes. Here task a is optional, 
// so it is possible to decide a is absent, in this case, all intervals a_modei will be absent too.
alternative(a, [a_mode1, a_mode2, a_mode3]);

Example


a = intervalVar(size=10);
a_worker1 = intervalVar(optional);
a_worker2 = intervalVar(optional);
a_worker3 = intervalVar(optional);
// Task a can be executed by 3 workers. Two workers are necessary to perform the task and the selected workers
// must work together on the task from its start time to its end time.
alternative(a, [a_worker1, a_worker2, a_worker3], 2);