Search in sources :

Example 6 with CSVFile

use of org.cpsolver.ifs.util.CSVFile in project cpsolver by UniTime.

the class ExamStudentConflictsPerExam 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("Direct"), new CSVField("Direct [%]"), new CSVField("More-2-Day"), new CSVField("More-2-Day [%]"), new CSVField("Back-To-Back"), new CSVField("Back-To-Back [%]"), new CSVField("Dist Back-To-Back"), new CSVField("Dist Back-To-Back [%]") });
    DecimalFormat df = new DecimalFormat("0.0");
    for (Exam exam : iModel.variables()) {
        ExamPlacement placement = assignment.getValue(exam);
        if (placement == null)
            continue;
        int dc = (int) iModel.getCriterion(StudentDirectConflicts.class).getValue(assignment, placement, null) + (int) iModel.getCriterion(StudentNotAvailableConflicts.class).getValue(assignment, placement, null);
        int btb = (int) iModel.getCriterion(StudentBackToBackConflicts.class).getValue(assignment, placement, null);
        int dbtb = (int) iModel.getCriterion(StudentDistanceBackToBackConflicts.class).getValue(assignment, placement, null);
        int m2d = (int) iModel.getCriterion(StudentMoreThan2ADayConflicts.class).getValue(assignment, placement, null);
        if (dc == 0 && m2d == 0 && btb == 0 && dbtb == 0)
            continue;
        /*
             * String section = ""; for (Enumeration
             * f=exam.getCourseSections().elements();f.hasMoreElements();) {
             * ExamCourseSection cs = (ExamCourseSection)f.nextElement(); if
             * (section.length()>0) section+="\n"; section += cs.getName(); }
             */
        csv.addLine(new CSVField[] { new CSVField(exam.getName()), new CSVField(exam.getStudents().size()), new CSVField(dc), new CSVField(df.format(100.0 * dc / exam.getStudents().size())), new CSVField(m2d), new CSVField(df.format(100.0 * m2d / exam.getStudents().size())), new CSVField(btb), new CSVField(df.format(100.0 * btb / exam.getStudents().size())), new CSVField(dbtb), new CSVField(df.format(100.0 * dbtb / exam.getStudents().size())) });
    }
    return csv;
}
Also used : CSVFile(org.cpsolver.ifs.util.CSVFile) CSVField(org.cpsolver.ifs.util.CSVFile.CSVField) StudentNotAvailableConflicts(org.cpsolver.exam.criteria.StudentNotAvailableConflicts) ExamPlacement(org.cpsolver.exam.model.ExamPlacement) DecimalFormat(java.text.DecimalFormat) StudentDirectConflicts(org.cpsolver.exam.criteria.StudentDirectConflicts) Exam(org.cpsolver.exam.model.Exam)

Example 7 with CSVFile

use of org.cpsolver.ifs.util.CSVFile in project cpsolver by UniTime.

the class ExamStudentMoreTwoADay 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("Period 2"), new CSVField("Time 2"), new CSVField("Exam 3"), new CSVField("Enrl 3"), new CSVField("Period 3"), new CSVField("Time 3"), new CSVField("More-2-Day"), new CSVField("More-2-Day [%]") });
    DecimalFormat df = new DecimalFormat("0.0");
    for (Exam ex1 : iModel.variables()) {
        ExamPlacement p1 = assignment.getValue(ex1);
        if (p1 == null)
            continue;
        for (Exam ex2 : iModel.variables()) {
            if (ex2.equals(ex1))
                continue;
            ExamPlacement p2 = assignment.getValue(ex2);
            if (p2 == null || p2.getPeriod().getDay() != p1.getPeriod().getDay() || p2.getPeriod().getIndex() < p1.getPeriod().getIndex())
                continue;
            if (p1.getPeriod().equals(p2.getPeriod()) && ex1.getId() >= ex2.getId())
                continue;
            List<ExamStudent> students = ex1.getJointEnrollments().get(ex2);
            if (students == null || students.isEmpty())
                continue;
            for (Exam ex3 : iModel.variables()) {
                if (ex3.equals(ex2) || ex3.equals(ex1))
                    continue;
                ExamPlacement p3 = assignment.getValue(ex3);
                if (p3 == null || p3.getPeriod().getDay() != p2.getPeriod().getDay() || p3.getPeriod().getIndex() < p2.getPeriod().getIndex())
                    continue;
                if (p1.getPeriod().equals(p3.getPeriod()) && ex1.getId() >= ex3.getId())
                    continue;
                if (p2.getPeriod().equals(p3.getPeriod()) && ex2.getId() >= ex3.getId())
                    continue;
                int m2d = 0;
                for (ExamStudent h : ex3.getStudents()) if (students.contains(h))
                    m2d++;
                if (m2d == 0)
                    continue;
                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(p2.getPeriod().getIndex() + 1), new CSVField(p2.getPeriod().getTimeStr()), new CSVField(ex3.getName()), new CSVField(ex3.getStudents().size()), new CSVField(p3.getPeriod().getIndex() + 1), new CSVField(p3.getPeriod().getTimeStr()), new CSVField(m2d), new CSVField(df.format(100.0 * m2d / Math.min(Math.min(ex1.getStudents().size(), ex2.getStudents().size()), ex3.getStudents().size()))) });
            }
        }
    }
    return csv;
}
Also used : CSVFile(org.cpsolver.ifs.util.CSVFile) CSVField(org.cpsolver.ifs.util.CSVFile.CSVField) ExamPlacement(org.cpsolver.exam.model.ExamPlacement) DecimalFormat(java.text.DecimalFormat) ExamStudent(org.cpsolver.exam.model.ExamStudent) Exam(org.cpsolver.exam.model.Exam)

Example 8 with CSVFile

use of org.cpsolver.ifs.util.CSVFile 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 9 with CSVFile

use of org.cpsolver.ifs.util.CSVFile in project cpsolver by UniTime.

the class AccommodationConflictsTable method createTable.

/**
 * Create report
 *
 * @param assignment current assignment
 * @param includeLastLikeStudents
 *            true, if last-like students should be included (i.e.,
 *            {@link Student#isDummy()} is true)
 * @param includeRealStudents
 *            true, if real students should be included (i.e.,
 *            {@link Student#isDummy()} is false)
 * @param useAmPm use 12-hour format
 * @return report as comma separated text file
 */
public CSVFile createTable(final Assignment<Request, Enrollment> assignment, boolean includeLastLikeStudents, boolean includeRealStudents, boolean useAmPm) {
    if (iSQ == null)
        throw new IllegalArgumentException("Student Schedule Quality is not enabled.");
    CSVFile csv = new CSVFile();
    csv.setHeader(new CSVFile.CSVField[] { new CSVFile.CSVField("__Student"), new CSVFile.CSVField("External Id"), new CSVFile.CSVField("Student Name"), new CSVFile.CSVField("Curriculum"), new CSVFile.CSVField("Group"), new CSVFile.CSVField("Advisor"), new CSVFile.CSVField("Type"), new CSVFile.CSVField("Course"), new CSVFile.CSVField("Class"), new CSVFile.CSVField("Meeting Time"), new CSVFile.CSVField("Room"), new CSVFile.CSVField("Conflicting\nCourse"), new CSVFile.CSVField("Conflicting\nClass"), new CSVFile.CSVField("Conflicting\nMeeting Time"), new CSVFile.CSVField("Conflicting\nRoom"), new CSVFile.CSVField("Penalty\nMinutes") });
    List<Conflict> confs = new ArrayList<Conflict>();
    for (Request r1 : getModel().variables()) {
        Enrollment e1 = assignment.getValue(r1);
        if (e1 == null || !(r1 instanceof CourseRequest))
            continue;
        for (StudentQuality.Type t : iTypes) confs.addAll(iSQ.conflicts(t, e1));
        for (Request r2 : r1.getStudent().getRequests()) {
            Enrollment e2 = assignment.getValue(r2);
            if (e2 == null || r1.getId() >= r2.getId() || !(r2 instanceof CourseRequest))
                continue;
            for (StudentQuality.Type t : iTypes) confs.addAll(iSQ.conflicts(t, e1, e2));
        }
    }
    Collections.sort(confs, new Comparator<Conflict>() {

        @Override
        public int compare(Conflict c1, Conflict c2) {
            int cmp = (c1.getStudent().getExternalId() == null ? "" : c1.getStudent().getExternalId()).compareTo(c2.getStudent().getExternalId() == null ? "" : c2.getStudent().getExternalId());
            if (cmp != 0)
                return cmp;
            cmp = c1.getStudent().compareTo(c2.getStudent());
            if (cmp != 0)
                return cmp;
            if (c1.getType() != c2.getType())
                return Integer.compare(c1.getType().ordinal(), c2.getType().ordinal());
            cmp = c1.getE1().getCourse().getName().toString().compareTo(c2.getE1().getCourse().getName());
            if (cmp != 0)
                return cmp;
            return ((Section) c1.getS1()).getName(c1.getE1().getCourse().getId()).compareTo(((Section) c2.getS1()).getName(c2.getE1().getCourse().getId()));
        }
    });
    for (Conflict conflict : confs) {
        if (conflict.getStudent().isDummy() && !includeLastLikeStudents)
            continue;
        if (!conflict.getStudent().isDummy() && !includeRealStudents)
            continue;
        if (conflict.getType() == Type.AccBackToBack) {
            boolean trueConflict = false;
            for (int i = 0; i < Constants.DAY_CODES.length; i++) {
                if ((conflict.getS1().getTime().getDayCode() & Constants.DAY_CODES[i]) == 0 || (conflict.getS2().getTime().getDayCode() & Constants.DAY_CODES[i]) == 0)
                    continue;
                boolean inBetween = false;
                for (Request r : conflict.getStudent().getRequests()) {
                    Enrollment e = r.getAssignment(assignment);
                    if (e == null)
                        continue;
                    for (SctAssignment s : e.getAssignments()) {
                        if (s.getTime() == null)
                            continue;
                        if ((s.getTime().getDayCode() & Constants.DAY_CODES[i]) == 0)
                            continue;
                        if (!s.getTime().shareWeeks(conflict.getS1().getTime()) || !s.getTime().shareWeeks(conflict.getS2().getTime()))
                            continue;
                        if (conflict.getS1().getTime().getStartSlot() + conflict.getS1().getTime().getLength() <= s.getTime().getStartSlot() && s.getTime().getStartSlot() + s.getTime().getLength() <= conflict.getS2().getTime().getStartSlot()) {
                            inBetween = true;
                            break;
                        }
                        if (conflict.getS2().getTime().getStartSlot() + conflict.getS2().getTime().getLength() <= s.getTime().getStartSlot() && s.getTime().getStartSlot() + s.getTime().getLength() <= conflict.getS1().getTime().getStartSlot()) {
                            inBetween = true;
                            break;
                        }
                    }
                }
                if (!inBetween) {
                    trueConflict = true;
                    break;
                }
            }
            if (!trueConflict)
                continue;
        }
        List<CSVFile.CSVField> line = new ArrayList<CSVFile.CSVField>();
        line.add(new CSVFile.CSVField(conflict.getStudent().getId()));
        line.add(new CSVFile.CSVField(conflict.getStudent().getExternalId()));
        line.add(new CSVFile.CSVField(conflict.getStudent().getName()));
        line.add(new CSVFile.CSVField(curriculum(conflict.getStudent())));
        line.add(new CSVFile.CSVField(group(conflict.getStudent())));
        line.add(new CSVFile.CSVField(advisor(conflict.getStudent())));
        switch(conflict.getType()) {
            case ShortDistance:
                line.add(new CSVFile.CSVField(iSQ.getDistanceMetric().getShortDistanceAccommodationReference()));
                break;
            case AccBackToBack:
                line.add(new CSVFile.CSVField(iSQ.getStudentQualityContext().getBackToBackAccommodation()));
                break;
            case AccBreaksBetweenClasses:
                line.add(new CSVFile.CSVField(iSQ.getStudentQualityContext().getBreakBetweenClassesAccommodation()));
                break;
            case AccFreeTimeOverlap:
                line.add(new CSVFile.CSVField(iSQ.getStudentQualityContext().getFreeTimeAccommodation()));
                break;
            default:
                line.add(new CSVFile.CSVField(conflict.getType().getName()));
                break;
        }
        line.add(new CSVFile.CSVField(conflict.getE1().getCourse().getName()));
        line.add(new CSVFile.CSVField(conflict.getS1() instanceof Section ? ((Section) conflict.getS1()).getName(conflict.getE1().getCourse().getId()) : ""));
        line.add(new CSVFile.CSVField(conflict.getS1().getTime() == null ? "" : conflict.getS1().getTime().getLongName(useAmPm)));
        line.add(new CSVFile.CSVField(rooms(conflict.getS1())));
        line.add(new CSVFile.CSVField(conflict.getE2().isCourseRequest() ? conflict.getE2().getCourse().getName() : "Free Time"));
        line.add(new CSVFile.CSVField(conflict.getS2() instanceof Section ? ((Section) conflict.getS2()).getName(conflict.getE2().getCourse().getId()) : ""));
        line.add(new CSVFile.CSVField(conflict.getS2().getTime() == null ? "" : conflict.getS2().getTime().getLongName(useAmPm)));
        line.add(new CSVFile.CSVField(rooms(conflict.getS2())));
        switch(conflict.getType()) {
            case AccFreeTimeOverlap:
                line.add(new CSVFile.CSVField(5 * conflict.getPenalty()));
                break;
            case ShortDistance:
                line.add(new CSVFile.CSVField(iSQ.getStudentQualityContext().getDistanceInMinutes(((Section) conflict.getS1()).getPlacement(), ((Section) conflict.getS2()).getPlacement())));
                break;
            case AccBackToBack:
            case AccBreaksBetweenClasses:
                TimeLocation t1 = conflict.getS1().getTime();
                TimeLocation t2 = conflict.getS2().getTime();
                if (t1.getStartSlot() + t1.getNrSlotsPerMeeting() <= t2.getStartSlot()) {
                    int dist = t2.getStartSlot() - (t1.getStartSlot() + t1.getNrSlotsPerMeeting());
                    line.add(new CSVFile.CSVField(5 * dist + t1.getBreakTime()));
                } else if (t2.getStartSlot() + t2.getNrSlotsPerMeeting() <= t1.getStartSlot()) {
                    int dist = t1.getStartSlot() - (t2.getStartSlot() + t2.getNrSlotsPerMeeting());
                    line.add(new CSVFile.CSVField(5 * dist + t2.getBreakTime()));
                } else {
                    line.add(new CSVFile.CSVField(null));
                }
                break;
            default:
                line.add(new CSVFile.CSVField(conflict.getPenalty()));
                break;
        }
        csv.addLine(line);
    }
    return csv;
}
Also used : CSVFile(org.cpsolver.ifs.util.CSVFile) StudentQuality(org.cpsolver.studentsct.extension.StudentQuality) TimeLocation(org.cpsolver.coursett.model.TimeLocation) ArrayList(java.util.ArrayList) Request(org.cpsolver.studentsct.model.Request) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Section(org.cpsolver.studentsct.model.Section) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Conflict(org.cpsolver.studentsct.extension.StudentQuality.Conflict) Enrollment(org.cpsolver.studentsct.model.Enrollment) Type(org.cpsolver.studentsct.extension.StudentQuality.Type) SctAssignment(org.cpsolver.studentsct.model.SctAssignment)

Example 10 with CSVFile

use of org.cpsolver.ifs.util.CSVFile in project cpsolver by UniTime.

the class CourseConflictTable method createTable.

/**
 * Create report
 *
 * @param assignment current assignment
 * @param includeLastLikeStudents
 *            true, if last-like students should be included (i.e.,
 *            {@link Student#isDummy()} is true)
 * @param includeRealStudents
 *            true, if real students should be included (i.e.,
 *            {@link Student#isDummy()} is false)
 * @param useAmPm use 12-hour format
 * @return report as comma separated text file
 */
@SuppressWarnings("unchecked")
public CSVFile createTable(Assignment<Request, Enrollment> assignment, boolean includeLastLikeStudents, boolean includeRealStudents, boolean useAmPm) {
    CSVFile csv = new CSVFile();
    csv.setHeader(new CSVFile.CSVField[] { new CSVFile.CSVField("UnasgnCrs"), new CSVFile.CSVField("ConflCrs"), new CSVFile.CSVField("NrStud"), new CSVFile.CSVField("StudWeight"), new CSVFile.CSVField("NoAlt"), new CSVFile.CSVField("Reason") });
    HashMap<Course, HashMap<Course, Object[]>> unassignedCourseTable = new HashMap<Course, HashMap<Course, Object[]>>();
    for (Request request : new ArrayList<Request>(getModel().unassignedVariables(assignment))) {
        if (request.getStudent().isDummy() && !includeLastLikeStudents)
            continue;
        if (!request.getStudent().isDummy() && !includeRealStudents)
            continue;
        if (request instanceof CourseRequest) {
            CourseRequest courseRequest = (CourseRequest) request;
            if (courseRequest.getStudent().isComplete(assignment))
                continue;
            List<Enrollment> values = courseRequest.values(assignment);
            SectionLimit limitConstraint = null;
            for (GlobalConstraint<Request, Enrollment> c : getModel().globalConstraints()) {
                if (c instanceof SectionLimit) {
                    limitConstraint = (SectionLimit) c;
                    break;
                }
            }
            if (limitConstraint == null) {
                limitConstraint = new SectionLimit(new DataProperties());
                limitConstraint.setModel(getModel());
            }
            List<Enrollment> availableValues = new ArrayList<Enrollment>(values.size());
            for (Enrollment enrollment : values) {
                if (!limitConstraint.inConflict(assignment, enrollment))
                    availableValues.add(enrollment);
            }
            if (availableValues.isEmpty()) {
                Course course = courseRequest.getCourses().get(0);
                HashMap<Course, Object[]> conflictCourseTable = unassignedCourseTable.get(course);
                if (conflictCourseTable == null) {
                    conflictCourseTable = new HashMap<Course, Object[]>();
                    unassignedCourseTable.put(course, conflictCourseTable);
                }
                Object[] weight = conflictCourseTable.get(course);
                double nrStud = (weight == null ? 0.0 : ((Double) weight[0]).doubleValue()) + 1.0;
                double nrStudW = (weight == null ? 0.0 : ((Double) weight[1]).doubleValue()) + request.getWeight();
                boolean noAlt = (weight == null ? true : ((Boolean) weight[2]).booleanValue());
                HashSet<String> expl = (weight == null ? new HashSet<String>() : (HashSet<String>) weight[3]);
                expl.add(course.getName() + " n/a");
                conflictCourseTable.put(course, new Object[] { Double.valueOf(nrStud), Double.valueOf(nrStudW), Boolean.valueOf(noAlt), expl });
            }
            for (Enrollment enrollment : availableValues) {
                Set<Enrollment> conflicts = getModel().conflictValues(assignment, enrollment);
                if (conflicts.isEmpty()) {
                    sLog.warn("Request " + courseRequest + " of student " + courseRequest.getStudent() + " not assigned, however, no conflicts were returned.");
                    assignment.assign(0, enrollment);
                    break;
                }
                Course course = null;
                for (Course c : courseRequest.getCourses()) {
                    if (c.getOffering().equals(enrollment.getConfig().getOffering())) {
                        course = c;
                        break;
                    }
                }
                if (course == null) {
                    sLog.warn("Course not found for request " + courseRequest + " of student " + courseRequest.getStudent() + ".");
                    continue;
                }
                HashMap<Course, Object[]> conflictCourseTable = unassignedCourseTable.get(course);
                if (conflictCourseTable == null) {
                    conflictCourseTable = new HashMap<Course, Object[]>();
                    unassignedCourseTable.put(course, conflictCourseTable);
                }
                for (Enrollment conflict : conflicts) {
                    if (conflict.variable() instanceof CourseRequest) {
                        CourseRequest conflictCourseRequest = (CourseRequest) conflict.variable();
                        Course conflictCourse = null;
                        for (Course c : conflictCourseRequest.getCourses()) {
                            if (c.getOffering().equals(conflict.getConfig().getOffering())) {
                                conflictCourse = c;
                                break;
                            }
                        }
                        if (conflictCourse == null) {
                            sLog.warn("Course not found for request " + conflictCourseRequest + " of student " + conflictCourseRequest.getStudent() + ".");
                            continue;
                        }
                        double weightThisConflict = request.getWeight() / availableValues.size() / conflicts.size();
                        double partThisConflict = 1.0 / availableValues.size() / conflicts.size();
                        Object[] weight = conflictCourseTable.get(conflictCourse);
                        double nrStud = (weight == null ? 0.0 : ((Double) weight[0]).doubleValue()) + partThisConflict;
                        double nrStudW = (weight == null ? 0.0 : ((Double) weight[1]).doubleValue()) + weightThisConflict;
                        boolean noAlt = (weight == null ? areInHardConfict(assignment, request, conflict.getRequest()) : ((Boolean) weight[2]).booleanValue());
                        HashSet<String> expl = (weight == null ? new HashSet<String>() : (HashSet<String>) weight[3]);
                        expl.addAll(explanations(assignment, enrollment, conflict, useAmPm));
                        conflictCourseTable.put(conflictCourse, new Object[] { Double.valueOf(nrStud), Double.valueOf(nrStudW), Boolean.valueOf(noAlt), expl });
                    }
                }
            }
        }
    }
    for (Map.Entry<Course, HashMap<Course, Object[]>> entry : unassignedCourseTable.entrySet()) {
        Course unassignedCourse = entry.getKey();
        HashMap<Course, Object[]> conflictCourseTable = entry.getValue();
        for (Map.Entry<Course, Object[]> entry2 : conflictCourseTable.entrySet()) {
            Course conflictCourse = entry2.getKey();
            Object[] weight = entry2.getValue();
            HashSet<String> expl = (HashSet<String>) weight[3];
            String explStr = "";
            for (Iterator<String> k = new TreeSet<String>(expl).iterator(); k.hasNext(); ) explStr += k.next() + (k.hasNext() ? "\n" : "");
            csv.addLine(new CSVFile.CSVField[] { new CSVFile.CSVField(unassignedCourse.getName()), new CSVFile.CSVField(conflictCourse.getName()), new CSVFile.CSVField(sDF.format(weight[0])), new CSVFile.CSVField(sDF.format(weight[1])), new CSVFile.CSVField(((Boolean) weight[2]).booleanValue() ? "Y" : "N"), new CSVFile.CSVField(explStr) });
        }
    }
    if (csv.getLines() != null)
        Collections.sort(csv.getLines(), new Comparator<CSVFile.CSVLine>() {

            @Override
            public int compare(CSVFile.CSVLine l1, CSVFile.CSVLine l2) {
                // int cmp =
                // l2.getField(3).toString().compareTo(l1.getField(3).toString());
                // if (cmp!=0) return cmp;
                int cmp = Double.compare(l2.getField(2).toDouble(), l1.getField(2).toDouble());
                if (cmp != 0)
                    return cmp;
                cmp = l1.getField(0).toString().compareTo(l2.getField(0).toString());
                if (cmp != 0)
                    return cmp;
                return l1.getField(1).toString().compareTo(l2.getField(1).toString());
            }
        });
    return csv;
}
Also used : CSVFile(org.cpsolver.ifs.util.CSVFile) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DataProperties(org.cpsolver.ifs.util.DataProperties) Comparator(java.util.Comparator) Enrollment(org.cpsolver.studentsct.model.Enrollment) Course(org.cpsolver.studentsct.model.Course) HashSet(java.util.HashSet) Request(org.cpsolver.studentsct.model.Request) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) GlobalConstraint(org.cpsolver.ifs.model.GlobalConstraint) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) SectionLimit(org.cpsolver.studentsct.constraint.SectionLimit) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

CSVFile (org.cpsolver.ifs.util.CSVFile)26 ArrayList (java.util.ArrayList)14 CSVField (org.cpsolver.ifs.util.CSVFile.CSVField)13 Exam (org.cpsolver.exam.model.Exam)12 ExamPlacement (org.cpsolver.exam.model.ExamPlacement)12 TreeSet (java.util.TreeSet)9 Enrollment (org.cpsolver.studentsct.model.Enrollment)9 Course (org.cpsolver.studentsct.model.Course)8 Request (org.cpsolver.studentsct.model.Request)8 CourseRequest (org.cpsolver.studentsct.model.CourseRequest)7 Section (org.cpsolver.studentsct.model.Section)7 ExamPeriod (org.cpsolver.exam.model.ExamPeriod)6 ExamRoomPlacement (org.cpsolver.exam.model.ExamRoomPlacement)6 ExamStudent (org.cpsolver.exam.model.ExamStudent)6 HashSet (java.util.HashSet)5 Map (java.util.Map)5 DecimalFormat (java.text.DecimalFormat)4 Comparator (java.util.Comparator)4 HashMap (java.util.HashMap)4 Set (java.util.Set)4