Search in sources :

Example 11 with ExamModel

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

the class InstructorDistanceBackToBackConflicts method getValue.

@Override
public double getValue(Assignment<Exam, ExamPlacement> assignment, ExamPlacement value, Set<ExamPlacement> conflicts) {
    Exam exam = value.variable();
    double btbDist = getBackToBackDistance();
    if (btbDist < 0)
        return 0;
    int penalty = 0;
    ExamPeriod period = value.getPeriod();
    Map<ExamInstructor, Set<Exam>> prev = (period.prev() != null && period.prev().getDay() == period.getDay() ? ((ExamModel) getModel()).getInstructorsOfPeriod(assignment, period.prev()) : null);
    Map<ExamInstructor, Set<Exam>> next = (period.next() != null && 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)
                for (Exam x : exams) {
                    if (x.equals(exam))
                        continue;
                    if (value.getDistanceInMeters(assignment.getValue(x)) > getBackToBackDistance())
                        penalty++;
                }
        }
        if (next != null) {
            Set<Exam> exams = next.get(s);
            if (exams != null)
                for (Exam x : exams) {
                    if (x.equals(exam))
                        continue;
                    if (value.getDistanceInMeters(assignment.getValue(x)) > getBackToBackDistance())
                        penalty++;
                }
        }
    }
    /*
        for (ExamInstructor s : exam.getInstructors()) {
            if (period.prev() != null) {
                if (period.prev().getDay() == period.getDay()) {
                    for (Exam x : s.getExams(assignment, period.prev())) {
                        if (x.equals(exam))
                            continue;
                        if (value.getDistanceInMeters(assignment.getValue(x)) > btbDist)
                            penalty++;
                    }
                }
            }
            if (period.next() != null) {
                if (period.next().getDay() == period.getDay()) {
                    for (Exam x : s.getExams(assignment, period.next())) {
                        if (x.equals(exam))
                            continue;
                        if (value.getDistanceInMeters(assignment.getValue(x)) > btbDist)
                            penalty++;
                    }
                }
            }
        }
        */
    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)

Example 12 with ExamModel

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

the class InstructorMoreThan2ADayConflicts 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()).getInstructorsOfDay(assignment, value.getPeriod());
    for (ExamInstructor s : exam.getInstructors()) {
        Set<Exam> exams = instructors.get(s);
        if (exams == null || exams.size() < 2)
            continue;
        int nrExams = exams.size() + (exams.contains(exam) ? 0 : 1);
        if (nrExams > 2)
            penalty++;
    }
    /*
        for (ExamInstructor s : exam.getInstructors()) {
            Set<Exam> exams = s.getExamsADay(assignment, value.getPeriod());
            int nrExams = exams.size() + (exams.contains(exam) ? 0 : 1);
            if (nrExams > 2)
                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 13 with ExamModel

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

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

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

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