intervalVar
Creates a new interval variable.
Note: this section describes the function intervalVar. There is also a type with
the same name, see intervalVar. The semantics of the interval variable is
also described elsewhere, see Interval variables in CP Optimizer.
Syntax

The function intervalVar uses named parameters syntax. All parameters are
optional and can be specified in any order. Presence status of the interval is
set using keywords present, absent or optional (without specifying the
value because it is already encoded in the parameter name), the remaining
arguments are specified using parameter = value syntax.
If the allowed value for the parameter is an integer range then it can be
specified as min..max where min and max are integer constants or
simply as v if the range contains only one value v.
To simplify code generation, a trailing comma is allowed after the last parameter.
Parameters
Parameters present, absent and optional set initial presence status of
the interval variable, only one of them can be used. If the presence status is
not specified then present is used by default.
The remaining parameters all take a value:
| Parameter | Type | Description | Maximum range | Default |
|---|---|---|---|---|
start |
integer range | Allowed range for the start of the interval. | intervalmin..intervalmax |
0..intervalmax |
end |
integer range | Allowed range for the end the interval. | intervalmin..intervalmax |
0..intervalmax |
length |
integer range | Allowed range for the length the interval. | 0..intervalmax |
0..intervalmax |
size |
integer range | Allowed range for the size the interval. | 0..intervalmax |
0..intervalmax |
intensity |
stepFunction |
Specifies relation between size and length of the interval. | N/A | not used |
granularity |
uint |
Scale of the intensity function. | 0..intmax |
100 |
It is not allowed to specify any parameter twice (even with the same value).
Description
The function intervalVar creates a new interval variable with the domain
according to the supplied arguments.
Use interval variables to model (possibly zero-length) intervals of integers,
for example a time to perform some action. Informally saying, an interval variable
has unknown start and end such that start ≤ end and non-negative
length = end - start. Furthermore an interval variable can be absent to
represent the fact that the action was not taken at all.
When the interval is present then it cannot be absent (the action must be
taken). When the interval is optional then it is up to CP Optimizer to
decide whether it will be present or absent in the solution (the action
may be taken).
More detailed descriptions of the semantics of the interval variable including
intensity, granularity and size can be found in
Interval variables in CP Optimizer.
Example
// Present interval variable with length 10 that cannot end after 1000:
a = intervalVar(end=0..1000, length=10);
// Longer way to express the same (domains of variables a and b are the same):
b = intervalVar(present, length=10, start=0..990, end=10..1000);
// Optional action with fixed start time but unknown end time:
c = intervalVar(optional, start=112, end=0..2000);
// A task that takes 6 working days, it is prolonged by weekends.
// Days are counted from 0.
workingDays = stepFunction((intervalmin, 0), (0, 100), (5, 0), (7, 100), (12, 0), (14, 100), (19, 0));
d = intervalVar(size=6, end=0..21, intensity=workingDays);
// Task d cannot start or end during a weekends:
forbidStart(d, workingDays);
forbidEnd(d, workingDays);
// Absent interval variable, trailing comma.
e = intervalVar(absent,);
// None of the interval variables above can overlap:
noOverlap([a, b, c, d, e]);
Notes
- It is not mandatory to assign a name to interval variable, however it is a good practice.
-
It is not an error to specify
start,endor other parameters when the interval var was set toabsent, it is not a good practice though. Those parameters are ignored in this case. -
It is also not an error to specify the parameters in a conflicting way. E.g.
start=10andend=0would make the interval end before its start. In this case, if the interval variable is optional then it is set to absent. If it is present then the whole problem is insoluble (CP Optimizer reports that there is no solution). - CP Optimizer is obliged to assign a value to every interval variable when it search for a solution, even if the variable is not used in any constraint or expression. Such variables have no purpose and slow down the search.
- If several interval variables use the same intensity function then it is best to assign a name to that function and then use it repeatedly.