startOf

Returns the start of a specified interval variable.

Syntax


intExpr startOf(intervalVar interval, int absentValue = 0)

Parameters

  • interval: interval variable.
  • absentValue: value to return if the interval variable interval becomes absent.

Description

This function returns an integer expression that is equal to start of the interval variable interval if it is present. If it is absent, then the value of the expression is absentValue (zero by default).

Example


interval = intervalVar(optional, length=10);
startOf(interval) == 0;

There are two solutions to this problem:

  • Either interval is present, starts at 0 and ends at 10,
  • Or interval is absent. The condition startOf(interval) == 0 holds in this case because by default startOf returns 0 when the interval variable is absent.

Example


a = intervalVar(optional);
b = intervalVar(optional);
startOf(a) <= startOf(b, intervalmax);

In this example, condition startOf(a) <= startOf(b, intervalmax) is equal to constraint startBeforeStart(a, b). Notice that when a or b is absent then the condition holds.

Example


a = intervalVar(optional);
startOf(a) >= 10;

The condition startOf(a) >= 10 cannot hold if the interval variable a is absent. Therefore a must be present and cannot start before 10.

For comparison:


startOf(a, intervalmax) >= 10;

also constrains a not to start before 10; however it keeps the possibility that a is absent.