Search in sources :

Example 36 with Exam

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

the class DistributionPenalty method getValue.

@Override
public double getValue(Assignment<Exam, ExamPlacement> assignment, Collection<Exam> variables) {
    int penalty = 0;
    Set<ExamDistributionConstraint> added = new HashSet<ExamDistributionConstraint>();
    for (Exam exam : variables) {
        for (ExamDistributionConstraint dc : exam.getDistributionConstraints()) {
            if (added.add(dc)) {
                if (dc.isHard() || (iSoftDistributions != null && iSoftDistributions == dc.getWeight()))
                    continue;
                if (!dc.isSatisfied(assignment))
                    penalty += dc.getWeight();
            }
        }
    }
    return penalty;
}
Also used : ExamDistributionConstraint(org.cpsolver.exam.model.ExamDistributionConstraint) ExamDistributionConstraint(org.cpsolver.exam.model.ExamDistributionConstraint) Exam(org.cpsolver.exam.model.Exam) HashSet(java.util.HashSet)

Example 37 with Exam

use of org.cpsolver.exam.model.Exam 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 38 with Exam

use of org.cpsolver.exam.model.Exam 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 39 with Exam

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

the class StudentDirectConflicts method getValue.

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

Example 40 with Exam

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

the class InstructorBackToBackConflicts method getValue.

@Override
public double getValue(Assignment<Exam, ExamPlacement> assignment, ExamPlacement value, Set<ExamPlacement> conflicts) {
    Exam exam = value.variable();
    int penalty = 0;
    ExamPeriod period = value.getPeriod();
    Map<ExamInstructor, Set<Exam>> prev = (period.prev() != null && (isDayBreakBackToBack() || period.prev().getDay() == period.getDay()) ? ((ExamModel) getModel()).getInstructorsOfPeriod(assignment, period.prev()) : null);
    Map<ExamInstructor, Set<Exam>> next = (period.next() != null && (isDayBreakBackToBack() || period.next().getDay() == period.getDay()) ? ((ExamModel) getModel()).getInstructorsOfPeriod(assignment, period.next()) : null);
    for (ExamInstructor s : exam.getInstructors()) {
        if (prev != null) {
            Set<Exam> exams = prev.get(s);
            if (exams != null) {
                int nrExams = exams.size() + (exams.contains(exam) ? -1 : 0);
                penalty += nrExams;
            }
        }
        if (next != null) {
            Set<Exam> exams = next.get(s);
            if (exams != null) {
                int nrExams = exams.size() + (exams.contains(exam) ? -1 : 0);
                penalty += nrExams;
            }
        }
    }
    /*
        for (ExamInstructor s : exam.getInstructors()) {
            if (period.prev() != null) {
                if (isDayBreakBackToBack() || period.prev().getDay() == period.getDay()) {
                    Set<Exam> exams = s.getExams(assignment, period.prev());
                    int nrExams = exams.size() + (exams.contains(exam) ? -1 : 0);
                    penalty += nrExams;
                }
            }
            if (period.next() != null) {
                if (isDayBreakBackToBack() || period.next().getDay() == period.getDay()) {
                    Set<Exam> exams = s.getExams(assignment, period.next());
                    int nrExams = exams.size() + (exams.contains(exam) ? -1 : 0);
                    penalty += nrExams;
                }
            }
        }
        */
    return penalty;
}
Also used : ExamPeriod(org.cpsolver.exam.model.ExamPeriod) ExamInstructor(org.cpsolver.exam.model.ExamInstructor) Set(java.util.Set) ExamModel(org.cpsolver.exam.model.ExamModel) 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