Search in sources :

Example 26 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();
    ExamModel m = (ExamModel) getModel();
    Map<ExamStudent, Set<Exam>> students = m.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++;
    }
    if (m.isCheckForPeriodOverlaps()) {
        for (ExamPeriod p : m.getPeriods()) {
            if (period.hasIntersection(p)) {
                Map<ExamStudent, Set<Exam>> others = m.getStudentsOfPeriod(assignment, p);
                s: for (ExamStudent s : exam.getStudents()) {
                    Set<Exam> exams = students.get(s);
                    if (exams == null || exams.size() + (exams.contains(exam) ? 0 : 1) <= 1) {
                        Set<Exam> other = others.get(s);
                        if (other != null && !other.isEmpty())
                            for (Exam x : other) {
                                if (period.hasIntersection(exam, x, p)) {
                                    penalty++;
                                    continue s;
                                }
                            }
                    }
                }
            }
        }
    }
    /*
        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 27 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)27 Exam (org.cpsolver.exam.model.Exam)26 Set (java.util.Set)15 ExamPeriod (org.cpsolver.exam.model.ExamPeriod)13 ExamPlacement (org.cpsolver.exam.model.ExamPlacement)13 ExamStudent (org.cpsolver.exam.model.ExamStudent)10 HashSet (java.util.HashSet)9 ExamRoomPlacement (org.cpsolver.exam.model.ExamRoomPlacement)9 ExamInstructor (org.cpsolver.exam.model.ExamInstructor)8 ExamPeriodPlacement (org.cpsolver.exam.model.ExamPeriodPlacement)8 ArrayList (java.util.ArrayList)4 IOException (java.io.IOException)3 File (java.io.File)2 DecimalFormat (java.text.DecimalFormat)2 HashMap (java.util.HashMap)2 Map (java.util.Map)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