Untitled

mail@pastecode.io avatar
unknown
python
a month ago
2.5 kB
2
Indexable
Never
    def add_constraints(self):
        # Constraints 1 and 2: No overlapping lectures for courses and professors
        for i in range(self.schedule.num_courses):
            for j in range(i + 1, self.schedule.num_courses):
                # Ensure no overlap for courses
                self.solver.Add(self.start[j] >= self.end[i] or self.start[i] >= self.end[j])

                # Ensure no overlap for professors
                for k in range(self.schedule.num_professors):
                    self.solver.Add(
                        self.start[j] >= self.end[i] or self.start[i] >= self.end[j] or
                        self.professor_assignments[i][k] + self.professor_assignments[j][k] <= 1
                    )

        # Constraints 3 and 4: Room capacity constraint and no overlapping lectures for courses in the same room
        for i in range(self.schedule.num_courses):
            for j in range(i + 1, self.schedule.num_courses):
                for k in range(self.schedule.num_rooms):
                    # Ensure room capacity constraint is satisfied
                    self.solver.Add(
                        self.room_assignments[i][k] * self.schedule.course_data[i]["capacity"] <=
                        self.schedule.room_data[k]["capacity"]
                    )

                    # Ensure no overlap for courses in the same room
                    self.solver.Add(
                        self.start[j] >= self.end[i] or self.start[i] >= self.end[j] or
                        self.room_assignments[i][k] + self.room_assignments[j][k] <= 1
                    )

        # Constraints 5 and 6: Room availability and break constraints
        for i in range(self.schedule.num_courses):
            for j in range(i + 1, self.schedule.num_courses):
                # Ensure room availability
                self.solver.Add(
                    self.end[i] <= self.start[j] + self.schedule.break_duration or
                    self.end[j] <= self.start[i] + self.schedule.break_duration
                )


        # Constraints 7 and 8: Day and time slot constraints
        for i in range(self.schedule.num_courses):
            # Ensure appropriate day and time slot
            self.solver.Add(
                self.start[i] <= (self.schedule.num_days * self.schedule.num_time_slots_per_day) - 1
            )
            self.solver.Add(
                self.end[i] <= (self.schedule.num_days * self.schedule.num_time_slots_per_day) - 1
            )
Leave a Comment