Search in sources :

Example 61 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 62 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)62 ExamPlacement (org.cpsolver.exam.model.ExamPlacement)38 ExamModel (org.cpsolver.exam.model.ExamModel)26 ExamRoomPlacement (org.cpsolver.exam.model.ExamRoomPlacement)21 ExamPeriod (org.cpsolver.exam.model.ExamPeriod)19 ExamStudent (org.cpsolver.exam.model.ExamStudent)18 Set (java.util.Set)15 ArrayList (java.util.ArrayList)13 ExamPeriodPlacement (org.cpsolver.exam.model.ExamPeriodPlacement)12 CSVFile (org.cpsolver.ifs.util.CSVFile)12 CSVField (org.cpsolver.ifs.util.CSVFile.CSVField)12 HashSet (java.util.HashSet)11 ExamInstructor (org.cpsolver.exam.model.ExamInstructor)10 DecimalFormat (java.text.DecimalFormat)6 AssignmentContext (org.cpsolver.ifs.assignment.context.AssignmentContext)6 NeighbourSelectionWithContext (org.cpsolver.ifs.assignment.context.NeighbourSelectionWithContext)6 HashMap (java.util.HashMap)4 TreeSet (java.util.TreeSet)4 ExamOwner (org.cpsolver.exam.model.ExamOwner)4 IOException (java.io.IOException)3