-
Notifications
You must be signed in to change notification settings - Fork 0
/
objective.py
49 lines (40 loc) · 1.72 KB
/
objective.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from ..classes.schedule import Schedule
from ..classes.student import Student
# TODO: #15 Implement objective function which couples a score to a schedule
class Objective:
"""
Check for:
- overbooked timeslots (over room capacity)
- overbooked timeslots (over tutorial/practical capacity)
- double booked timeslots
- students with double booked hours
- lectures only happen once
- free periods for student (max three is hard constraint)
- malus points for using evening timeslot
- student should only follow each class once (eg: one wc1 and one wc2 in student schedule)
Optional:
- least amount of unique classes (wc1 only given once etc.)
"""
def __init__(self, schedule: Schedule) -> None:
self.statistics: dict = {}
self.score: float = 0
self.schedule = schedule
# TODO: #23 first check whether schedule is at all valid (no doubly booked rooms etc.)
# test for students with doubly booked timeslots
def count_student_doubles(self, student: Student):
bookings = set()
double_bookings: int = 0
for timeslot in student.timeslots.values():
moment = (timeslot.day, timeslot.period)
if moment in bookings:
double_bookings += 1
print(f"doubly booked student {student.name}: {moment} twice")
else:
bookings.add(moment)
return double_bookings
def get_score(self):
student_double_bookings = 0
for student in self.schedule.students.values():
student_double_bookings += self.count_student_doubles(student)
self.statistics["student_double_bookings"] = student_double_bookings
return self.score