Search in sources :

Example 46 with Exam

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

the class ExamRandomMove method selectNeighbour.

/**
 * Select an exam randomly, select an available period randomly (from
 * {@link Exam#getPeriodPlacements()}), select rooms using
 * {@link Exam#findBestAvailableRooms(Assignment, ExamPeriodPlacement)}.
 */
@Override
public Neighbour<Exam, ExamPlacement> selectNeighbour(Solution<Exam, ExamPlacement> solution) {
    ExamModel model = (ExamModel) solution.getModel();
    Assignment<Exam, ExamPlacement> assignment = solution.getAssignment();
    Exam exam = ToolBox.random(model.variables());
    int px = ToolBox.random(exam.getPeriodPlacements().size());
    for (int p = 0; p < exam.getPeriodPlacements().size(); p++) {
        ExamPeriodPlacement period = exam.getPeriodPlacements().get((p + px) % exam.getPeriodPlacements().size());
        if (iCheckStudentConflicts && exam.countStudentConflicts(assignment, period) > 0)
            continue;
        if (iCheckDistributionConstraints && !exam.checkDistributionConstraints(assignment, period))
            continue;
        Set<ExamRoomPlacement> rooms = exam.findBestAvailableRooms(assignment, period);
        if (rooms == null)
            continue;
        return new ExamSimpleNeighbour(assignment, new ExamPlacement(exam, period, rooms));
    }
    return null;
}
Also used : ExamRoomPlacement(org.cpsolver.exam.model.ExamRoomPlacement) ExamPlacement(org.cpsolver.exam.model.ExamPlacement) ExamModel(org.cpsolver.exam.model.ExamModel) ExamPeriodPlacement(org.cpsolver.exam.model.ExamPeriodPlacement) Exam(org.cpsolver.exam.model.Exam)

Example 47 with Exam

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

the class ExamTimeMove method selectNeighbour.

/**
 * Select an exam randomly,
 * select an available period randomly (if it is not assigned),
 * use rooms if possible, select rooms using {@link Exam#findBestAvailableRooms(Assignment, ExamPeriodPlacement)} if not (exam is unassigned, a room is not available or used).
 */
@Override
public Neighbour<Exam, ExamPlacement> selectNeighbour(Solution<Exam, ExamPlacement> solution) {
    ExamModel model = (ExamModel) solution.getModel();
    Assignment<Exam, ExamPlacement> assignment = solution.getAssignment();
    ExamRoomSharing sharing = model.getRoomSharing();
    Exam exam = ToolBox.random(model.variables());
    ExamPlacement placement = assignment.getValue(exam);
    int px = ToolBox.random(exam.getPeriodPlacements().size());
    for (int p = 0; p < exam.getPeriodPlacements().size(); p++) {
        ExamPeriodPlacement period = exam.getPeriodPlacements().get((p + px) % exam.getPeriodPlacements().size());
        if (placement != null && placement.getPeriod().equals(period))
            continue;
        if (iCheckStudentConflicts && exam.countStudentConflicts(assignment, period) > 0)
            continue;
        if (iCheckDistributionConstraints && !exam.checkDistributionConstraints(assignment, period))
            continue;
        if (placement != null) {
            boolean ok = true;
            if (sharing != null && placement.getRoomPlacements().size() == 1) {
                ExamRoomPlacement room = placement.getRoomPlacements().iterator().next();
                ok = room.isAvailable(period.getPeriod()) && !sharing.inConflict(exam, room.getRoom().getPlacements(assignment, period.getPeriod()), room.getRoom());
            } else {
                for (Iterator<ExamRoomPlacement> i = placement.getRoomPlacements().iterator(); i.hasNext(); ) {
                    ExamRoomPlacement room = i.next();
                    if (!room.isAvailable(period.getPeriod()) || !room.getRoom().getPlacements(assignment, period.getPeriod()).isEmpty()) {
                        ok = false;
                        break;
                    }
                }
            }
            if (ok)
                return new ExamSimpleNeighbour(assignment, new ExamPlacement(exam, period, placement.getRoomPlacements()));
        }
        Set<ExamRoomPlacement> rooms = exam.findBestAvailableRooms(assignment, period);
        if (rooms == null)
            continue;
        return new ExamSimpleNeighbour(assignment, new ExamPlacement(exam, period, rooms));
    }
    return null;
}
Also used : ExamRoomSharing(org.cpsolver.exam.model.ExamRoomSharing) ExamRoomPlacement(org.cpsolver.exam.model.ExamRoomPlacement) ExamPlacement(org.cpsolver.exam.model.ExamPlacement) ExamModel(org.cpsolver.exam.model.ExamModel) ExamPeriodPlacement(org.cpsolver.exam.model.ExamPeriodPlacement) Exam(org.cpsolver.exam.model.Exam)

Example 48 with Exam

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

the class StudentNotAvailableConflicts method getValue.

@Override
public double getValue(Assignment<Exam, ExamPlacement> assignment, ExamPlacement value, Set<ExamPlacement> conflicts) {
    Exam exam = value.variable();
    int penalty = 0;
    for (ExamStudent s : exam.getStudents()) {
        if (!s.isAvailable(value.getPeriod()))
            penalty++;
    }
    return penalty;
}
Also used : ExamStudent(org.cpsolver.exam.model.ExamStudent) Exam(org.cpsolver.exam.model.Exam)

Example 49 with Exam

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

the class DistributionViolation method getValue.

@Override
public double getValue(Assignment<Exam, ExamPlacement> assignment, Collection<Exam> variables) {
    int penalty = 0;
    Set<ExamDistributionConstraint> added = new HashSet<ExamDistributionConstraint>();
    for (Exam exam : variables) {
        for (ExamDistributionConstraint dc : exam.getDistributionConstraints()) {
            if (added.add(dc)) {
                if (dc.isHard() || getWeight() != dc.getWeight())
                    continue;
                if (!dc.isSatisfied(assignment))
                    penalty += 1;
            }
        }
    }
    return penalty;
}
Also used : ExamDistributionConstraint(org.cpsolver.exam.model.ExamDistributionConstraint) ExamDistributionConstraint(org.cpsolver.exam.model.ExamDistributionConstraint) Exam(org.cpsolver.exam.model.Exam) HashSet(java.util.HashSet)

Example 50 with Exam

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

the class ExamSplitter method getInfo.

/**
 * Lists the split
 */
@Override
public void getInfo(Assignment<Exam, ExamPlacement> assignment, Map<String, String> info) {
    if (!iChildren.isEmpty()) {
        int parents = 0;
        String split = "";
        for (Exam parent : new TreeSet<Exam>(iChildren.keySet())) {
            List<Exam> children = iChildren.get(parent);
            if (children.isEmpty())
                continue;
            split += "\n  ";
            parents++;
            split += parent.getName() + ": " + parent.getStudents().size() + " (" + (assignment.getValue(parent) == null ? "N/A" : assignment.getValue(parent).getPeriod()) + ")";
            for (Exam child : children) split += " + " + child.getStudents().size() + " (" + (assignment.getValue(child) == null ? "N/A" : assignment.getValue(child).getPeriod()) + ")";
        }
        if (parents > 0)
            info.put("Examination Splits", parents + split);
    }
}
Also used : TreeSet(java.util.TreeSet) Exam(org.cpsolver.exam.model.Exam)

Aggregations

Exam (org.cpsolver.exam.model.Exam)62 ExamPlacement (org.cpsolver.exam.model.ExamPlacement)38 ExamModel (org.cpsolver.exam.model.ExamModel)26 ExamRoomPlacement (org.cpsolver.exam.model.ExamRoomPlacement)21 ExamPeriod (org.cpsolver.exam.model.ExamPeriod)19 ExamStudent (org.cpsolver.exam.model.ExamStudent)18 Set (java.util.Set)15 ArrayList (java.util.ArrayList)13 ExamPeriodPlacement (org.cpsolver.exam.model.ExamPeriodPlacement)12 CSVFile (org.cpsolver.ifs.util.CSVFile)12 CSVField (org.cpsolver.ifs.util.CSVFile.CSVField)12 HashSet (java.util.HashSet)11 ExamInstructor (org.cpsolver.exam.model.ExamInstructor)10 DecimalFormat (java.text.DecimalFormat)6 AssignmentContext (org.cpsolver.ifs.assignment.context.AssignmentContext)6 NeighbourSelectionWithContext (org.cpsolver.ifs.assignment.context.NeighbourSelectionWithContext)6 HashMap (java.util.HashMap)4 TreeSet (java.util.TreeSet)4 ExamOwner (org.cpsolver.exam.model.ExamOwner)4 IOException (java.io.IOException)3