def test_matchRoomAllocation(self): path = u"data/TabuSearchDataTests/matchingRooms" self.t.readLecturesToTimetable(path) slot = 0 coursesId = [ 'c0001', 'c0002', 'c0004', 'c0030', 'c0005', 'c0014', 'c0015', 'c0016' ] self.t.timeTable[slot] = tabuSearch.matchingRoomAllocations( self.t.getTimeTable(), slot, self.data, self.sortedRoomIdList) listOfAssignedRooms = [x[1] for x in self.t.timeTable[slot]] self.assertEqual(listOfAssignedRooms, ['B', 'S', 'C', 'G', 'F']) penalty = softConstraints2.softConstraintsPenalty( self.t.getTimeTable(), self.data)['penaltyRoomCapacity'] self.assertEqual(penalty, 340) slot = 1 self.t.timeTable[slot] = tabuSearch.matchingRoomAllocations( self.t.getTimeTable(), slot, self.data, self.sortedRoomIdList) listOfAssignedRooms = [x[1] for x in self.t.timeTable[slot]] self.assertEqual(listOfAssignedRooms, ['G', 'S', 'E', 'B', 'C', 'F']) penalty = softConstraints2.softConstraintsPenalty( self.t.getTimeTable(), self.data)['penaltyRoomCapacity'] self.assertEqual(penalty, 305)
def testSoftConstraintsMinimumWorkingDays(self): assignedList = [(0, 'c0001', 'E'), (1, 'c0001', 'B'), (2, 'c0001', 'B'), (3, 'c0001', 'B'), (0, 'c0004', 'B'), (1, 'c0004', 'B'), (2, 'c0004', 'B')] self.t.addDataToTimetable(assignedList) penalty = softConstraints2.softConstraintsPenalty(self.t.getTimeTable(), self.data)['penaltyMinWorkingDays'] self.assertEqual(penalty, 520) assignedList = [(3, 'c0004', 'B'), (4, 'c0004', 'B'), (5, 'c0004', 'B')] self.t.addDataToTimetable(assignedList) penalty = softConstraints2.softConstraintsPenalty(self.t.getTimeTable(), self.data)['penaltyMinWorkingDays'] self.assertEqual(penalty, 520) assignedList = [(12, 'c0004', 'B'), (4, 'c0001', 'B'), (5, 'c0001', 'B')] self.t.addDataToTimetable(assignedList) penalty = softConstraints2.softConstraintsPenalty(self.t.getTimeTable(), self.data)['penaltyMinWorkingDays'] self.assertEqual(penalty, 515)
def testSoftConstraintsRoomStability22(self): assignedList = [(0, 'c0001', 'E'), (1, 'c0001', 'B'), (2, 'c0001', 'C'), (3, 'c0001', 'G'), (0, 'c0004', 'B'), (1, 'c0004', 'B'), (2, 'c0004', 'B')] self.t.addDataToTimetable(assignedList) result = softConstraints2.softConstraintsPenalty(self.t.getTimeTable(), self.data, "perturbation") penaltyRoomStability = result['penaltyRoomStability'] self.assertEqual(penaltyRoomStability, 3) self.assertEqual(len(result['perturbationPenalty']), len((assignedList)))
def test_matchRoomAllocation(self): path = u"data/TabuSearchDataTests/matchingRooms" self.t.readLecturesToTimetable(path) slot = 0 coursesId = ['c0001', 'c0002', 'c0004', 'c0030', 'c0005', 'c0014', 'c0015', 'c0016'] self.t.timeTable[slot] = tabuSearch.matchingRoomAllocations(self.t.getTimeTable(), slot, self.data, self.sortedRoomIdList) listOfAssignedRooms = [x[1] for x in self.t.timeTable[slot]] self.assertEqual(listOfAssignedRooms, ['B', 'S', 'C', 'G', 'F']) penalty = softConstraints2.softConstraintsPenalty(self.t.getTimeTable(), self.data)['penaltyRoomCapacity'] self.assertEqual(penalty, 340) slot = 1 self.t.timeTable[slot] = tabuSearch.matchingRoomAllocations(self.t.getTimeTable(), slot, self.data, self.sortedRoomIdList) listOfAssignedRooms = [x[1] for x in self.t.timeTable[slot]] self.assertEqual(listOfAssignedRooms, ['G', 'S', 'E', 'B', 'C', 'F']) penalty = softConstraints2.softConstraintsPenalty(self.t.getTimeTable(), self.data)['penaltyRoomCapacity'] self.assertEqual(penalty, 305)
def rankingOfLectures(partialTimetable, data, n, q): """ Function to identify a set of the first q highly-penalized lectures and select n lectures from them, the lecture of rank k is selected with probability distribution, n <= q :param partialTimetable: timetable :param data: information about data :param n: number of selected lectures from first q highly penalized ones :param q: """ # dictionary containing soft penalties for each of lecture assigned to timetable (courseId, roomId, slot) : penalty perturbationDict = softConstraintsPenalty( partialTimetable, data, "perturbation")['perturbationPenalty'] #perturbation penalty in form courseId, roomId, slot rankingLectures = sorted(perturbationDict.items(), key=itemgetter(1), reverse=True) listItems = map(lambda x: x[0], rankingLectures[:q]) selectedLectures = selectRandom(listItems, n) return selectedLectures
def testTotalSoftConstraintsPenalty2(self): expectedResult = reduce(lambda x, y: x + y, map(lambda z: z.minWorkingDays, self.data.getAllCourses())) * 5 penalty = softConstraints2.softConstraintsPenalty(self.t.getTimeTable(), self.data)['penaltyMinWorkingDays'] self.assertEqual(penalty, expectedResult) path = u"data/TabuSearchDataTests/softConstraintsLectures" self.t.readLecturesToTimetable(path) penalty = softConstraints2.softConstraintsPenalty(self.t.getTimeTable(), self.data)['penaltyRoomStability'] self.assertEqual(penalty, 4) penalty = softConstraints2.softConstraintsPenalty(self.t.getTimeTable(), self.data)['penaltyRoomCapacity'] self.assertEqual(penalty, 440) penalty = softConstraints2.softConstraintsPenalty(self.t.getTimeTable(), self.data)['penaltyMinWorkingDays'] self.assertEqual(penalty, 490) penalty = softConstraints2.softConstraintsPenalty(self.t.getTimeTable(), self.data)['penaltyCurriculumCompactness'] self.assertEqual(penalty, 24) penalty = softConstraints2.softConstraintsPenalty(self.t.getTimeTable(), self.data)['totalPenalty'] self.assertEqual(penalty, 958)
def testSoftConstraintsPerturbation(self): assignedList = [(0, 'c0001', 'E'), (1, 'c0001', 'B'), (4, 'c0001', 'C'), (7, 'c0002', 'G'), (9, 'c0072', 'E')] self.t.addDataToTimetable(assignedList) result = softConstraints2.softConstraintsPenalty(self.t.getTimeTable(), self.data, "perturbation") self.assertEqual(sum(map(lambda x: result['perturbationPenalty'][x], result['perturbationPenalty'])), 896)
def testTotalSoftConstrainsPenalty(self): assignedList = [(0, 'c0001', 'E'), (1, 'c0001', 'B'), (4, 'c0001', 'C'), (7, 'c0002', 'G'), (9, 'c0072', 'E')] self.t.addDataToTimetable(assignedList) penalty = softConstraints2.softConstraintsPenalty(self.t.getTimeTable(), self.data)['penaltyCurriculumCompactness'] self.assertEqual(penalty, 10)
def testSoftConstraintsRoomStability(self): assignedList = [(0, 'c0001', 'E'), (1, 'c0001', 'B'), (2, 'c0001', 'C'), (3, 'c0001', 'G'), (0, 'c0004', 'B'), (1, 'c0004', 'B'), (2, 'c0004', 'B')] self.t.addDataToTimetable(assignedList) penalty = softConstraints2.softConstraintsPenalty(self.t.getTimeTable(), self.data)['penaltyRoomStability'] self.assertEqual(penalty, 3)