- Function cp::Alternative(globalActivity, activityBinding, subActivity, noSelected)
cp::Alternative
The function cp::Alternative(g,i,a_i,n)
, returns
if activity \(g\) is not present, the value 1 if none of the activities \(a_i\) are present and 0 otherwise.
if activity \(g\) is present, the value 1 if precisely \(n\) activities \(a_i\) are present and these present activities match the activity \(g\).
The function cp::Alternative(g,i,a_i,n)
is equivalent to
and
This function is typically used in scheduling problems to denote selected (matching) activities.
cp::Alternative(
globalActivity, ! (input) an expression
activityBinding, ! (input) an activity binding
subActivity, ! (input) an expression
noSelected ! (optional) an expression
)
Arguments
- globalActivity
An expression resulting in an activity.
- activityBinding
An index domain that specifies and possibly limits the scope of indices. This argument follows the syntax of the index domain argument of iterative operators.
- subActivity
An expression resulting in an activity. The result is a vector with an element for each possible value of the indices in index domain
activityBinding
.- noSelected
The number of alternatives, the default being 1. This expression may involve variables.
Return Value
This function returns 1 if the above condition is satisfied, or otherwise 0. When the index domain
activityBinding
is empty this function will return an error.
Example
In the example below we require precisely one of the activities
altAct(i)
to match the activitychosenAct(i)
.Constraint PreciselyOneAlternativeMatches { Definition : cp::Alternative( chosenAct, i, altAct(i) ); }We could change the above example to allow multiple matches as follows:
Variable noMatches { Range : { { 1 .. n } } } Constraint AtLeastOneAlternativeMatches { Definition : cp::Alternative( chosenAct, i, altAct(i), noMatches ); }Here, the number of matches is counted in the integer variable
noMatches
.
See also
The functions cp::Span
and cp::Synchronize
.