Is there a way to limit the number of assignments for a specific value of a variable?
I'm writing a schedule problem using Choco [4.0.1]
with courses, teachers and timeslots. The same teacher can teach many courses and I need to define the amount of courses he/she could teach. I was thinking about counting the number of timeslots, like Teacher B can work 12 hours (12 timeslots)
, so I could post a constraint like arithm()
to ensure that. Any ideas?
[Updated]
Here is some code:
IntVar [] teachers;
IntVar [][] teacherTimeslots;
IntVar [] courses;
For each course there is a teacher and N
timeslots, so Teacher A can teach {1,2,3,4} and teacher B {3,4,5} and each course has 4 hours per week. Now imagine that A can work 12 hours. I'd like to limit A to teach only 12 hours (3 courses) while B would teach the remaining courses;
I cannot say how many courses has a teacher but how many he/she could teach, so I'm using
Tuples tuples = new Tuples(true);
tuples.add(1, 1);
...
tuples.add(2, 5);
model.table(teacher, course, tuples).post();
constraint to ensure that he/she is able to teach certain courses.
teacherTimeslots
is filled with all possible timeslots and I use model.allDifferent(teacherTimeslots[teacher]).post()
to keep each teacher timeslot unique.
My courses are fixed so
course[0] = 1;
...
course[4] = 5;
I thought about getting all timeslots for a teacher but when I'm building my model there is no timeslot selected, so I' get all possibilities.