Search in sources :

Example 6 with Exam

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

the class ExamSimulatedAnnealing method selectNeighbour.

/**
     * Select neighbour -- generate a move
     * {@link ExamSimulatedAnnealing#genMove(Solution)} until an acceptable
     * neighbour is found
     * {@link ExamSimulatedAnnealing#accept(Solution, Neighbour)}, keep
     * increasing iteration {@link ExamSimulatedAnnealing.Context#incIter(Solution)}.
     */
@Override
public Neighbour<Exam, ExamPlacement> selectNeighbour(Solution<Exam, ExamPlacement> solution) {
    Context context = getContext(solution.getAssignment());
    context.activateIfNeeded();
    Neighbour<Exam, ExamPlacement> neighbour = null;
    while ((neighbour = genMove(solution)) != null) {
        context.incMoves(neighbour.value(solution.getAssignment()));
        if (accept(solution, neighbour))
            break;
    }
    if (neighbour == null)
        context.reset();
    return (neighbour == null ? null : neighbour);
}
Also used : AssignmentContext(org.cpsolver.ifs.assignment.context.AssignmentContext) NeighbourSelectionWithContext(org.cpsolver.ifs.assignment.context.NeighbourSelectionWithContext) ExamPlacement(org.cpsolver.exam.model.ExamPlacement) Exam(org.cpsolver.exam.model.Exam)

Example 7 with Exam

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

the class ExamSimulatedAnnealing method accept.

/**
     * True if the given neighboir is to be be accepted
     * 
     * @param solution
     *            current solution
     * @param neighbour
     *            proposed move
     * @return true if generated random number is below
     *         {@link ExamSimulatedAnnealing.Context#prob(double)}
     */
protected boolean accept(Solution<Exam, ExamPlacement> solution, Neighbour<Exam, ExamPlacement> neighbour) {
    if (neighbour instanceof LazyNeighbour) {
        ((LazyNeighbour<Exam, ExamPlacement>) neighbour).setAcceptanceCriterion(this);
        return true;
    }
    Assignment<Exam, ExamPlacement> assignment = solution.getAssignment();
    double value = (iRelativeAcceptance ? neighbour.value(assignment) : solution.getModel().getTotalValue(assignment) + neighbour.value(assignment) - solution.getBestValue());
    Context context = getContext(solution.getAssignment());
    double prob = context.prob(value);
    if (prob >= 1.0 || ToolBox.random() < prob) {
        context.accepted(neighbour.value(assignment));
        return true;
    }
    return false;
}
Also used : AssignmentContext(org.cpsolver.ifs.assignment.context.AssignmentContext) NeighbourSelectionWithContext(org.cpsolver.ifs.assignment.context.NeighbourSelectionWithContext) ExamPlacement(org.cpsolver.exam.model.ExamPlacement) LazyNeighbour(org.cpsolver.ifs.model.LazyNeighbour) Exam(org.cpsolver.exam.model.Exam)

Example 8 with Exam

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

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

the class RoomSizePenalty method getValue.

@Override
public double getValue(Assignment<Exam, ExamPlacement> assignment, ExamPlacement value, Set<ExamPlacement> conflicts) {
    Exam exam = value.variable();
    int size = 0;
    if (value.getRoomPlacements() != null)
        for (ExamRoomPlacement r : value.getRoomPlacements()) {
            size += r.getSize(exam.hasAltSeating());
        }
    int diff = size - exam.getSize();
    return (diff < 0 ? 0 : Math.pow(diff, iRoomSizeFactor));
}
Also used : ExamRoomPlacement(org.cpsolver.exam.model.ExamRoomPlacement) Exam(org.cpsolver.exam.model.Exam)

Example 10 with Exam

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

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