forked from leungc70/scheduler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scheduler.py
221 lines (180 loc) · 6.37 KB
/
scheduler.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
'''
Interactive running mode
'''
from schedule_csp import schedule_csp_model, print_soln , print_table
from os import listdir
import file_parser
import cspbase
import propagators
'''
Helper function to list all .csv files under the directory
@param dir the directory of choice
return: returns nothing
'''
def list_all_csvfiles(dir):
flist = listdir(dir)
print()
print("Possible choice of .csv files under dir {}:".format(dir))
# list all files under dir that with extension .csv
for file in flist:
if file.endswith(".csv"):
print(file)
'''
Interactive running mode
Instruction:
Please put files in the correct directory:
student files in data/students/
profs files in data/profs/
Follow the message displayed in the console.
After setting environment success, type 'exit' to exit
Press ctrl + c any time to exit
'''
if __name__ == '__main__':
# define variables
profs = None
students = None
distance = None
locations = None
"""
format of profs
profs = { 'prof1':[(0,2),(4,8)],
'prof2':[(7,10),(11,14),(15,16)],
'prof3':[(6,10),(15,17),(20,22)] }
"""
while not profs:
# availability of profs
print()
print("Readding professor's availabilities...")
print("Please specify which file to read...")
print("Please choose a file from data/profs/")
# list .csv files under data/profs/
prof_dir = "data/profs/"
list_all_csvfiles(prof_dir)
prof_input_fname = input()
prof_file = prof_dir + prof_input_fname
print("Reading from FILE {}...".format(prof_file))
try:
profs = file_parser.read_avail(prof_file)
except FileNotFoundError as e:
print()
print("======ERROR=====")
print("FILE {} is not found".format(prof_file))
# message on console
print()
print("======SUCCESS=====")
print("Reading professor's availabilities success...")
"""
students = { 'student1':[['prof1'], [time_frame]],
'student2':[['prof2'], [(0,10),(10,2)]],
'student3':[['prof2','prof3'], [time_frame]],
'student4':[['prof1','prof3'], [(5,10),(20,24)]],
'student5':[all_profs , [time_frame]] }
"""
while not students:
# preferred prof and availability of students
print()
print("Readding student's availabilities...")
print("Please specify which file to read...")
print("Please choose a file from /data/students/")
# list .csv files under data/profs/
student_dir = "data/students/"
list_all_csvfiles(student_dir)
student_input_fname = input()
student_file = student_dir + student_input_fname
print("Reading from FILE {}...".format(student_file))
try:
students = file_parser.read_student(student_file)
except FileNotFoundError as e:
print()
print("======ERROR=====")
print("FILE {} is not found".format(student_file))
print()
print("======SUCCESS=====")
print("Reading student's availabilities success...")
"""
distance = { ('M5G 0A4', 'M5S 1A8'): 1200.0,
('M5S 1A8', 'M5S 3E1'): 300.0,
('M5S 3E1', 'M5S 3E1'): 1.0,
('M5G 0A4', 'M5S 3E1'): 1000.0 }
"""
while not distance:
print()
print("Readding distance...")
print("Please specify which file to read...")
print("Please choose a file from /data/distance/")
distance_dir = "data/distance/"
list_all_csvfiles(distance_dir)
distance_input_fname = input()
distance_file = distance_dir + distance_input_fname
print("Reading from FILE {}...".format(distance_file))
try:
distance = file_parser.read_distance(distance_file)
except FileNotFoundError as e:
print()
print("======ERROR=====")
print("FILE {} is not found".format(distance_file))
print()
print("======SUCCESS=====")
print("Reading distance success...")
"""
locations = { 'Prof B': ['M5S 3E1'],
'Prof J': ['M5S 1A8'],
'Prof H': ['M5S 1A8'],
'Prof D': ['M5G 0A4'] }
"""
while not locations:
print()
print("Readding location of the professors...")
print("Please specify which file to read...")
print("Please choose a file from /data/locations/")
locations_dir = "data/locations/"
list_all_csvfiles(locations_dir)
locations_input_fname = input()
locations_file = locations_dir + locations_input_fname
print("Reading from FILE {}...".format(locations_file))
try:
locations = file_parser.read_location(locations_file)
except FileNotFoundError as e:
print()
print("======ERROR=====")
print("FILE {} is not found".format(locations_file))
print()
print("======SUCCESS=====")
print("Reading locations success...")
# construct the interview scheduling CSP
csp, var_array = schedule_csp_model(profs, students, locations, distance)
solver = cspbase.BT(csp)
# Menue
while(1):
print()
print("Running environment setup success...")
print("Please choose which propagator you'd like to use?")
print("Choices: BT, FC, GAC , enter 'exit' to quit")
propa = input()
if propa.upper() == "GAC":
print()
print("======GAC=====")
solver.bt_search(propagators.prop_GAC)
elif propa.upper() == "FC":
print()
print("=======FC======")
solver.bt_search(propagators.prop_FC)
elif propa.upper() == "BT":
print()
print("======BT=====")
solver.bt_search(propagators.prop_BT)
elif propa.upper() == "exit":
print()
print("Exiting...")
break
else:
print()
print("======ERROR=====")
print("ERROR: Your input is not valid.")
print("NOTE: Please choose from BT, FC or GAC")
continue
print()
print("=====Solution=====")
print_soln(var_array)
print()
print_table(var_array)