Skip to content

Commit f5a6ae7

Browse files
committed
fix non-lab course constraints
Signed-off-by: Will Killian <william.killian@outlook.com>
1 parent 9c66b0f commit f5a6ae7

2 files changed

Lines changed: 10 additions & 22 deletions

File tree

src/scheduler/models/time_slot.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,6 @@ def lecture_next_to(self, other: "TimeSlot") -> bool:
290290
"""
291291
for i1, t1 in enumerate(self.times):
292292
for i2, t2 in enumerate(other.times):
293-
if self.lab_index is None or other.lab_index is None:
294-
continue
295-
if i1 == self.lab_index or i2 == other.lab_index:
296-
continue
297293
if TimeSlot._diff_between_slots(t1, t2) <= self.max_time_gap:
298294
return True
299295
return False

src/scheduler/scheduler.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -645,27 +645,19 @@ def _build_resource_constraints(
645645
if i.course_id == j.course_id:
646646
# when a faculty teaches two sections of the same course,
647647
# they must be next to each other
648-
constraint_parts.append(
649-
cast(
650-
z3.BoolRef,
651-
z3.And(
652-
lecture_next_to(i.time, j.time),
653-
lab_next_to(i.time, j.time),
654-
),
655-
)
656-
)
648+
same_course_constraints = [lecture_next_to(i.time, j.time)]
649+
# Only require lab_next_to if the course has labs
650+
if i.labs:
651+
same_course_constraints.append(lab_next_to(i.time, j.time))
652+
constraint_parts.append(cast(z3.BoolRef, z3.And(same_course_constraints)))
657653
else:
658654
# when a faculty teaches two sections of different courses,
659655
# they must not be next to each other
660-
constraint_parts.append(
661-
cast(
662-
z3.BoolRef,
663-
z3.And(
664-
z3.Not(lecture_next_to(i.time, j.time)),
665-
z3.Not(lab_next_to(i.time, j.time)),
666-
),
667-
)
668-
)
656+
diff_course_constraints = [z3.Not(lecture_next_to(i.time, j.time))]
657+
# Only require lab_next_to constraint if both courses have labs
658+
if i.labs and j.labs:
659+
diff_course_constraints.append(z3.Not(lab_next_to(i.time, j.time)))
660+
constraint_parts.append(cast(z3.BoolRef, z3.And(diff_course_constraints)))
669661

670662
if resource:
671663
# add all resource constraints (room, lab, etc.)

0 commit comments

Comments
 (0)