overlapLength
Returns the length of the overlap of two interval variables.
Syntax
intExpr overlapLength(intervalVar interval1, intervalVar interval2, int absentValue = 0)
intExpr overlapLength(intervalVar interval, sint start, sint end, int absentValue = 0)
Parameters
-
interval
: interval variable. -
interval1
: interval variable. -
interval2
: interval variable. -
start
: start value of a fixed interval. -
end
: end value of a fixed interval. -
absentValue
: value to return if some interval variable is absent.
Description
The first function returns an integer expression that represents the length of the overlap of interval variable interval1
and the interval variable interval2
whenever the interval variables interval1
and interval2
are present. When one of the interval variables interval1
or interval2
is absent, the function returns the constant integer value absentValue
(zero by default).
The second function returns an integer expression that represents the length of the overlap of interval variable interval
and the constant interval [start
, end
) whenever the interval variable interval
is present. When the interval variable interval
is absent, the function returns the constant integer value absentValue
(zero by default).
Example
a = intervalVar(optional, size=5..10);
b = intervalVar(optional, size=5..10);
// The length of the intersection between intervals a and b should be at least 7.
// Note that the constraint enforces that both interval variables a and b are present as
// if any of them is absent the value of the expression is 0 (default)
7 <= overlapLength(a, b);
A possible solution for this problem is a = [0, 7)
, b = [0, 7)
.
a = intervalVar(optional, size=5..10);
b = intervalVar(optional, size=5..10);
// If both interval variables a and b are present, the length of the intersection
// between intervals a and b should be at least 7.
// Note that the constraint does not enforce the presence of a or b. If any of them is absent the
// value of the expression is 10 so the constraint is satisfied.
7 <= overlapLength(a, b, 10);
A possible solution for this problem is a=absent
, b=[0, 10)
.
a = intervalVar(optional, size=5..10);
// The length of the intersection between interval a and constant interval [10, 20) should be at least 7.
// Note that the constraint enforces that interval variable a is present as
// if it is absent the value of the expression is 0 (default)
7 <= overlapLength(a, 10, 20);
A possible solution for this problem is a = [7, 17)
.
Requirements
-
For the function using a constant interval,
end
should be greater thanstart
.