-
Notifications
You must be signed in to change notification settings - Fork 0
/
schedule_maker.py
55 lines (41 loc) · 1.08 KB
/
schedule_maker.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import pickle
import numpy
import itertools
# Check if matrix doesn't have values greater than 1
def matrix_valid(matrix):
for e in matrix.flat:
if e > 1: return False
return True
f = open("data-08.30.57.pkl", "rb")
subj_dict = pickle.load(f)
f.close()
desired_subjects = [
827,
828,
829,
830,
901
]
subjects = [subj_dict[i] for i in desired_subjects]
# Preprocess the matrices
for subject in subjects:
for group in subject.groups:
group.matrix = numpy.array(group.matrix, dtype=numpy.int8)
group_options = [subject.groups for subject in subjects]
# The possible choices of groups
possible_groups = []
# Now check all the possible combinations
a = 0
for comb in itertools.product(*group_options):
matrix_result = numpy.zeros(group.matrix.shape)
for group in comb:
matrix_result += group.matrix
if matrix_valid(matrix_result):
possible_groups.append(([g.n_id for g in comb], matrix_result))
print a
a += 1
res_f = open("results.pkl", "wb")
pickle.dump(possible_groups, res_f)
res_f.close()