-
Notifications
You must be signed in to change notification settings - Fork 0
/
minimum_remaining_values.py
57 lines (46 loc) · 2.06 KB
/
minimum_remaining_values.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
50
51
52
53
54
55
56
57
"""First place lectures, then seminars (Minimum remaining values)."""
from random import shuffle
from typing import List
from templates import Gen as Schedule, Lesson, Classroom, Time
from templates import l_pool, c_pool, week_schedule, time_schedule, display_results
def run():
"""Run & display results."""
# sort lessons pool (first lectures)
l_pool.sort(key=lambda l: 0 if l.is_lecture else 1)
schedule = run_heuristic(l_pool)
display_results(schedule)
def run_heuristic(pool: List[Lesson]) -> Schedule:
schedule = Schedule([], [], [])
# make it a little bit funnier
week_days = list(week_schedule.keys())
# shuffle(week_days)
times = list(time_schedule.keys())
# shuffle(times)
for lesson in pool:
found = False
for day in week_days:
if found: break
for time in times:
if found: break
for room in c_pool:
duplicate = False
for i in range(len(schedule.lessons)):
# if room is booked at this time or teacher is busy
if (schedule.times[i].weekday == day and schedule.times[i].number == time and \
schedule.classrooms[i].building == room.building) and \
(schedule.classrooms[i].room == room.room or schedule.lessons[
i].teacher.name == lesson.teacher.name):
duplicate = True
if duplicate: continue
if found: break
if not lesson.is_lecture or room.is_big:
chosen_time = Time(day, time)
classroom = Classroom(room.building, room.room, room.is_big)
found = True
schedule.times.append(chosen_time)
schedule.classrooms.append(classroom)
schedule.lessons.append(lesson)
assert len(pool) == len(schedule.lessons)
return schedule
if __name__ == '__main__':
run()