Search in sources :

Example 1 with ExamPeriod

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

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

the class StudentMoreThan2ADayConflicts 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()).getStudentsOfDay(assignment, period);
    for (ExamStudent s : exam.getStudents()) {
        Set<Exam> exams = students.get(s);
        if (exams == null || exams.size() < 2)
            continue;
        int nrExams = exams.size() + (exams.contains(exam) ? 0 : 1);
        if (nrExams > 2)
            penalty++;
    }
    /*
        for (ExamStudent s : exam.getStudents()) {
            Set<Exam> exams = s.getExamsADay(assignment, period);
            int nrExams = exams.size() + (exams.contains(exam) ? 0 : 1);
            if (nrExams > 2)
                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 3 with ExamPeriod

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

the class StudentBackToBackConflicts 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>> prev = (period.prev() != null && (isDayBreakBackToBack() || period.prev().getDay() == period.getDay()) ? ((ExamModel) getModel()).getStudentsOfPeriod(assignment, period.prev()) : null);
    Map<ExamStudent, Set<Exam>> next = (period.next() != null && (isDayBreakBackToBack() || period.next().getDay() == period.getDay()) ? ((ExamModel) getModel()).getStudentsOfPeriod(assignment, period.next()) : null);
    for (ExamStudent s : exam.getStudents()) {
        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 (ExamStudent s : exam.getStudents()) {
            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) Set(java.util.Set) ExamModel(org.cpsolver.exam.model.ExamModel) ExamStudent(org.cpsolver.exam.model.ExamStudent) Exam(org.cpsolver.exam.model.Exam)

Example 4 with ExamPeriod

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

the class StudentDistanceBackToBackConflicts method getValue.

@Override
public double getValue(Assignment<Exam, ExamPlacement> assignment, ExamPlacement value, Set<ExamPlacement> conflicts) {
    Exam exam = value.variable();
    if (getBackToBackDistance() < 0)
        return 0;
    int penalty = 0;
    ExamPeriod period = value.getPeriod();
    Map<ExamStudent, Set<Exam>> prev = (period.prev() != null && period.prev().getDay() == period.getDay() ? ((ExamModel) getModel()).getStudentsOfPeriod(assignment, period.prev()) : null);
    Map<ExamStudent, Set<Exam>> next = (period.next() != null && period.next().getDay() == period.getDay() ? ((ExamModel) getModel()).getStudentsOfPeriod(assignment, period.next()) : null);
    for (ExamStudent s : exam.getStudents()) {
        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 (ExamStudent s : exam.getStudents()) {
            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)) > getBackToBackDistance())
                            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)) > getBackToBackDistance())
                            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 5 with ExamPeriod

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

the class ExamSplitter method delta.

/**
     * Difference in the total weighted student conflicts (including {@link StudentDirectConflicts},
     * {@link StudentMoreThan2ADayConflicts}, and {@link StudentBackToBackConflicts}) if a student
     * is moved from an exam with one placement into an exam with another placement.
     * @param assignment current assignment
     * @param student a student in question
     * @param oldPlacement placement of the exam in which the student is now
     * @param newPlacement placement of the exam into which the student would be moved
     * @return difference in the student conflict weight
     */
public double delta(Assignment<Exam, ExamPlacement> assignment, ExamStudent student, ExamPlacement oldPlacement, ExamPlacement newPlacement) {
    double delta = 0;
    // Weights of removing student form the old placement 
    if (oldPlacement != null) {
        Exam exam = oldPlacement.variable();
        ExamPeriod period = oldPlacement.getPeriod();
        Set<Exam> examsThisPeriod = student.getExams(assignment, period);
        if (examsThisPeriod.size() > (examsThisPeriod.contains(exam) ? 1 : 0))
            // will remove a direct conflict
            delta -= iStudentDirectConflicts.getWeight();
        ExamPeriod prev = period.prev();
        if (prev != null && (prev.getDay() == period.getDay() || isDayBreakBackToBack())) {
            Set<Exam> examsPrevPeriod = student.getExams(assignment, prev);
            if (examsPrevPeriod.size() > (examsPrevPeriod.contains(exam) ? 1 : 0))
                // will remove a back-to-back conflict
                delta -= iStudentBackToBackConflicts.getWeight();
        }
        ExamPeriod next = period.next();
        if (next != null && (next.getDay() == period.getDay() || isDayBreakBackToBack())) {
            Set<Exam> examsNextPeriod = student.getExams(assignment, next);
            if (examsNextPeriod.size() > (examsNextPeriod.contains(exam) ? 1 : 0))
                // will remove a back-to-back conflict
                delta -= iStudentBackToBackConflicts.getWeight();
        }
        Set<Exam> examsInADay = student.getExamsADay(assignment, period);
        if (examsInADay.size() > (examsInADay.contains(exam) ? 3 : 2))
            // will remove a more than 2 on a day conflict
            delta -= iStudentMoreThan2ADayConflicts.getWeight();
    }
    // Weights of moving student into the new placement
    if (newPlacement != null) {
        Exam exam = newPlacement.variable();
        ExamPeriod period = newPlacement.getPeriod();
        Set<Exam> examsThisPeriod = student.getExams(assignment, period);
        if (examsThisPeriod.size() > (examsThisPeriod.contains(exam) ? 1 : 0))
            // will add a direct conflict
            delta += iStudentDirectConflicts.getWeight();
        ExamPeriod prev = period.prev();
        if (prev != null && (prev.getDay() == period.getDay() || isDayBreakBackToBack())) {
            Set<Exam> examsPrevPeriod = student.getExams(assignment, prev);
            if (examsPrevPeriod.size() > (examsPrevPeriod.contains(exam) ? 1 : 0))
                // will add a back-to-back conflict
                delta += iStudentBackToBackConflicts.getWeight();
        }
        ExamPeriod next = period.next();
        if (next != null && (next.getDay() == period.getDay() || isDayBreakBackToBack())) {
            Set<Exam> examsNextPeriod = student.getExams(assignment, next);
            if (examsNextPeriod.size() > (examsNextPeriod.contains(exam) ? 1 : 0))
                // will add a back-to-back conflict
                delta += iStudentBackToBackConflicts.getWeight();
        }
        Set<Exam> examsInADay = student.getExamsADay(assignment, period);
        if (examsInADay.size() > (examsInADay.contains(exam) ? 3 : 2))
            // will add a more than 2 on a day conflict
            delta += iStudentMoreThan2ADayConflicts.getWeight();
    }
    return delta;
}
Also used : ExamPeriod(org.cpsolver.exam.model.ExamPeriod) Exam(org.cpsolver.exam.model.Exam)

Aggregations

ExamPeriod (org.cpsolver.exam.model.ExamPeriod)13 Exam (org.cpsolver.exam.model.Exam)12 ExamStudent (org.cpsolver.exam.model.ExamStudent)7 Set (java.util.Set)6 ExamModel (org.cpsolver.exam.model.ExamModel)6 CSVFile (org.cpsolver.ifs.util.CSVFile)6 CSVField (org.cpsolver.ifs.util.CSVFile.CSVField)6 ExamPlacement (org.cpsolver.exam.model.ExamPlacement)5 ArrayList (java.util.ArrayList)4 StudentBackToBackConflicts (org.cpsolver.exam.criteria.StudentBackToBackConflicts)3 ExamInstructor (org.cpsolver.exam.model.ExamInstructor)3 ExamOwner (org.cpsolver.exam.model.ExamOwner)3 ExamRoomPlacement (org.cpsolver.exam.model.ExamRoomPlacement)3 StudentDistanceBackToBackConflicts (org.cpsolver.exam.criteria.StudentDistanceBackToBackConflicts)2 TreeSet (java.util.TreeSet)1 InstructorBackToBackConflicts (org.cpsolver.exam.criteria.InstructorBackToBackConflicts)1 InstructorDistanceBackToBackConflicts (org.cpsolver.exam.criteria.InstructorDistanceBackToBackConflicts)1 ExamRoom (org.cpsolver.exam.model.ExamRoom)1