I have 3 intervals:
dvar interval MyInterval[0..2];
And I have state function
stateFunction MyStateFunction;
And I have constraints:
alwysConstant(MyStateFunction, MyInterval[i]); alwyasIn(MyStateFunction, MyInterval[i], value_min[i], value_max[i]);
As a result, I can get a graph like this:
But can I write a constraint so that the pieces of the function only go in ascending or descending order? (so the situation on IMG_2 is undesirable)
I would use alternative:
using CP;
int value_min[0..2]=[1,1,1];
int value_max[0..2]=[3,3,3];
dvar interval MyInterval[0..2] size 10;
dvar interval MyIntervalOptions[0..2][1..3] optional;
dvar int value[0..2];
stateFunction MyStateFunction;
subject to
{
endBeforeStart(MyInterval[0],MyInterval[1]);
endBeforeStart(MyInterval[1],MyInterval[2]);
forall(i in 0..2) alternative(MyInterval[i],all(o in 1..3)MyIntervalOptions[i][o]);
forall(i in 0..2)
{
alwaysConstant(MyStateFunction, MyInterval[i]);
alwaysIn(MyStateFunction, MyInterval[i], value_min[i], value_max[i]);
forall(o in 1..3) alwaysEqual(MyStateFunction, MyIntervalOptions[i][o],o);
value[i]==sum(o in 1..3) presenceOf(MyIntervalOptions[i][o])*o;
}
(value[0]<value[1]) && (value[1]<value[2]) || (value[0]>value[1]) && (value[1]>value[2]);
}
which gives