Search in sources :

Example 21 with ExamRoomPlacement

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

the class ExamColoringConstruction method findRooms.

public Set<ExamRoomPlacement> findRooms(Assignment<Exam, ExamPlacement> assignment, Exam exam, ExamPeriodPlacement period) {
    Set<ExamRoomPlacement> rooms = exam.findBestAvailableRooms(assignment, period);
    if (rooms != null)
        return rooms;
    rooms = new HashSet<ExamRoomPlacement>();
    int size = 0;
    while (size < exam.getSize()) {
        ExamRoomPlacement bestRoom = null;
        int bestSize = 0;
        for (ExamRoomPlacement r : exam.getRoomPlacements()) {
            if (!r.isAvailable(period.getPeriod()))
                continue;
            if (rooms.contains(r))
                continue;
            if (!r.getRoom().getPlacements(assignment, period.getPeriod()).isEmpty())
                continue;
            int s = r.getSize(exam.hasAltSeating());
            if (bestRoom == null || s > bestSize) {
                bestRoom = r;
                bestSize = s;
            }
        }
        if (bestRoom == null)
            return rooms;
        rooms.add(bestRoom);
        size += bestSize;
    }
    return rooms;
}
Also used : ExamRoomPlacement(org.cpsolver.exam.model.ExamRoomPlacement)

Example 22 with ExamRoomPlacement

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

the class ExamStudentConflicts 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("Student"), new CSVField("Type"), new CSVField("Section/Course"), new CSVField("Period"), new CSVField("Day"), new CSVField("Time"), new CSVField("Room"), new CSVField("Distance") });
    boolean isDayBreakBackToBack = ((StudentBackToBackConflicts) iModel.getCriterion(StudentBackToBackConflicts.class)).isDayBreakBackToBack();
    double backToBackDistance = ((StudentDistanceBackToBackConflicts) iModel.getCriterion(StudentDistanceBackToBackConflicts.class)).getBackToBackDistance();
    for (ExamStudent student : iModel.getStudents()) {
        for (ExamPeriod period : iModel.getPeriods()) {
            int nrExams = student.getExams(assignment, period).size();
            if (nrExams > 1) {
                String sections = "";
                String rooms = "";
                String periods = String.valueOf(period.getIndex() + 1);
                String periodDays = period.getDayStr();
                String periodTimes = period.getTimeStr();
                for (Exam exam : student.getExams(assignment, period)) {
                    ExamPlacement placement = assignment.getValue(exam);
                    String roomsThisExam = "";
                    for (ExamRoomPlacement room : placement.getRoomPlacements()) {
                        if (roomsThisExam.length() > 0)
                            roomsThisExam += ", ";
                        roomsThisExam += room.getName();
                    }
                    boolean first = true;
                    for (ExamOwner cs : exam.getOwners(student)) {
                        if (sections.length() > 0) {
                            sections += "\n";
                            rooms += "\n";
                            periods += "\n";
                            periodDays += "\n";
                            periodTimes += "\n";
                        }
                        sections += cs.getName();
                        if (first)
                            rooms += roomsThisExam;
                        first = false;
                    }
                    if (exam.getOwners(student).isEmpty()) {
                        sections += exam.getName();
                        rooms += roomsThisExam;
                    }
                }
                csv.addLine(new CSVField[] { new CSVField(student.getName()), new CSVField("direct"), new CSVField(sections), new CSVField(periods), new CSVField(periodDays), new CSVField(periodTimes), new CSVField(rooms) });
            }
            if (nrExams > 0) {
                if (period.next() != null && !student.getExams(assignment, period.next()).isEmpty() && (!isDayBreakBackToBack || period.next().getDay() == period.getDay())) {
                    for (Exam ex1 : student.getExams(assignment, period)) {
                        for (Exam ex2 : student.getExams(assignment, period.next())) {
                            ExamPlacement placement = assignment.getValue(ex1);
                            String sections = "";
                            String rooms = "";
                            String roomsThisExam = "";
                            String periods = String.valueOf(period.getIndex() + 1);
                            String periodDays = period.getDayStr();
                            String periodTimes = period.getTimeStr();
                            for (ExamRoomPlacement room : placement.getRoomPlacements()) {
                                if (roomsThisExam.length() > 0)
                                    roomsThisExam += ", ";
                                roomsThisExam += room.getName();
                            }
                            boolean first = true;
                            for (ExamOwner cs : ex1.getOwners(student)) {
                                if (sections.length() > 0) {
                                    sections += "\n";
                                    rooms += "\n";
                                    periods += "\n";
                                    periodDays += "\n";
                                    periodTimes += "\n";
                                }
                                sections += cs.getName();
                                if (first)
                                    rooms += roomsThisExam;
                                first = false;
                            }
                            if (ex1.getOwners(student).isEmpty()) {
                                sections += ex1.getName();
                                rooms += roomsThisExam;
                            }
                            placement = assignment.getValue(ex2);
                            roomsThisExam = "";
                            for (ExamRoomPlacement room : placement.getRoomPlacements()) {
                                if (roomsThisExam.length() > 0)
                                    roomsThisExam += ", ";
                                roomsThisExam += room.getName();
                            }
                            first = true;
                            for (ExamOwner cs : ex2.getOwners(student)) {
                                sections += "\n";
                                rooms += "\n";
                                periods += "\n";
                                periodDays += "\n";
                                periodTimes += "\n";
                                sections += cs.getName();
                                if (first) {
                                    rooms += roomsThisExam;
                                    periods += String.valueOf(period.next().getIndex() + 1);
                                    periodDays += period.next().getDayStr();
                                    periodTimes += period.next().getTimeStr();
                                }
                                first = false;
                            }
                            if (ex2.getOwners(student).isEmpty()) {
                                sections += "\n";
                                rooms += "\n";
                                periods += "\n";
                                periodDays += "\n";
                                periodTimes += "\n";
                                sections += ex2.getName();
                                rooms += roomsThisExam;
                                periods += String.valueOf(period.next().getIndex() + 1);
                                periodDays += period.next().getDayStr();
                                periodTimes += period.next().getTimeStr();
                                rooms += roomsThisExam;
                            }
                            String distStr = "";
                            if (backToBackDistance >= 0) {
                                double dist = (assignment.getValue(ex1)).getDistanceInMeters(assignment.getValue(ex2));
                                if (dist > 0)
                                    distStr = String.valueOf(dist);
                            }
                            csv.addLine(new CSVField[] { new CSVField(student.getName()), new CSVField("back-to-back"), new CSVField(sections), new CSVField(periods), new CSVField(periodDays), new CSVField(periodTimes), new CSVField(rooms), new CSVField(distStr) });
                        }
                    }
                }
            }
            if (period.next() == null || period.next().getDay() != period.getDay()) {
                int nrExamsADay = student.getExamsADay(assignment, period.getDay()).size();
                if (nrExamsADay > 2) {
                    String sections = "";
                    String periods = "";
                    String periodDays = "";
                    String periodTimes = "";
                    String rooms = "";
                    for (Exam exam : student.getExamsADay(assignment, period.getDay())) {
                        ExamPlacement placement = assignment.getValue(exam);
                        String roomsThisExam = "";
                        for (ExamRoomPlacement room : placement.getRoomPlacements()) {
                            if (roomsThisExam.length() > 0)
                                roomsThisExam += ", ";
                            roomsThisExam += room.getName();
                        }
                        boolean first = true;
                        for (ExamOwner cs : exam.getOwners(student)) {
                            if (sections.length() > 0) {
                                sections += "\n";
                                rooms += "\n";
                                periods += "\n";
                                periodDays += "\n";
                                periodTimes += "\n";
                            }
                            sections += cs.getName();
                            if (first) {
                                periods += (placement.getPeriod().getIndex() + 1);
                                periodDays += placement.getPeriod().getDayStr();
                                periodTimes += placement.getPeriod().getTimeStr();
                                rooms += roomsThisExam;
                            }
                            first = false;
                        }
                        if (exam.getOwners(student).isEmpty()) {
                            if (sections.length() > 0) {
                                sections += "\n";
                                rooms += "\n";
                                periods += "\n";
                                periodDays += "\n";
                                periodTimes += "\n";
                            }
                            sections += exam.getName();
                            periods += (placement.getPeriod().getIndex() + 1);
                            periodDays += placement.getPeriod().getDayStr();
                            periodTimes += placement.getPeriod().getTimeStr();
                            rooms += roomsThisExam;
                        }
                    }
                    csv.addLine(new CSVField[] { new CSVField(student.getName()), new CSVField("more-2-day"), new CSVField(sections), new CSVField(periods), new CSVField(periodDays), new CSVField(periodTimes), new CSVField(rooms) });
                }
            }
        }
    }
    return csv;
}
Also used : ExamPeriod(org.cpsolver.exam.model.ExamPeriod) CSVFile(org.cpsolver.ifs.util.CSVFile) ExamStudent(org.cpsolver.exam.model.ExamStudent) ExamRoomPlacement(org.cpsolver.exam.model.ExamRoomPlacement) CSVField(org.cpsolver.ifs.util.CSVFile.CSVField) ExamPlacement(org.cpsolver.exam.model.ExamPlacement) StudentBackToBackConflicts(org.cpsolver.exam.criteria.StudentBackToBackConflicts) ExamOwner(org.cpsolver.exam.model.ExamOwner) StudentDistanceBackToBackConflicts(org.cpsolver.exam.criteria.StudentDistanceBackToBackConflicts) Exam(org.cpsolver.exam.model.Exam)

Example 23 with ExamRoomPlacement

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

the class ExamStudentConflictsBySectionCourse 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("Period"), new CSVField("Day"), new CSVField("Time"), new CSVField("Room"), new CSVField("Student"), new CSVField("Type"), new CSVField("Section/Course"), new CSVField("Period"), new CSVField("Time"), new CSVField("Room"), new CSVField("Distance") });
    boolean isDayBreakBackToBack = ((StudentBackToBackConflicts) iModel.getCriterion(StudentBackToBackConflicts.class)).isDayBreakBackToBack();
    double backToBackDistance = ((StudentDistanceBackToBackConflicts) iModel.getCriterion(StudentDistanceBackToBackConflicts.class)).getBackToBackDistance();
    TreeSet<ExamOwner> courseSections = new TreeSet<ExamOwner>();
    for (Exam exam : iModel.variables()) {
        courseSections.addAll(getOwners(exam));
    }
    for (ExamOwner cs : courseSections) {
        Exam exam = cs.getExam();
        ExamPlacement placement = assignment.getValue(exam);
        if (placement == null)
            continue;
        String roomsThisExam = "";
        for (ExamRoomPlacement room : placement.getRoomPlacements()) {
            if (roomsThisExam.length() > 0)
                roomsThisExam += ", ";
            roomsThisExam += room.getName();
        }
        ExamPeriod period = placement.getPeriod();
        boolean csPrinted = false;
        List<ExamStudent> students = new ArrayList<ExamStudent>(cs.getStudents());
        Collections.sort(students, new Comparator<ExamStudent>() {

            @Override
            public int compare(ExamStudent s1, ExamStudent s2) {
                int cmp = s1.getName().compareTo(s2.getName());
                if (cmp != 0)
                    return cmp;
                return Double.compare(s1.getId(), s2.getId());
            }
        });
        for (ExamStudent student : students) {
            boolean stdPrinted = false;
            int nrExams = student.getExams(assignment, period).size();
            if (nrExams > 1) {
                boolean typePrinted = false;
                for (Exam otherExam : student.getExams(assignment, period)) {
                    if (otherExam.equals(exam))
                        continue;
                    ExamPlacement otherPlacement = assignment.getValue(otherExam);
                    ExamPeriod otherPeriod = otherPlacement.getPeriod();
                    String roomsOtherExam = "";
                    for (ExamRoomPlacement room : otherPlacement.getRoomPlacements()) {
                        if (roomsOtherExam.length() > 0)
                            roomsOtherExam += ", ";
                        roomsOtherExam += room.getName();
                    }
                    boolean otherPrinted = false;
                    for (ExamOwner ocs : getOwners(otherExam, student)) {
                        csv.addLine(new CSVField[] { new CSVField(csPrinted ? "" : cs.getName()), new CSVField(csPrinted ? "" : String.valueOf(1 + period.getIndex())), new CSVField(csPrinted ? "" : period.getDayStr()), new CSVField(csPrinted ? "" : period.getTimeStr()), new CSVField(csPrinted ? "" : roomsThisExam), new CSVField(stdPrinted ? "" : student.getName()), new CSVField(typePrinted ? "" : "direct"), new CSVField(ocs.getName()), new CSVField(otherPrinted ? "" : String.valueOf(1 + otherPeriod.getIndex())), new CSVField(otherPrinted ? "" : otherPeriod.getTimeStr()), new CSVField(otherPrinted ? "" : roomsOtherExam) });
                        csPrinted = true;
                        stdPrinted = true;
                        typePrinted = true;
                        otherPrinted = true;
                    }
                }
            }
            if (nrExams > 0) {
                boolean typePrinted = false;
                List<ExamPeriod> periods = new ArrayList<ExamPeriod>(2);
                if (period.prev() != null && !student.getExams(assignment, period.prev()).isEmpty() && (!isDayBreakBackToBack || period.prev().getDay() == period.getDay()))
                    periods.add(period.prev());
                if (period.next() != null && !student.getExams(assignment, period.next()).isEmpty() && (!isDayBreakBackToBack || period.next().getDay() == period.getDay()))
                    periods.add(period.next());
                for (ExamPeriod otherPeriod : periods) {
                    for (Exam otherExam : student.getExams(assignment, otherPeriod)) {
                        ExamPlacement otherPlacement = assignment.getValue(otherExam);
                        String roomsOtherExam = "";
                        for (ExamRoomPlacement room : otherPlacement.getRoomPlacements()) {
                            if (roomsOtherExam.length() > 0)
                                roomsOtherExam += ", ";
                            roomsOtherExam += room.getName();
                        }
                        String distStr = "";
                        if (backToBackDistance >= 0) {
                            double dist = placement.getDistanceInMeters(otherPlacement);
                            if (dist > 0)
                                distStr = String.valueOf(dist);
                        }
                        boolean otherPrinted = false;
                        for (ExamOwner ocs : getOwners(otherExam, student)) {
                            csv.addLine(new CSVField[] { new CSVField(csPrinted ? "" : cs.getName()), new CSVField(csPrinted ? "" : String.valueOf(1 + period.getIndex())), new CSVField(csPrinted ? "" : period.getDayStr()), new CSVField(csPrinted ? "" : period.getTimeStr()), new CSVField(csPrinted ? "" : roomsThisExam), new CSVField(stdPrinted ? "" : student.getName()), new CSVField(typePrinted ? "" : "back-to-back"), new CSVField(ocs.getName()), new CSVField(otherPrinted ? "" : String.valueOf(1 + otherPeriod.getIndex())), new CSVField(otherPrinted ? "" : otherPeriod.getTimeStr()), new CSVField(otherPrinted ? "" : roomsOtherExam), new CSVField(otherPrinted ? "" : distStr) });
                            csPrinted = true;
                            stdPrinted = true;
                            typePrinted = true;
                            otherPrinted = true;
                        }
                    }
                }
            }
            int nrExamsADay = student.getExamsADay(assignment, period.getDay()).size();
            if (nrExamsADay > 2) {
                boolean typePrinted = false;
                for (Exam otherExam : student.getExamsADay(assignment, period.getDay())) {
                    if (otherExam.equals(exam))
                        continue;
                    ExamPlacement otherPlacement = assignment.getValue(otherExam);
                    ExamPeriod otherPeriod = otherPlacement.getPeriod();
                    String roomsOtherExam = "";
                    for (ExamRoomPlacement room : otherPlacement.getRoomPlacements()) {
                        if (roomsOtherExam.length() > 0)
                            roomsOtherExam += ", ";
                        roomsOtherExam += room.getName();
                    }
                    boolean otherPrinted = false;
                    for (ExamOwner ocs : getOwners(otherExam, student)) {
                        csv.addLine(new CSVField[] { new CSVField(csPrinted ? "" : cs.getName()), new CSVField(csPrinted ? "" : String.valueOf(1 + period.getIndex())), new CSVField(csPrinted ? "" : period.getDayStr()), new CSVField(csPrinted ? "" : period.getTimeStr()), new CSVField(csPrinted ? "" : roomsThisExam), new CSVField(stdPrinted ? "" : student.getName()), new CSVField(typePrinted ? "" : "more-2-day"), new CSVField(ocs.getName()), new CSVField(otherPrinted ? "" : String.valueOf(1 + otherPeriod.getIndex())), new CSVField(otherPrinted ? "" : otherPeriod.getTimeStr()), new CSVField(otherPrinted ? "" : roomsOtherExam) });
                        csPrinted = true;
                        stdPrinted = true;
                        typePrinted = true;
                        otherPrinted = true;
                    }
                }
            }
        }
    }
    return csv;
}
Also used : ExamPeriod(org.cpsolver.exam.model.ExamPeriod) CSVFile(org.cpsolver.ifs.util.CSVFile) ArrayList(java.util.ArrayList) ExamStudent(org.cpsolver.exam.model.ExamStudent) ExamRoomPlacement(org.cpsolver.exam.model.ExamRoomPlacement) CSVField(org.cpsolver.ifs.util.CSVFile.CSVField) ExamPlacement(org.cpsolver.exam.model.ExamPlacement) StudentBackToBackConflicts(org.cpsolver.exam.criteria.StudentBackToBackConflicts) TreeSet(java.util.TreeSet) ExamOwner(org.cpsolver.exam.model.ExamOwner) StudentDistanceBackToBackConflicts(org.cpsolver.exam.criteria.StudentDistanceBackToBackConflicts) Exam(org.cpsolver.exam.model.Exam)

Example 24 with ExamRoomPlacement

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

Example 25 with ExamRoomPlacement

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

the class ExamRoomSplit 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("Period"), new CSVField("Date"), new CSVField("Time"), new CSVField("Room 1"), new CSVField("Cap 1"), new CSVField("Room 2"), new CSVField("Cap 2"), new CSVField("Room 3"), new CSVField("Cap 3"), new CSVField("Room 4"), new CSVField("Cap 4") });
    for (Exam exam : iModel.variables()) {
        ExamPlacement placement = assignment.getValue(exam);
        if (placement == null || placement.getRoomPlacements().size() <= 1)
            continue;
        List<CSVField> fields = new ArrayList<CSVField>();
        fields.add(new CSVField(exam.getName()));
        fields.add(new CSVField(exam.getStudents().size()));
        fields.add(new CSVField(placement.getPeriod().getIndex() + 1));
        fields.add(new CSVField(placement.getPeriod().getDayStr()));
        fields.add(new CSVField(placement.getPeriod().getTimeStr()));
        TreeSet<ExamRoomPlacement> rooms = new TreeSet<ExamRoomPlacement>(new ExamRoomComparator(exam, false));
        rooms.addAll(placement.getRoomPlacements());
        for (ExamRoomPlacement room : rooms) {
            fields.add(new CSVField(room.getName()));
            fields.add(new CSVField(room.getSize(exam.hasAltSeating())));
        }
        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) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) Exam(org.cpsolver.exam.model.Exam)

Aggregations

ExamRoomPlacement (org.cpsolver.exam.model.ExamRoomPlacement)25 Exam (org.cpsolver.exam.model.Exam)21 ExamPlacement (org.cpsolver.exam.model.ExamPlacement)21 ExamPeriodPlacement (org.cpsolver.exam.model.ExamPeriodPlacement)11 ArrayList (java.util.ArrayList)9 ExamModel (org.cpsolver.exam.model.ExamModel)9 CSVFile (org.cpsolver.ifs.util.CSVFile)6 CSVField (org.cpsolver.ifs.util.CSVFile.CSVField)6 HashSet (java.util.HashSet)4 ExamOwner (org.cpsolver.exam.model.ExamOwner)4 ExamStudent (org.cpsolver.exam.model.ExamStudent)4 TreeSet (java.util.TreeSet)3 ExamPeriod (org.cpsolver.exam.model.ExamPeriod)3 HashMap (java.util.HashMap)2 StudentBackToBackConflicts (org.cpsolver.exam.criteria.StudentBackToBackConflicts)2 StudentDistanceBackToBackConflicts (org.cpsolver.exam.criteria.StudentDistanceBackToBackConflicts)2 ExamInstructor (org.cpsolver.exam.model.ExamInstructor)2 ExamRoomSharing (org.cpsolver.exam.model.ExamRoomSharing)2 ExamSimpleNeighbour (org.cpsolver.exam.neighbours.ExamSimpleNeighbour)2 AssignmentContext (org.cpsolver.ifs.assignment.context.AssignmentContext)2