-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimportCompareRosters.py
executable file
·86 lines (72 loc) · 2.25 KB
/
importCompareRosters.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
"""
Author: Corneel den Hartogh
Course: Heuristics
Description: Attempt to compare the rosters with each other
"""
import random
import copy
import json
import time
import glob
from decimal import Decimal
from xlrd import *
from xlwt import *
from xlutils.copy import copy
from csvFilesController import classrooms,subjects,students
from classes import Classroom,Subject,Activity,Student,Roster
import classesImport as ci
from scoreFunction import getScore
from studentOptimization import studentOptimization
from roomOptimization import roomOptimization
rosterList = []
hillclimber = []
annealing = []
genetics = []
top = 0
#instead of activitiesDict just a list
def buildDict(data, x, y, z, activitiesDict):
for activity in (data["roster"]["activities"]):
if [x,y,z] == activity["activity"]["slot"]:
activitiesDict[(x,y,z)] = activity["activity"]["subject"] + " " + \
activity["activity"]["kind"]
if (x,y,z) not in activitiesDict:
activitiesDict[(x,y,z)] = "empty"
return activitiesDict
def saveRoster(filename, hillclimber, annealing, genetics):
kind = None
topBool = False
if filename.split("/")[1][:11] == "hillclimber":
kind = "hillclimber"
hillclimber.append(filename)
elif filename.split("/")[1][:9] == "annealing":
kind = "annealing"
annealing.append(filename)
elif filename.split("/")[1][:8] == "genetics":
kind = "genetics"
genetics.append(filename)
with open(filename) as jsonfile:
data = json.load(jsonfile)
activitiesDict = {}
for x in range(5):
for y in range (5):
if y == 4:
z = 5
activitiesDict = buildDict(data, x, y, z, activitiesDict)
else:
for z in range(7):
activitiesDict = buildDict(data, x, y, z, activitiesDict)
return [filename, activitiesDict, kind, topBool]
# select all rosters that score 99% of optimal score (=1360)
for filename in glob.glob('rosters/*.json'):
if float(filename.split("_",2)[1]) >= 1400.00:
topBool = True
top += 1
rosterList.append(saveRoster(filename, hillclimber, annealing, genetics))
for filename in glob.glob('rosters_server/*.json'):
if float(filename.split("_",3)[2]) >= 1400.00:
topBool = True
top += 1
rosterList.append(saveRoster(filename, hillclimber, annealing, genetics))
for roster in rosterList:
timetable = roster[1]
for roster in rosterList: