Search in sources :

Example 31 with Exam

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

the class PerturbationPenalty 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;
    return Math.abs(initial.getPeriod().getIndex() - value.getPeriod().getIndex()) * (1 + exam.getSize());
}
Also used : ExamPlacement(org.cpsolver.exam.model.ExamPlacement) Exam(org.cpsolver.exam.model.Exam)

Example 32 with Exam

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

the class RoomPenalty method getBounds.

@Override
public double[] getBounds(Assignment<Exam, ExamPlacement> assignment, Collection<Exam> variables) {
    double[] bounds = new double[] { 0.0, 0.0 };
    for (Exam exam : variables) {
        if (!exam.getRoomPlacements().isEmpty()) {
            int minPenalty = Integer.MAX_VALUE, maxPenalty = Integer.MIN_VALUE;
            for (ExamRoomPlacement roomPlacement : exam.getRoomPlacements()) {
                if (iSoftRooms != null && iSoftRooms == roomPlacement.getPenalty())
                    continue;
                if (!isAvailable(roomPlacement.getRoom()))
                    continue;
                minPenalty = Math.min(minPenalty, 2 * roomPlacement.getPenalty() + getMinPenalty(roomPlacement.getRoom()));
                maxPenalty = Math.max(maxPenalty, 2 * roomPlacement.getPenalty() + getMaxPenalty(roomPlacement.getRoom()));
            }
            bounds[0] += minPenalty;
            bounds[1] += maxPenalty;
        }
    }
    return bounds;
}
Also used : ExamRoomPlacement(org.cpsolver.exam.model.ExamRoomPlacement) Exam(org.cpsolver.exam.model.Exam)

Example 33 with Exam

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

the class PeriodSizePenalty method getBounds.

@Override
public double[] getBounds(Assignment<Exam, ExamPlacement> assignment, Collection<Exam> variables) {
    double[] bounds = new double[] { 0.0, 0.0 };
    for (Exam exam : variables) {
        if (!exam.getPeriodPlacements().isEmpty()) {
            int minSizePenalty = Integer.MAX_VALUE, maxSizePenalty = Integer.MIN_VALUE;
            for (ExamPeriodPlacement periodPlacement : exam.getPeriodPlacements()) {
                minSizePenalty = Math.min(minSizePenalty, periodPlacement.getPenalty() * (exam.getSize() + 1));
                maxSizePenalty = Math.max(maxSizePenalty, periodPlacement.getPenalty() * (exam.getSize() + 1));
            }
            bounds[0] += minSizePenalty;
            bounds[1] += maxSizePenalty;
        }
    }
    return bounds;
}
Also used : ExamPeriodPlacement(org.cpsolver.exam.model.ExamPeriodPlacement) Exam(org.cpsolver.exam.model.Exam)

Example 34 with Exam

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

the class InstructorDirectConflicts method getValue.

@Override
public double getValue(Assignment<Exam, ExamPlacement> assignment, ExamPlacement value, Set<ExamPlacement> conflicts) {
    Exam exam = value.variable();
    int penalty = 0;
    Map<ExamInstructor, Set<Exam>> instructors = ((ExamModel) getModel()).getInstructorsOfPeriod(assignment, value.getPeriod());
    for (ExamInstructor s : exam.getInstructors()) {
        Set<Exam> exams = instructors.get(s);
        if (exams == null)
            continue;
        int nrExams = exams.size() + (exams.contains(exam) ? 0 : 1);
        if (nrExams > 1)
            penalty++;
    }
    /*
        for (ExamInstructor s : exam.getInstructors()) {
            Set<Exam> exams = s.getExams(assignment, value.getPeriod());
            int nrExams = exams.size() + (exams.contains(exam) ? 0 : 1);
            if (nrExams > 1)
                penalty++;
        }
        */
    return penalty;
}
Also used : ExamInstructor(org.cpsolver.exam.model.ExamInstructor) Set(java.util.Set) ExamModel(org.cpsolver.exam.model.ExamModel) Exam(org.cpsolver.exam.model.Exam)

Example 35 with Exam

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

the class ExamHillClimbing method selectNeighbour.

/**
     * Select one of the given neighbourhoods randomly, select neighbour, return
     * it if its value is below or equal to zero (continue with the next
     * selection otherwise). Return null when the given number of idle
     * iterations is reached.
     */
@Override
public Neighbour<Exam, ExamPlacement> selectNeighbour(Solution<Exam, ExamPlacement> solution) {
    Context context = getContext(solution.getAssignment());
    context.activateIfNeeded();
    while (true) {
        if (context.incIter(solution))
            break;
        NeighbourSelection<Exam, ExamPlacement> ns = iNeighbours.get(ToolBox.random(iNeighbours.size()));
        Neighbour<Exam, ExamPlacement> n = ns.selectNeighbour(solution);
        if (n != null) {
            if (n instanceof LazyNeighbour) {
                ((LazyNeighbour<Exam, ExamPlacement>) n).setAcceptanceCriterion(this);
                return n;
            } else if (n.value(solution.getAssignment()) <= 0.0)
                return n;
        }
    }
    context.reset();
    return null;
}
Also used : AssignmentContext(org.cpsolver.ifs.assignment.context.AssignmentContext) NeighbourSelectionWithContext(org.cpsolver.ifs.assignment.context.NeighbourSelectionWithContext) ExamPlacement(org.cpsolver.exam.model.ExamPlacement) LazyNeighbour(org.cpsolver.ifs.model.LazyNeighbour) Exam(org.cpsolver.exam.model.Exam)

Aggregations

Exam (org.cpsolver.exam.model.Exam)56 ExamPlacement (org.cpsolver.exam.model.ExamPlacement)38 ExamRoomPlacement (org.cpsolver.exam.model.ExamRoomPlacement)21 ExamModel (org.cpsolver.exam.model.ExamModel)20 ExamStudent (org.cpsolver.exam.model.ExamStudent)14 ArrayList (java.util.ArrayList)13 ExamPeriod (org.cpsolver.exam.model.ExamPeriod)12 ExamPeriodPlacement (org.cpsolver.exam.model.ExamPeriodPlacement)12 CSVFile (org.cpsolver.ifs.util.CSVFile)12 CSVField (org.cpsolver.ifs.util.CSVFile.CSVField)12 Set (java.util.Set)9 ExamInstructor (org.cpsolver.exam.model.ExamInstructor)8 DecimalFormat (java.text.DecimalFormat)6 AssignmentContext (org.cpsolver.ifs.assignment.context.AssignmentContext)6 NeighbourSelectionWithContext (org.cpsolver.ifs.assignment.context.NeighbourSelectionWithContext)6 HashSet (java.util.HashSet)5 HashMap (java.util.HashMap)4 TreeSet (java.util.TreeSet)4 ExamOwner (org.cpsolver.exam.model.ExamOwner)4 IOException (java.io.IOException)3