Originally posted by: DavidGravot
I wrote a tiny example for each formulation
using CP;
//initial data
tuple Slot{ int start; int end; int station;}
{Slot} slots = { <10,14,1>, <12,15,1>, <13,18,2>};
//transitions
{int} stations = { s.station | s in slots};
tuple Transition { int station1 ; int station2 ; int duration;};
{Transition} transitions = { <s1, s2, (s1==s2?10000 : 0)> | s1 in stations, s2 in stations};
dvar interval slotsItv[s in slots] optional in s.start .. s.end size (s.end-s.start);
dvar interval startSlots[s in slots] optional in s.start .. (s.start+1) size 1;
dvar sequence stationsSeq in all(s in slots) startSlots[s] types all(s in slots) s.station;
maximize sum(s in slots) presenceOf(slotsItv[s]);
constraints{
noOverlap(stationsSeq,transitions);
forall(s in slots)
presenceOf(slotsItv[s]) == presenceOf(startSlots[s]);
}
and the second one without noOverlap :
using CP;
//initial data
tuple Slot{ int start; int end; int station;}
{Slot} slots = { <10,14,1>, <12,15,1>, <13,18,2>};
dvar interval itv[s in slots] optional in s.start .. s.end size (s.end-s.start);
dvar sequence stationsSeq in all(s in slots) itv[s] types all(s in slots) s.station;
maximize sum(s in slots) presenceOf(itv[s]);
constraints{
forall(s in slots)
startOf(itv[s]) <= startOfNext(stationsSeq, itv[s], s.start);
forall(s in slots)
typeOfNext(stationsSeq, itv[s], s.station+1, s.station+1) != s.station;
}
Both finds the optimal solution of 2 slots, the second one with 26 branches and 11 fails, while the first one has 14 branches and 11 fails
#CPOptimizer#DecisionOptimization