Reputation: 5
I am trying to add a constraint to my scheduling optimization problem to ensure that generated timetables have consecutive hours (i.e., no gaps between time slots within a day). However, the current implementation does not work as expected, and it returns INFEASIBLE despite having sufficient resources (teachers, classrooms, and subjects). Below is the problematic section of my code:
# C - Problematic - Timetable needs to be consecutive
for lvl_idx, level in enumerate(self._problem.levels):
for sub_idx, subject in enumerate(self._problem.subjects):
if self._problem.curriculum_contains(level, subject):
required_slots = self._problem.curriculum_time_request(level, subject)
for day, (start, end) in self._problem.slots_per_day().items():
for tch_idx in self._all_teachers:
for loc_idx in self._all_locations:
for slt_start in range(start, end - required_slots + 1):
sequence = [
self._assignment[lvl_idx, sub_idx, tch_idx, slt_start + offset, loc_idx]
for offset in range(required_slots)
]
for i in range(len(sequence) - 1):
self._model.Add(sequence[i] == sequence[i + 1])
I am building software using OR-Tools to generate timetables for high schools in Romania. I’m working with a slightly modified version of the OR-Tools school scheduling SAT example: OR-Tools school scheduling.
Here’s some background information that might be relevant:
Here you'll find my full code to replicate the issue, along with all relevant variables.
Thank you.
Upvotes: 0
Views: 42