use of org.cpsolver.exam.model.ExamModel in project cpsolver by UniTime.
the class ExamRandomMove method selectNeighbour.
/**
* Select an exam randomly, select an available period randomly (from
* {@link Exam#getPeriodPlacements()}), select rooms using
* {@link Exam#findBestAvailableRooms(Assignment, ExamPeriodPlacement)}.
*/
@Override
public Neighbour<Exam, ExamPlacement> selectNeighbour(Solution<Exam, ExamPlacement> solution) {
ExamModel model = (ExamModel) solution.getModel();
Assignment<Exam, ExamPlacement> assignment = solution.getAssignment();
Exam exam = ToolBox.random(model.variables());
int px = ToolBox.random(exam.getPeriodPlacements().size());
for (int p = 0; p < exam.getPeriodPlacements().size(); p++) {
ExamPeriodPlacement period = exam.getPeriodPlacements().get((p + px) % exam.getPeriodPlacements().size());
if (iCheckStudentConflicts && exam.countStudentConflicts(assignment, period) > 0)
continue;
if (iCheckDistributionConstraints && !exam.checkDistributionConstraints(assignment, period))
continue;
Set<ExamRoomPlacement> rooms = exam.findBestAvailableRooms(assignment, period);
if (rooms == null)
continue;
return new ExamSimpleNeighbour(assignment, new ExamPlacement(exam, period, rooms));
}
return null;
}
Aggregations