Originally posted by: rdumeur
Dear Ran21,
Are you using interval variables to model your scheduling problem?
If so, the following (very simplified) model can give you an idea of how using "alternative" and "span" constraints on optional intervals may help you.
The idea here is to consider days as optional intervals, and while allowing any course to happen during any day, impose the fact that the number of "present" days (days of work) must be equals to (<number of days> -1). Hi hope this helps!
Cheers,
--------------- model begins here --------------
using CP;
int nc = 10; // number of courses
int nd = 5; // number of days
dvar interval days[1..nd] optional size 8;
dvar interval courses[1..nc] size 1;
dvar interval day_course[1..nd][1..nc] optional;
constraints {
// one course happens on a certain day
forall(c in 1..nc) {
alternative(courses[c], all(d in 1..nd) day_course[d][c]);
}
// a course happens during a day
forall(d in 1..nd) {
if(d > 1) endBeforeStart(days[d-1],days[d]); // order days... for presentation
span(days[d], all(c in 1..nc) day_course[d][c]);
}
// cannot teach two courses at the same time
noOverlap(courses);
// days do not overlap either.
noOverlap(days);
// ensure that there is one day off.
nd-1 == sum(d in 1..nd) presenceOf(days[d]);
}
#CPOptimizer#DecisionOptimization