Originally posted by: rdumeur
Dear 0372_Mintch_Zulitch
The rand() function was used in the model provided as an example to generate production activities with random durations and output quantities. It wasn't meant to solve exactly your problem, but as said, to illustrate how the cumul function could be used to control the presence of maintenance activities.
Now, modifying the above model by setting a constant duration (1) for production and maintenance intervals and 50 for the level at which you want a maintenance interval, you get the following model:
using CP;
int n=100;
int Q = 50;
int m = n;
int horizon = 100000;
dvar interval production[i in 1..n] in 0..horizon size 1;
dvar interval maintenance[j in 1..m] optional in 0..horizon size 1;
dvar sequence machine in
append(all(i in 1..n) production[i],
all(j in 1..m) maintenance[j]);
cumulFunction level =
sum(i in 1..n) stepAtStart(production[i], 1) -
sum(j in 1..m) stepAtEnd (maintenance[j], 1, Q);
execute {
var f = cp.factory;
cp.setSearchPhases(f.searchPhase(production));
}
minimize max(i in 1..n) endOf(production[i]);
subject to {
noOverlap(machine);
level <= Q;
forall(j in 1..m-1) {
endBeforeStart(maintenance[j], maintenance[j+1]);
presenceOf(maintenance[j+1]) => presenceOf(maintenance[j]);
}
}
That produce the level function, the image of which is attached. One can see very clearly the time at which the maintenance intervals are inserted, which correspond to the "level == 0" state.
Please feel free to adjust the maintenance & production interval duration to reflect your own problem data.
I hope it helps.
Cheers,
#CPOptimizer#DecisionOptimization