def assign_lab_hours(self):
for group, it in zip(self.groups.values(), range(len(self.groups.items()))):
# get subjects and its practical hours
subject_list = self.__get_subj_list__(group)
shuffle(subject_list)
subject_list = self.recalculate_subjects(subject_list, group.numsubgroups)
# compute range of shift
if group.shift == 'M':
start_range, end_range = 0, self.time_table.shape[1] // 2
else:
start_range, end_range = self.time_table.shape[1] // 2, self.time_table.shape[1]
# compute the index
subjects_index = [i for i in range(group.numsubgroups)]
days_week = self.structure.shape[2]
# compute the total lab hours, for each subject
hours = list(map(lambda x: x*group.numsubgroups, [subject.practical_hours if type(subject) is not tuple
else subject[0].practical_hours + subject[1].practical_hours
for subject in subject_list]))
# start loop
for hour in range(start_range, end_range, 2):
for day in range(days_week):
# if the cell is a lab cell, let's fill it
if (self.structure[it, hour, day] == 'L' or self.structure[it, hour, day] == 'E')\
and sum(compress(hours, map(lambda x: x in subjects_index, range(len(hours))))) > 0:
cell1, cell2 = self.compute_best_cells(group, subject_list, subjects_index, hours, hour, day)
self.time_table[it, hour, day] = cell1
self.time_table[it, hour + 1, day] = cell2
subjects_index = list(map(lambda x: (x + 1) % len(subject_list), subjects_index))
if sum(hours) == 0: break
评论列表
文章目录