Search in sources :

Example 21 with ExamModel

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;
}
Also used : ExamRoomPlacement(org.cpsolver.exam.model.ExamRoomPlacement) ExamPlacement(org.cpsolver.exam.model.ExamPlacement) ExamModel(org.cpsolver.exam.model.ExamModel) ExamPeriodPlacement(org.cpsolver.exam.model.ExamPeriodPlacement) Exam(org.cpsolver.exam.model.Exam)

Aggregations

ExamModel (org.cpsolver.exam.model.ExamModel)21 Exam (org.cpsolver.exam.model.Exam)20 ExamPlacement (org.cpsolver.exam.model.ExamPlacement)13 Set (java.util.Set)9 ExamRoomPlacement (org.cpsolver.exam.model.ExamRoomPlacement)9 ExamPeriodPlacement (org.cpsolver.exam.model.ExamPeriodPlacement)8 ExamInstructor (org.cpsolver.exam.model.ExamInstructor)6 ExamPeriod (org.cpsolver.exam.model.ExamPeriod)6 ExamStudent (org.cpsolver.exam.model.ExamStudent)6 ArrayList (java.util.ArrayList)4 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 File (java.io.File)2 DecimalFormat (java.text.DecimalFormat)2 HashMap (java.util.HashMap)2 ExamRoomSharing (org.cpsolver.exam.model.ExamRoomSharing)2 ExamStudentConflictsPerExam (org.cpsolver.exam.reports.ExamStudentConflictsPerExam)2 Assignment (org.cpsolver.ifs.assignment.Assignment)2 FileInputStream (java.io.FileInputStream)1 FileWriter (java.io.FileWriter)1