Search in sources :

Example 11 with ExamPeriodPlacement

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

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

the class PeriodPenalty method getBounds.

@Override
public double[] getBounds(Assignment<Exam, ExamPlacement> assignment, Collection<Exam> variables) {
    double[] bounds = new double[] { 0.0, 0.0 };
    for (Exam exam : variables) {
        if (!exam.getPeriodPlacements().isEmpty()) {
            int minPenalty = Integer.MAX_VALUE, maxPenalty = Integer.MIN_VALUE;
            for (ExamPeriodPlacement periodPlacement : exam.getPeriodPlacements()) {
                if (iSoftPeriods != null && (periodPlacement.getExamPenalty() == iSoftPeriods || periodPlacement.getPeriod().getPenalty() == iSoftPeriods))
                    continue;
                minPenalty = Math.min(minPenalty, periodPlacement.getPenalty());
                maxPenalty = Math.max(maxPenalty, periodPlacement.getPenalty());
            }
            bounds[0] += minPenalty;
            bounds[1] += maxPenalty;
        }
    }
    return bounds;
}
Also used : ExamPeriodPlacement(org.cpsolver.exam.model.ExamPeriodPlacement) Exam(org.cpsolver.exam.model.Exam)

Example 13 with ExamPeriodPlacement

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

the class ExamSplitMoves method bestSplit.

/**
     * Find a best split for the given exam. Only improving neighbors are considered. 
     * @param assignment current assignment
     * @param exam an exam to be split
     * @return best neighbor that will do the split
     */
public ExamSplitNeighbour bestSplit(Assignment<Exam, ExamPlacement> assignment, Exam exam) {
    ExamSplitNeighbour split = null;
    ExamPlacement placement = assignment.getValue(exam);
    int px = ToolBox.random(exam.getPeriodPlacements().size());
    for (int p = 0; p < exam.getPeriodPlacements().size(); p++) {
        // Iterate over possible periods
        ExamPeriodPlacement period = exam.getPeriodPlacements().get((p + px) % exam.getPeriodPlacements().size());
        if (placement != null && placement.getPeriod().equals(period))
            continue;
        // Try to create a neighbor
        ExamSplitNeighbour s = new ExamSplitNeighbour(assignment, exam, new ExamPlacement(exam, period, null));
        if (split == null || s.value(assignment) < split.value(assignment)) {
            // If improving, try to find available rooms
            Set<ExamRoomPlacement> rooms = findBestAvailableRooms(assignment, exam, period, s.nrStudents());
            if (rooms != null) {
                // Remember as best split
                s.placement().getRoomPlacements().addAll(rooms);
                split = s;
            }
        }
    }
    return split;
}
Also used : ExamRoomPlacement(org.cpsolver.exam.model.ExamRoomPlacement) ExamPlacement(org.cpsolver.exam.model.ExamPlacement) ExamPeriodPlacement(org.cpsolver.exam.model.ExamPeriodPlacement)

Aggregations

ExamPeriodPlacement (org.cpsolver.exam.model.ExamPeriodPlacement)13 Exam (org.cpsolver.exam.model.Exam)12 ExamPlacement (org.cpsolver.exam.model.ExamPlacement)11 ExamRoomPlacement (org.cpsolver.exam.model.ExamRoomPlacement)11 ExamModel (org.cpsolver.exam.model.ExamModel)8 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 HashMap (java.util.HashMap)2 ExamSimpleNeighbour (org.cpsolver.exam.neighbours.ExamSimpleNeighbour)2 AssignmentContext (org.cpsolver.ifs.assignment.context.AssignmentContext)2 NeighbourSelectionWithContext (org.cpsolver.ifs.assignment.context.NeighbourSelectionWithContext)2 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 ExamDistributionConstraint (org.cpsolver.exam.model.ExamDistributionConstraint)1 ExamInstructor (org.cpsolver.exam.model.ExamInstructor)1 ExamRoomSharing (org.cpsolver.exam.model.ExamRoomSharing)1 ExamStudent (org.cpsolver.exam.model.ExamStudent)1 Assignment (org.cpsolver.ifs.assignment.Assignment)1 LazySwap (org.cpsolver.ifs.model.LazySwap)1 Neighbour (org.cpsolver.ifs.model.Neighbour)1