List<ExamInitializationWeight> examInitialWeightList = createExamAssigningScoreList(examination);
for (ExamInitializationWeight examInitialWeight : examInitialWeightList) {
Score unscheduledScore = abstractSolverScope.calculateScoreFromWorkingMemory();
Exam leader = examInitialWeight.getExam();
FactHandle leaderHandle = null;
List<ExamToHandle> examToHandleList = new ArrayList<ExamToHandle>(5);
if (leader.getExamCoincidence() == null) {
examToHandleList.add(new ExamToHandle(leader));
} else {
for (Exam coincidenceExam : leader.getExamCoincidence().getCoincidenceExamSet()) {
examToHandleList.add(new ExamToHandle(coincidenceExam));
}
}
List<PeriodScoring> periodScoringList = new ArrayList<PeriodScoring>(periodList.size());
for (Period period : periodList) {
for (ExamToHandle examToHandle : examToHandleList) {
examToHandle.getExam().setPeriod(period);
if (examToHandle.getExamHandle() == null) {
examToHandle.setExamHandle(workingMemory.insert(examToHandle.getExam()));
if (examToHandle.getExam().isCoincidenceLeader()) {
leaderHandle = examToHandle.getExamHandle();
}
} else {
workingMemory.update(examToHandle.getExamHandle(), examToHandle.getExam());
}
}
Score score = abstractSolverScope.calculateScoreFromWorkingMemory();
periodScoringList.add(new PeriodScoring(period, score));
}
Collections.sort(periodScoringList);
scheduleLeader(periodScoringList, roomList, abstractSolverScope, workingMemory, unscheduledScore,
examToHandleList, leader, leaderHandle);
examList.add(leader);
// Schedule the non leaders
for (ExamToHandle examToHandle : examToHandleList) {
Exam exam = examToHandle.getExam();
// Leader already has a room
if (!exam.isCoincidenceLeader()) {
scheduleNonLeader(roomList, abstractSolverScope, workingMemory, exam, examToHandle.getExamHandle());
examList.add(exam);
}
}
}