Hi,
when we need to model a given capacity for a cumul, we can use simply <=
using CP;
range options=1..10;
dvar interval itvs[options] optional in 1..3 size 1;
cumulFunction c=sum(o in options) pulse(itvs[o],1);
maximize sum(o in options) presenceOf(itvs[o]);
subject to
{
// constant capacity
c<=2;
}
gives
in the IDE for c
Now if the capacity is not a constant 2 but changes over time:
// capacity 1 between 1 and 2
// capacity 2 between 2 and 3
Then what can we do ?
We can rely on alwaysIn:
using CP;
range options=1..10;
dvar interval itvs[options] optional in 1..3 size 1;
cumulFunction c=sum(o in options) pulse(itvs[o],1);
maximize sum(o in options) presenceOf(itvs[o]);
subject to
{
// capacity 1 between 1 and 2
// capacity 2 between 2 and 3
alwaysIn(c,1,2,0,1);
alwaysIn(c,2,3,0,2);
}
which gives for c
or we can also use a second cumul function that will take the capacity changes into account. See c_bis
using CP;
range options=1..10;
dvar interval itvs[options] optional in 1..3 size 1;
cumulFunction c=sum(o in options) pulse(itvs[o],1);
cumulFunction c_bis=sum(o in options) pulse(itvs[o],1)
+pulse(1,2,1);
maximize sum(o in options) presenceOf(itvs[o]);
subject to
{
// capacity 1 between 1 and 2
// capacity 2 between 2 and 3
c_bis<=2;
c<=2;
}
and then we get the same c as when we rely on alwaysIn
regards
PS: Many how to at https://www.linkedin.com/pulse/how-opl-alex-fleischer/
#DecisionOptimization#OPLusingCPOptimizer