Search in sources :

Example 21 with Exam

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

the class ExamAssignments method report.

/**
     * generate report
     * @param assignment current assignment
     * @return resultant report
     */
public CSVFile report(Assignment<Exam, ExamPlacement> assignment) {
    CSVFile csv = new CSVFile();
    csv.setHeader(new CSVField[] { new CSVField("Exam"), new CSVField("Enrl"), new CSVField("Alt"), new CSVField("Period"), new CSVField("Date"), new CSVField("Time"), new CSVField("Room"), new CSVField("Cap") });
    for (Exam exam : iModel.variables()) {
        ExamPlacement placement = assignment.getValue(exam);
        ArrayList<CSVField> fields = new ArrayList<CSVField>();
        fields.add(new CSVField(exam.getName()));
        fields.add(new CSVField(exam.getStudents().size()));
        fields.add(new CSVField(exam.hasAltSeating() ? "Yes" : "No"));
        if (placement == null) {
            fields.add(new CSVField(""));
            fields.add(new CSVField(""));
            fields.add(new CSVField(""));
            fields.add(new CSVField(""));
            fields.add(new CSVField(""));
        } else {
            fields.add(new CSVField(placement.getPeriod().getIndex() + 1));
            fields.add(new CSVField(placement.getPeriod().getDayStr()));
            fields.add(new CSVField(placement.getPeriod().getTimeStr()));
            String rooms = "";
            String roomSizes = "";
            for (Iterator<ExamRoomPlacement> i = placement.getRoomPlacements().iterator(); i.hasNext(); ) {
                ExamRoomPlacement room = i.next();
                rooms += room.getRoom().getName();
                roomSizes += room.getSize(exam.hasAltSeating());
                if (i.hasNext()) {
                    rooms += ", ";
                    roomSizes += ", ";
                }
            }
            fields.add(new CSVField(rooms));
            fields.add(new CSVField(roomSizes));
        }
        csv.addLine(fields);
    }
    return csv;
}
Also used : CSVFile(org.cpsolver.ifs.util.CSVFile) ExamRoomPlacement(org.cpsolver.exam.model.ExamRoomPlacement) CSVField(org.cpsolver.ifs.util.CSVFile.CSVField) ExamPlacement(org.cpsolver.exam.model.ExamPlacement) ArrayList(java.util.ArrayList) Exam(org.cpsolver.exam.model.Exam)

Example 22 with Exam

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

the class ExamCourseSectionAssignments method report.

/**
     * generate report
     * @param assignment current assignment
     * @return resultant report
     */
public CSVFile report(Assignment<Exam, ExamPlacement> assignment) {
    CSVFile csv = new CSVFile();
    csv.setHeader(new CSVField[] { new CSVField("Section/Course"), new CSVField("Enrl"), new CSVField("Alt"), new CSVField("Period"), new CSVField("Date"), new CSVField("Time"), new CSVField("Room"), new CSVField("Cap") });
    for (Exam exam : iModel.variables()) {
        ExamPlacement placement = assignment.getValue(exam);
        for (ExamOwner owner : exam.getOwners()) {
            List<CSVField> fields = new ArrayList<CSVField>();
            fields.add(new CSVField(owner.getName()));
            fields.add(new CSVField(owner.getStudents().size()));
            fields.add(new CSVField(exam.hasAltSeating() ? "Yes" : "No"));
            if (placement == null) {
                fields.add(new CSVField(""));
                fields.add(new CSVField(""));
                fields.add(new CSVField(""));
                fields.add(new CSVField(""));
                fields.add(new CSVField(""));
            } else {
                fields.add(new CSVField(placement.getPeriod().getIndex() + 1));
                fields.add(new CSVField(placement.getPeriod().getDayStr()));
                fields.add(new CSVField(placement.getPeriod().getTimeStr()));
                String rooms = "";
                String roomSizes = "";
                for (Iterator<ExamRoomPlacement> i = placement.getRoomPlacements().iterator(); i.hasNext(); ) {
                    ExamRoomPlacement room = i.next();
                    rooms += room.getName();
                    roomSizes += room.getSize(exam.hasAltSeating());
                    if (i.hasNext()) {
                        rooms += ", ";
                        roomSizes += ", ";
                    }
                }
                fields.add(new CSVField(rooms));
                fields.add(new CSVField(roomSizes));
            }
            csv.addLine(fields);
        }
    }
    return csv;
}
Also used : CSVFile(org.cpsolver.ifs.util.CSVFile) ExamRoomPlacement(org.cpsolver.exam.model.ExamRoomPlacement) CSVField(org.cpsolver.ifs.util.CSVFile.CSVField) ExamPlacement(org.cpsolver.exam.model.ExamPlacement) ExamOwner(org.cpsolver.exam.model.ExamOwner) ArrayList(java.util.ArrayList) Exam(org.cpsolver.exam.model.Exam)

Example 23 with Exam

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

the class ExamStudentBackToBackConflicts method report.

/**
     * generate report
     * @param assignment current assignment
     * @return resultant report
     */
public CSVFile report(Assignment<Exam, ExamPlacement> assignment) {
    CSVFile csv = new CSVFile();
    csv.setHeader(new CSVField[] { new CSVField("Exam 1"), new CSVField("Enrl 1"), new CSVField("Period 1"), new CSVField("Date 1"), new CSVField("Time 1"), new CSVField("Exam 2"), new CSVField("Enrl 2"), new CSVField("Back-To-Back"), new CSVField("Back-To-Back [%]"), new CSVField("Distance") });
    DecimalFormat df = new DecimalFormat("0.0");
    boolean isDayBreakBackToBack = ((StudentBackToBackConflicts) iModel.getCriterion(StudentBackToBackConflicts.class)).isDayBreakBackToBack();
    double backToBackDistance = ((StudentDistanceBackToBackConflicts) iModel.getCriterion(StudentDistanceBackToBackConflicts.class)).getBackToBackDistance();
    for (Exam ex1 : iModel.variables()) {
        ExamPlacement p1 = assignment.getValue(ex1);
        if (p1 == null || p1.getPeriod().next() == null)
            continue;
        if (!isDayBreakBackToBack && p1.getPeriod().getDay() != p1.getPeriod().next().getDay())
            continue;
        for (Exam ex2 : iModel.variables()) {
            ExamPlacement p2 = assignment.getValue(ex2);
            if (p2 == null || !p2.getPeriod().equals(p1.getPeriod().next()))
                continue;
            List<ExamStudent> students = ex1.getJointEnrollments().get(ex2);
            if (students == null || students.isEmpty())
                continue;
            String distStr = "";
            if (backToBackDistance >= 0) {
                double dist = p1.getDistanceInMeters(p2);
                if (dist > 0)
                    distStr = String.valueOf(dist);
            }
            csv.addLine(new CSVField[] { new CSVField(ex1.getName()), new CSVField(ex1.getStudents().size()), new CSVField(p1.getPeriod().getIndex() + 1), new CSVField(p1.getPeriod().getDayStr()), new CSVField(p1.getPeriod().getTimeStr()), new CSVField(ex2.getName()), new CSVField(ex2.getStudents().size()), new CSVField(students.size()), new CSVField(df.format(100.0 * students.size() / Math.min(ex1.getStudents().size(), ex2.getStudents().size()))), new CSVField(distStr) });
        }
    }
    return csv;
}
Also used : CSVFile(org.cpsolver.ifs.util.CSVFile) CSVField(org.cpsolver.ifs.util.CSVFile.CSVField) ExamPlacement(org.cpsolver.exam.model.ExamPlacement) StudentBackToBackConflicts(org.cpsolver.exam.criteria.StudentBackToBackConflicts) DecimalFormat(java.text.DecimalFormat) ExamStudent(org.cpsolver.exam.model.ExamStudent) StudentDistanceBackToBackConflicts(org.cpsolver.exam.criteria.StudentDistanceBackToBackConflicts) Exam(org.cpsolver.exam.model.Exam)

Example 24 with Exam

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

the class ExamRoomSchedule method report.

public CSVFile report(Assignment<Exam, ExamPlacement> assignment) {
    CSVFile csv = new CSVFile();
    csv.setHeader(new CSVField[] { new CSVField("Room"), new CSVField("Cap"), new CSVField("AltCap"), new CSVField("Period"), new CSVField("Date"), new CSVField("Time"), new CSVField("Exam"), new CSVField("Enrl") });
    List<ExamRoom> rooms = new ArrayList<ExamRoom>(iModel.getRooms());
    Collections.sort(rooms, new Comparator<ExamRoom>() {

        @Override
        public int compare(ExamRoom r1, ExamRoom r2) {
            int cmp = -Double.compare(r1.getSize(), r2.getSize());
            if (cmp != 0)
                return cmp;
            cmp = -Double.compare(r1.getAltSize(), r2.getAltSize());
            if (cmp != 0)
                return cmp;
            return r1.compareTo(r2);
        }
    });
    for (ExamRoom room : rooms) {
        boolean first = true;
        int day = -1;
        for (ExamPeriod period : iModel.getPeriods()) {
            for (ExamPlacement placement : room.getPlacements(assignment, period)) {
                Exam exam = placement.variable();
                csv.addLine(new CSVField[] { new CSVField(first ? room.getName() : ""), new CSVField(first ? "" + room.getSize() : ""), new CSVField(first ? "" + room.getAltSize() : ""), new CSVField(period.getIndex() + 1), new CSVField(day == period.getDay() ? "" : period.getDayStr()), new CSVField(period.getTimeStr()), new CSVField(exam.getName()), new CSVField(exam.getStudents().size()) });
                first = false;
                day = period.getDay();
            }
        }
    }
    return csv;
}
Also used : ExamPeriod(org.cpsolver.exam.model.ExamPeriod) CSVFile(org.cpsolver.ifs.util.CSVFile) ExamRoom(org.cpsolver.exam.model.ExamRoom) CSVField(org.cpsolver.ifs.util.CSVFile.CSVField) ExamPlacement(org.cpsolver.exam.model.ExamPlacement) ArrayList(java.util.ArrayList) Exam(org.cpsolver.exam.model.Exam)

Example 25 with Exam

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

the class ExamRoomMove method selectNeighbour.

/**
     * Select an exam randomly, select an available period randomly (if it is
     * not assigned, from {@link Exam#getPeriodPlacements()}), select rooms
     * using {@link Exam#findRoomsRandom(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());
    if (exam.getMaxRooms() <= 0)
        return null;
    ExamPlacement placement = assignment.getValue(exam);
    ExamPeriodPlacement period = (placement != null ? placement.getPeriodPlacement() : (ExamPeriodPlacement) ToolBox.random(exam.getPeriodPlacements()));
    if (iCheckStudentConflicts && placement == null && exam.countStudentConflicts(assignment, period) > 0)
        return null;
    if (iCheckDistributionConstraints && placement == null && !exam.checkDistributionConstraints(assignment, period))
        return null;
    Set<ExamRoomPlacement> rooms = (placement != null ? placement.getRoomPlacements() : exam.findBestAvailableRooms(assignment, period));
    if (rooms == null || rooms.isEmpty())
        return null;
    if (placement == null)
        placement = new ExamPlacement(exam, period, rooms);
    List<ExamRoomPlacement> roomVect = new ArrayList<ExamRoomPlacement>(rooms);
    int rx = ToolBox.random(roomVect.size());
    for (int r = 0; r < roomVect.size(); r++) {
        ExamRoomPlacement current = roomVect.get((r + rx) % roomVect.size());
        int mx = ToolBox.random(exam.getRoomPlacements().size());
        for (int m = 0; m < exam.getRoomPlacements().size(); m++) {
            ExamRoomPlacement swap = exam.getRoomPlacements().get((m + mx) % exam.getRoomPlacements().size());
            ExamRoomSwapNeighbour n = new ExamRoomSwapNeighbour(assignment, placement, current, swap);
            if (n.canDo())
                return n;
        }
    }
    rooms = exam.findRoomsRandom(assignment, period);
    if (rooms == null)
        return null;
    return new ExamSimpleNeighbour(assignment, new ExamPlacement(exam, period, rooms));
}
Also used : ExamRoomPlacement(org.cpsolver.exam.model.ExamRoomPlacement) ExamPlacement(org.cpsolver.exam.model.ExamPlacement) ExamModel(org.cpsolver.exam.model.ExamModel) ArrayList(java.util.ArrayList) ExamPeriodPlacement(org.cpsolver.exam.model.ExamPeriodPlacement) 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