Search in sources :

Example 16 with ExamRoomPlacement

use of org.cpsolver.exam.model.ExamRoomPlacement in project cpsolver by UniTime.

the class ExamTimeMove method selectNeighbour.

/**
     * Select an exam randomly,
     * select an available period randomly (if it is not assigned), 
     * use rooms if possible, select rooms using {@link Exam#findBestAvailableRooms(Assignment, ExamPeriodPlacement)} if not (exam is unassigned, a room is not available or used).
     */
@Override
public Neighbour<Exam, ExamPlacement> selectNeighbour(Solution<Exam, ExamPlacement> solution) {
    ExamModel model = (ExamModel) solution.getModel();
    Assignment<Exam, ExamPlacement> assignment = solution.getAssignment();
    ExamRoomSharing sharing = model.getRoomSharing();
    Exam exam = ToolBox.random(model.variables());
    ExamPlacement placement = assignment.getValue(exam);
    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 (placement != null && placement.getPeriod().equals(period))
            continue;
        if (iCheckStudentConflicts && exam.countStudentConflicts(assignment, period) > 0)
            continue;
        if (iCheckDistributionConstraints && !exam.checkDistributionConstraints(assignment, period))
            continue;
        if (placement != null) {
            boolean ok = true;
            if (sharing != null && placement.getRoomPlacements().size() == 1) {
                ExamRoomPlacement room = placement.getRoomPlacements().iterator().next();
                ok = room.isAvailable(period.getPeriod()) && !sharing.inConflict(exam, room.getRoom().getPlacements(assignment, period.getPeriod()), room.getRoom());
            } else {
                for (Iterator<ExamRoomPlacement> i = placement.getRoomPlacements().iterator(); i.hasNext(); ) {
                    ExamRoomPlacement room = i.next();
                    if (!room.isAvailable(period.getPeriod()) || !room.getRoom().getPlacements(assignment, period.getPeriod()).isEmpty()) {
                        ok = false;
                        break;
                    }
                }
            }
            if (ok)
                return new ExamSimpleNeighbour(assignment, new ExamPlacement(exam, period, placement.getRoomPlacements()));
        }
        Set<ExamRoomPlacement> rooms = exam.findBestAvailableRooms(assignment, period);
        if (rooms == null)
            continue;
        return new ExamSimpleNeighbour(assignment, new ExamPlacement(exam, period, rooms));
    }
    return null;
}
Also used : ExamRoomSharing(org.cpsolver.exam.model.ExamRoomSharing) 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)

Example 17 with ExamRoomPlacement

use of org.cpsolver.exam.model.ExamRoomPlacement 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)

Example 18 with ExamRoomPlacement

use of org.cpsolver.exam.model.ExamRoomPlacement in project cpsolver by UniTime.

the class ExamCriterion method getBounds.

@Override
public double[] getBounds(Assignment<Exam, ExamPlacement> assignment, Collection<Exam> exams) {
    double[] bounds = new double[] { 0.0, 0.0 };
    for (Exam exam : exams) {
        Double min = null, max = null;
        for (ExamPeriodPlacement period : exam.getPeriodPlacements()) {
            if (exam.getMaxRooms() == 0) {
                double value = getValue(assignment, new ExamPlacement(exam, period, null), null);
                if (min == null) {
                    min = value;
                    max = value;
                    continue;
                }
                min = Math.min(min, value);
                max = Math.max(max, value);
            } else {
                for (ExamRoomPlacement room : exam.getRoomPlacements()) {
                    Set<ExamRoomPlacement> rooms = new HashSet<ExamRoomPlacement>();
                    rooms.add(room);
                    double value = getValue(assignment, new ExamPlacement(exam, period, rooms), null);
                    if (min == null) {
                        min = value;
                        max = value;
                        continue;
                    }
                    min = Math.min(min, value);
                    max = Math.max(max, value);
                }
            }
        }
        if (min != null) {
            bounds[0] += min;
            bounds[1] += max;
        }
    }
    return bounds;
}
Also used : ExamRoomPlacement(org.cpsolver.exam.model.ExamRoomPlacement) ExamPlacement(org.cpsolver.exam.model.ExamPlacement) ExamPeriodPlacement(org.cpsolver.exam.model.ExamPeriodPlacement) Exam(org.cpsolver.exam.model.Exam) HashSet(java.util.HashSet)

Example 19 with ExamRoomPlacement

use of org.cpsolver.exam.model.ExamRoomPlacement in project cpsolver by UniTime.

the class RoomPerturbationPenalty method getValue.

@Override
public double getValue(Assignment<Exam, ExamPlacement> assignment, ExamPlacement value, Set<ExamPlacement> conflicts) {
    if (!isMPP())
        return 0;
    Exam exam = value.variable();
    ExamPlacement initial = exam.getInitialAssignment();
    if (initial == null)
        return 0;
    int penalty = 0;
    if (value.getRoomPlacements() != null)
        for (ExamRoomPlacement rp : value.getRoomPlacements()) {
            if (initial.getRoomPlacements() == null || !initial.getRoomPlacements().contains(rp))
                penalty++;
        }
    return penalty;
}
Also used : ExamRoomPlacement(org.cpsolver.exam.model.ExamRoomPlacement) ExamPlacement(org.cpsolver.exam.model.ExamPlacement) Exam(org.cpsolver.exam.model.Exam)

Example 20 with ExamRoomPlacement

use of org.cpsolver.exam.model.ExamRoomPlacement in project cpsolver by UniTime.

the class RoomSplitDistancePenalty method getValue.

@Override
public double getValue(Assignment<Exam, ExamPlacement> assignment, ExamPlacement value, Set<ExamPlacement> conflicts) {
    if (value.getRoomPlacements() == null || value.getRoomPlacements().size() <= 1)
        return 0.0;
    double distance = 0.0;
    for (ExamRoomPlacement r : value.getRoomPlacements()) {
        for (ExamRoomPlacement w : value.getRoomPlacements()) {
            if (r.getRoom().getId() < w.getRoom().getId())
                distance += r.getRoom().getDistanceInMeters(w.getRoom());
        }
    }
    int pairs = value.getRoomPlacements().size() * (value.getRoomPlacements().size() - 1) / 2;
    return distance / pairs;
}
Also used : ExamRoomPlacement(org.cpsolver.exam.model.ExamRoomPlacement)

Aggregations

ExamRoomPlacement (org.cpsolver.exam.model.ExamRoomPlacement)25 Exam (org.cpsolver.exam.model.Exam)21 ExamPlacement (org.cpsolver.exam.model.ExamPlacement)21 ExamPeriodPlacement (org.cpsolver.exam.model.ExamPeriodPlacement)11 ArrayList (java.util.ArrayList)9 ExamModel (org.cpsolver.exam.model.ExamModel)9 CSVFile (org.cpsolver.ifs.util.CSVFile)6 CSVField (org.cpsolver.ifs.util.CSVFile.CSVField)6 HashSet (java.util.HashSet)4 ExamOwner (org.cpsolver.exam.model.ExamOwner)4 ExamStudent (org.cpsolver.exam.model.ExamStudent)4 TreeSet (java.util.TreeSet)3 ExamPeriod (org.cpsolver.exam.model.ExamPeriod)3 HashMap (java.util.HashMap)2 StudentBackToBackConflicts (org.cpsolver.exam.criteria.StudentBackToBackConflicts)2 StudentDistanceBackToBackConflicts (org.cpsolver.exam.criteria.StudentDistanceBackToBackConflicts)2 ExamInstructor (org.cpsolver.exam.model.ExamInstructor)2 ExamRoomSharing (org.cpsolver.exam.model.ExamRoomSharing)2 ExamSimpleNeighbour (org.cpsolver.exam.neighbours.ExamSimpleNeighbour)2 AssignmentContext (org.cpsolver.ifs.assignment.context.AssignmentContext)2