Search in sources :

Example 1 with InstructorBackToBackConflicts

use of org.cpsolver.exam.criteria.InstructorBackToBackConflicts in project cpsolver by UniTime.

the class ExamInstructorConflicts 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("Instructor"), new CSVField("Type"), new CSVField("Section/Course"), new CSVField("Period"), new CSVField("Day"), new CSVField("Time"), new CSVField("Room"), new CSVField("Distance") });
    boolean isDayBreakBackToBack = ((InstructorBackToBackConflicts) iModel.getCriterion(InstructorBackToBackConflicts.class)).isDayBreakBackToBack();
    double backToBackDistance = ((InstructorDistanceBackToBackConflicts) iModel.getCriterion(InstructorDistanceBackToBackConflicts.class)).getBackToBackDistance();
    for (ExamInstructor instructor : iModel.getInstructors()) {
        for (ExamPeriod period : iModel.getPeriods()) {
            int nrExams = instructor.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 : instructor.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 owner : exam.getOwners(instructor)) {
                        if (sections.length() > 0) {
                            sections += "\n";
                            rooms += "\n";
                            periods += "\n";
                            periodDays += "\n";
                            periodTimes += "\n";
                        }
                        sections += owner.getName();
                        if (first)
                            rooms += roomsThisExam;
                        first = false;
                    }
                    if (exam.getOwners(instructor).isEmpty()) {
                        sections += exam.getName();
                        rooms += roomsThisExam;
                    }
                }
                csv.addLine(new CSVField[] { new CSVField(instructor.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 && !instructor.getExams(assignment, period.next()).isEmpty() && (!isDayBreakBackToBack || period.next().getDay() == period.getDay())) {
                    for (Exam ex1 : instructor.getExams(assignment, period)) {
                        for (Exam ex2 : instructor.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 owner : ex1.getOwners(instructor)) {
                                if (sections.length() > 0) {
                                    sections += "\n";
                                    rooms += "\n";
                                    periods += "\n";
                                    periodDays += "\n";
                                    periodTimes += "\n";
                                }
                                sections += owner.getName();
                                if (first)
                                    rooms += roomsThisExam;
                                first = false;
                            }
                            if (ex1.getOwners(instructor).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 owner : ex2.getOwners(instructor)) {
                                sections += "\n";
                                rooms += "\n";
                                periods += "\n";
                                periodDays += "\n";
                                periodTimes += "\n";
                                sections += owner.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(instructor).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();
                            }
                            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(instructor.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 = instructor.getExamsADay(assignment, period.getDay()).size();
                if (nrExamsADay > 2) {
                    String sections = "";
                    String periods = "";
                    String periodDays = "";
                    String periodTimes = "";
                    String rooms = "";
                    for (Exam exam : instructor.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 owner : exam.getOwners(instructor)) {
                            if (sections.length() > 0) {
                                sections += "\n";
                                rooms += "\n";
                                periods += "\n";
                                periodDays += "\n";
                                periodTimes += "\n";
                            }
                            sections += owner.getName();
                            if (first) {
                                periods += (placement.getPeriod().getIndex() + 1);
                                periodDays += placement.getPeriod().getDayStr();
                                periodTimes += placement.getPeriod().getTimeStr();
                                rooms += roomsThisExam;
                            }
                            first = false;
                        }
                        if (exam.getOwners(instructor).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(instructor.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 : ExamInstructor(org.cpsolver.exam.model.ExamInstructor) ExamPeriod(org.cpsolver.exam.model.ExamPeriod) CSVFile(org.cpsolver.ifs.util.CSVFile) InstructorDistanceBackToBackConflicts(org.cpsolver.exam.criteria.InstructorDistanceBackToBackConflicts) InstructorBackToBackConflicts(org.cpsolver.exam.criteria.InstructorBackToBackConflicts) 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) Exam(org.cpsolver.exam.model.Exam)

Aggregations

InstructorBackToBackConflicts (org.cpsolver.exam.criteria.InstructorBackToBackConflicts)1 InstructorDistanceBackToBackConflicts (org.cpsolver.exam.criteria.InstructorDistanceBackToBackConflicts)1 Exam (org.cpsolver.exam.model.Exam)1 ExamInstructor (org.cpsolver.exam.model.ExamInstructor)1 ExamOwner (org.cpsolver.exam.model.ExamOwner)1 ExamPeriod (org.cpsolver.exam.model.ExamPeriod)1 ExamPlacement (org.cpsolver.exam.model.ExamPlacement)1 ExamRoomPlacement (org.cpsolver.exam.model.ExamRoomPlacement)1 CSVFile (org.cpsolver.ifs.util.CSVFile)1 CSVField (org.cpsolver.ifs.util.CSVFile.CSVField)1