Search in sources :

Example 1 with PerturbationPenalty

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

the class Test method addCSVLine.

private static void addCSVLine(File file, String instance, String config, Solution<Exam, ExamPlacement> solution) {
    try {
        ExamModel model = (ExamModel) solution.getModel();
        Assignment<Exam, ExamPlacement> assignment = solution.getAssignment();
        boolean ex = file.exists();
        PrintWriter pw = new PrintWriter(new FileWriter(file, true));
        boolean mpp = ((PerturbationPenalty) model.getCriterion(PerturbationPenalty.class)).isMPP();
        int largeSize = ((LargeExamsPenalty) model.getCriterion(LargeExamsPenalty.class)).getLargeSize();
        RoomSplitDistancePenalty splitDistance = (RoomSplitDistancePenalty) model.getCriterion(RoomSplitDistancePenalty.class);
        ExamSplitter splitter = (ExamSplitter) model.getCriterion(ExamSplitter.class);
        PeriodViolation violPer = (PeriodViolation) model.getCriterion(PeriodViolation.class);
        RoomViolation violRoom = (RoomViolation) model.getCriterion(RoomViolation.class);
        DistributionViolation violDist = (DistributionViolation) model.getCriterion(DistributionViolation.class);
        DistanceToStronglyPreferredRoom distStrPref = (DistanceToStronglyPreferredRoom) model.getCriterion(DistanceToStronglyPreferredRoom.class);
        ExamRotationPenalty rotation = (ExamRotationPenalty) model.getCriterion(ExamRotationPenalty.class);
        DecimalFormat df = new DecimalFormat("0.00");
        if (!ex) {
            pw.println("SEED" + ",NA,DC,M2D,BTB" + (model.getBackToBackDistance() < 0 ? "" : ",dBTB") + ",iNA,iDC,iM2D,iBTB" + (model.getBackToBackDistance() < 0 ? "" : ",diBTB") + ",PP,RP,DP" + // Period Index, Rotation Penalty, Period Size
            ",PI,@P,PS" + // Room Size, Room Split, Room Split Distance
            ",RSz,RSp,RD" + (largeSize >= 0 ? ",LP" : "") + (mpp ? ",IP,IRP" : "") + (distStrPref == null ? "" : ",@D") + (splitter == null ? "" : ",XX") + (violPer == null ? "" : ",!P") + (violRoom == null ? "" : ",!R") + (violDist == null ? "" : ",!D") + ",INSTANCE,CONFIG");
            int nrStudentExams = 0;
            for (ExamStudent student : model.getStudents()) {
                nrStudentExams += student.variables().size();
            }
            int nrInstructorExams = 0;
            for (ExamInstructor instructor : model.getInstructors()) {
                nrInstructorExams += instructor.variables().size();
            }
            pw.println("MIN" + ",#EX,#RM,#PER," + (model.getBackToBackDistance() < 0 ? "" : ",") + ",#STD,#STDX,#INS,#INSX" + (model.getBackToBackDistance() < 0 ? "" : ",") + "," + model.getCriterion(PeriodPenalty.class).getBounds(assignment)[0] + "," + model.getCriterion(RoomPenalty.class).getBounds(assignment)[0] + "," + model.getCriterion(DistributionPenalty.class).getBounds(assignment)[0] + ",," + df.format(rotation.averagePeriod(assignment)) + "," + ",,," + (largeSize >= 0 ? ",0" : "") + (mpp ? ",," : "") + (distStrPref == null ? "" : ",") + (splitter == null ? "" : ",") + (violPer == null ? "" : ",") + (violRoom == null ? "" : ",") + (violDist == null ? "" : ",") + ",,");
            pw.println("MAX" + "," + model.variables().size() + "," + model.getRooms().size() + "," + model.getPeriods().size() + "," + (model.getBackToBackDistance() < 0 ? "" : ",") + "," + model.getStudents().size() + "," + nrStudentExams + "," + model.getInstructors().size() + "," + nrInstructorExams + (model.getBackToBackDistance() < 0 ? "" : ",") + "," + model.getCriterion(PeriodPenalty.class).getBounds(assignment)[1] + "," + model.getCriterion(RoomPenalty.class).getBounds(assignment)[1] + "," + model.getCriterion(DistributionPenalty.class).getBounds(assignment)[1] + ",," + rotation.nrAssignedExamsWithAvgPeriod(assignment) + "," + ",,," + (largeSize >= 0 ? "," + model.getCriterion(LargeExamsPenalty.class).getBounds(assignment)[1] : "") + (mpp ? ",," : "") + (distStrPref == null ? "" : ",") + (splitter == null ? "" : ",") + (violPer == null ? "" : "," + model.getCriterion(PeriodViolation.class).getBounds(assignment)[1]) + (violRoom == null ? "" : "," + model.getCriterion(RoomViolation.class).getBounds(assignment)[1]) + (violDist == null ? "" : "," + model.getCriterion(DistributionViolation.class).getBounds(assignment)[1]) + ",,");
        }
        pw.println(ToolBox.getSeed() + "," + model.getCriterion(StudentNotAvailableConflicts.class).getValue(assignment) + "," + model.getCriterion(StudentDirectConflicts.class).getValue(assignment) + "," + model.getCriterion(StudentMoreThan2ADayConflicts.class).getValue(assignment) + "," + model.getCriterion(StudentBackToBackConflicts.class).getValue(assignment) + (model.getBackToBackDistance() < 0 ? "" : "," + model.getCriterion(StudentDistanceBackToBackConflicts.class).getValue(assignment)) + "," + model.getCriterion(InstructorNotAvailableConflicts.class).getValue(assignment) + "," + model.getCriterion(InstructorDirectConflicts.class).getValue(assignment) + "," + model.getCriterion(InstructorMoreThan2ADayConflicts.class).getValue(assignment) + "," + model.getCriterion(InstructorBackToBackConflicts.class).getValue(assignment) + (model.getBackToBackDistance() < 0 ? "" : "," + model.getCriterion(InstructorDistanceBackToBackConflicts.class).getValue(assignment)) + "," + model.getCriterion(PeriodPenalty.class).getValue(assignment) + "," + model.getCriterion(RoomPenalty.class).getValue(assignment) + "," + model.getCriterion(DistributionPenalty.class).getValue(assignment) + "," + df.format(model.getCriterion(PeriodIndexPenalty.class).getValue(assignment) / assignment.nrAssignedVariables()) + "," + df.format(Math.sqrt(rotation.getValue(assignment) / rotation.nrAssignedExamsWithAvgPeriod(assignment)) - 1) + "," + df.format(model.getCriterion(PeriodSizePenalty.class).getValue(assignment) / assignment.nrAssignedVariables()) + "," + df.format(model.getCriterion(RoomSizePenalty.class).getValue(assignment) / assignment.nrAssignedVariables()) + "," + model.getCriterion(RoomSplitPenalty.class).getValue(assignment) + "," + df.format(splitDistance.nrRoomSplits(assignment) <= 0 ? 0.0 : splitDistance.getValue(assignment) / splitDistance.nrRoomSplits(assignment)) + (largeSize >= 0 ? "," + model.getCriterion(LargeExamsPenalty.class).getValue(assignment) : "") + (mpp ? "," + df.format(model.getCriterion(PerturbationPenalty.class).getValue(assignment) / assignment.nrAssignedVariables()) + "," + df.format(model.getCriterion(RoomPerturbationPenalty.class).getValue(assignment) / assignment.nrAssignedVariables()) : "") + (distStrPref == null ? "" : "," + df.format(distStrPref.getValue(assignment) / assignment.nrAssignedVariables())) + (splitter == null ? "" : "," + df.format(splitter.getValue(assignment))) + (violPer == null ? "" : "," + df.format(violPer.getValue(assignment))) + (violRoom == null ? "" : "," + df.format(violRoom.getValue(assignment))) + (violDist == null ? "" : "," + df.format(violDist.getValue(assignment))) + "," + instance + "," + config);
        pw.flush();
        pw.close();
    } catch (Exception e) {
        sLog.error("Unable to add CSV line to " + file, e);
    }
}
Also used : RoomPerturbationPenalty(org.cpsolver.exam.criteria.RoomPerturbationPenalty) PerturbationPenalty(org.cpsolver.exam.criteria.PerturbationPenalty) InstructorDistanceBackToBackConflicts(org.cpsolver.exam.criteria.InstructorDistanceBackToBackConflicts) ExamModel(org.cpsolver.exam.model.ExamModel) FileWriter(java.io.FileWriter) DecimalFormat(java.text.DecimalFormat) DistanceToStronglyPreferredRoom(org.cpsolver.exam.criteria.additional.DistanceToStronglyPreferredRoom) InstructorBackToBackConflicts(org.cpsolver.exam.criteria.InstructorBackToBackConflicts) DistributionViolation(org.cpsolver.exam.criteria.additional.DistributionViolation) RoomViolation(org.cpsolver.exam.criteria.additional.RoomViolation) ExamStudentConflictsPerExam(org.cpsolver.exam.reports.ExamStudentConflictsPerExam) Exam(org.cpsolver.exam.model.Exam) PrintWriter(java.io.PrintWriter) LargeExamsPenalty(org.cpsolver.exam.criteria.LargeExamsPenalty) ExamInstructor(org.cpsolver.exam.model.ExamInstructor) RoomSplitDistancePenalty(org.cpsolver.exam.criteria.RoomSplitDistancePenalty) PeriodViolation(org.cpsolver.exam.criteria.additional.PeriodViolation) InstructorDirectConflicts(org.cpsolver.exam.criteria.InstructorDirectConflicts) ExamStudent(org.cpsolver.exam.model.ExamStudent) IOException(java.io.IOException) ExamRotationPenalty(org.cpsolver.exam.criteria.ExamRotationPenalty) ExamPlacement(org.cpsolver.exam.model.ExamPlacement) InstructorNotAvailableConflicts(org.cpsolver.exam.criteria.InstructorNotAvailableConflicts) InstructorMoreThan2ADayConflicts(org.cpsolver.exam.criteria.InstructorMoreThan2ADayConflicts) ExamSplitter(org.cpsolver.exam.split.ExamSplitter) RoomPerturbationPenalty(org.cpsolver.exam.criteria.RoomPerturbationPenalty)

Aggregations

FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 DecimalFormat (java.text.DecimalFormat)1 ExamRotationPenalty (org.cpsolver.exam.criteria.ExamRotationPenalty)1 InstructorBackToBackConflicts (org.cpsolver.exam.criteria.InstructorBackToBackConflicts)1 InstructorDirectConflicts (org.cpsolver.exam.criteria.InstructorDirectConflicts)1 InstructorDistanceBackToBackConflicts (org.cpsolver.exam.criteria.InstructorDistanceBackToBackConflicts)1 InstructorMoreThan2ADayConflicts (org.cpsolver.exam.criteria.InstructorMoreThan2ADayConflicts)1 InstructorNotAvailableConflicts (org.cpsolver.exam.criteria.InstructorNotAvailableConflicts)1 LargeExamsPenalty (org.cpsolver.exam.criteria.LargeExamsPenalty)1 PerturbationPenalty (org.cpsolver.exam.criteria.PerturbationPenalty)1 RoomPerturbationPenalty (org.cpsolver.exam.criteria.RoomPerturbationPenalty)1 RoomSplitDistancePenalty (org.cpsolver.exam.criteria.RoomSplitDistancePenalty)1 DistanceToStronglyPreferredRoom (org.cpsolver.exam.criteria.additional.DistanceToStronglyPreferredRoom)1 DistributionViolation (org.cpsolver.exam.criteria.additional.DistributionViolation)1 PeriodViolation (org.cpsolver.exam.criteria.additional.PeriodViolation)1 RoomViolation (org.cpsolver.exam.criteria.additional.RoomViolation)1 Exam (org.cpsolver.exam.model.Exam)1 ExamInstructor (org.cpsolver.exam.model.ExamInstructor)1