Search in sources :

Example 21 with Offering

use of org.cpsolver.studentsct.model.Offering in project cpsolver by UniTime.

the class StudentSectioningXMLLoader method loadStudent.

/**
 * Load student
 * @param studentEl student element
 * @param offeringTable offering table
 * @return loaded student
 */
protected Student loadStudent(Element studentEl, Map<Long, Offering> offeringTable) {
    Student student = new Student(Long.parseLong(studentEl.attributeValue("id")), "true".equals(studentEl.attributeValue("dummy")));
    if (studentEl.attributeValue("priority") != null)
        student.setPriority(StudentPriority.getPriority(studentEl.attributeValue("priority")));
    if ("true".equals(studentEl.attributeValue("shortDistances")))
        student.setNeedShortDistances(true);
    if ("true".equals(studentEl.attributeValue("allowDisabled")))
        student.setAllowDisabled(true);
    student.setExternalId(studentEl.attributeValue("externalId"));
    student.setName(studentEl.attributeValue("name"));
    student.setStatus(studentEl.attributeValue("status"));
    String minCredit = studentEl.attributeValue("minCredit");
    if (minCredit != null)
        student.setMinCredit(Float.parseFloat(minCredit));
    String maxCredit = studentEl.attributeValue("maxCredit");
    if (maxCredit != null)
        student.setMaxCredit(Float.parseFloat(maxCredit));
    List<String[]> clasf = new ArrayList<String[]>();
    List<String[]> major = new ArrayList<String[]>();
    for (Iterator<?> j = studentEl.elementIterator(); j.hasNext(); ) {
        Element requestEl = (Element) j.next();
        if ("classification".equals(requestEl.getName())) {
            clasf.add(new String[] { requestEl.attributeValue("area"), requestEl.attributeValue("code"), requestEl.attributeValue("label") });
        } else if ("major".equals(requestEl.getName())) {
            major.add(new String[] { requestEl.attributeValue("area"), requestEl.attributeValue("code"), requestEl.attributeValue("label") });
        } else if ("minor".equals(requestEl.getName())) {
            if ("A".equals(requestEl.attributeValue("area")))
                student.getAccommodations().add(requestEl.attributeValue("code"));
            else
                student.getGroups().add(new StudentGroup(requestEl.attributeValue("area"), requestEl.attributeValue("code"), requestEl.attributeValue("label")));
        } else if ("unavailability".equals(requestEl.getName())) {
            Offering offering = offeringTable.get(Long.parseLong(requestEl.attributeValue("offering")));
            Section section = (offering == null ? null : offering.getSection(Long.parseLong(requestEl.attributeValue("section"))));
            if (section != null)
                new Unavailability(student, section, "true".equals(requestEl.attributeValue("allowOverlap")));
        } else if ("acm".equals(requestEl.getName())) {
            if (requestEl.attributeValue("minor") != null)
                student.getAreaClassificationMinors().add(new AreaClassificationMajor(requestEl.attributeValue("area"), requestEl.attributeValue("areaName"), requestEl.attributeValue("classification"), requestEl.attributeValue("classificationName"), requestEl.attributeValue("minor"), requestEl.attributeValue("minorName"), requestEl.attributeValue("concentration"), requestEl.attributeValue("concentrationName"), requestEl.attributeValue("degree"), requestEl.attributeValue("degreeName"), requestEl.attributeValue("program"), requestEl.attributeValue("programName"), requestEl.attributeValue("weight") == null ? null : Double.valueOf(requestEl.attributeValue("weight"))));
            else
                student.getAreaClassificationMajors().add(new AreaClassificationMajor(requestEl.attributeValue("area"), requestEl.attributeValue("areaName"), requestEl.attributeValue("classification"), requestEl.attributeValue("classificationName"), requestEl.attributeValue("major"), requestEl.attributeValue("majorName"), requestEl.attributeValue("concentration"), requestEl.attributeValue("concentrationName"), requestEl.attributeValue("degree"), requestEl.attributeValue("degreeName"), requestEl.attributeValue("program"), requestEl.attributeValue("programName"), requestEl.attributeValue("weight") == null ? null : Double.valueOf(requestEl.attributeValue("weight"))));
        } else if ("group".equals(requestEl.getName())) {
            student.getGroups().add(new StudentGroup(requestEl.attributeValue("type"), requestEl.attributeValue("reference"), requestEl.attributeValue("name")));
        } else if ("accommodation".equals(requestEl.getName())) {
            student.getAccommodations().add(requestEl.attributeValue("reference"));
        } else if ("advisor".equals(requestEl.getName())) {
            student.getAdvisors().add(new Instructor(0l, requestEl.attributeValue("externalId"), requestEl.attributeValue("name"), requestEl.attributeValue("email")));
        }
    }
    for (int i = 0; i < Math.min(clasf.size(), major.size()); i++) {
        student.getAreaClassificationMajors().add(new AreaClassificationMajor(clasf.get(i)[0], clasf.get(i)[1], major.get(i)[1]));
    }
    return student;
}
Also used : AreaClassificationMajor(org.cpsolver.studentsct.model.AreaClassificationMajor) Element(org.dom4j.Element) Instructor(org.cpsolver.studentsct.model.Instructor) ArrayList(java.util.ArrayList) Student(org.cpsolver.studentsct.model.Student) Offering(org.cpsolver.studentsct.model.Offering) Section(org.cpsolver.studentsct.model.Section) Constraint(org.cpsolver.ifs.model.Constraint) Unavailability(org.cpsolver.studentsct.model.Unavailability) StudentGroup(org.cpsolver.studentsct.model.StudentGroup)

Example 22 with Offering

use of org.cpsolver.studentsct.model.Offering in project cpsolver by UniTime.

the class StudentSectioningXMLLoader method load.

/**
 * Load data from the given XML root
 * @param root document root
 * @throws DocumentException
 */
protected void load(Element root) throws DocumentException {
    sLogger.debug("Root element: " + root.getName());
    if (!"sectioning".equals(root.getName())) {
        sLogger.error("Given XML file is not student sectioning problem.");
        return;
    }
    if (iLoadOfferings && getModel().getDistanceConflict() != null && root.element("travel-times") != null)
        loadTravelTimes(root.element("travel-times"), getModel().getDistanceConflict().getDistanceMetric());
    Map<Long, Placement> timetable = null;
    if (iTimetableFile != null) {
        sLogger.info("Reading timetable from " + iTimetableFile + " ...");
        Document timetableDocument = (new SAXReader()).read(iTimetableFile);
        Element timetableRoot = timetableDocument.getRootElement();
        if (!"timetable".equals(timetableRoot.getName())) {
            sLogger.error("Given XML file is not course timetabling problem.");
            return;
        }
        timetable = loadTimetable(timetableRoot);
    }
    Progress.getInstance(getModel()).load(root, true);
    Progress.getInstance(getModel()).message(Progress.MSGLEVEL_STAGE, "Restoring from backup ...");
    if (root.attributeValue("term") != null)
        getModel().getProperties().setProperty("Data.Term", root.attributeValue("term"));
    if (root.attributeValue("year") != null)
        getModel().getProperties().setProperty("Data.Year", root.attributeValue("year"));
    if (root.attributeValue("initiative") != null)
        getModel().getProperties().setProperty("Data.Initiative", root.attributeValue("initiative"));
    Map<Long, Offering> offeringTable = new HashMap<Long, Offering>();
    Map<Long, Course> courseTable = new HashMap<Long, Course>();
    if (iLoadOfferings && root.element("offerings") != null) {
        loadOfferings(root.element("offerings"), offeringTable, courseTable, timetable);
    } else {
        for (Offering offering : getModel().getOfferings()) {
            offeringTable.put(Long.valueOf(offering.getId()), offering);
            for (Course course : offering.getCourses()) {
                courseTable.put(Long.valueOf(course.getId()), course);
            }
        }
    }
    List<Enrollment> bestEnrollments = new ArrayList<Enrollment>();
    List<Enrollment> currentEnrollments = new ArrayList<Enrollment>();
    if (iLoadStudents && root.element("students") != null) {
        loadStudents(root.element("students"), offeringTable, courseTable, bestEnrollments, currentEnrollments);
    }
    if (iLoadOfferings && root.element("constraints") != null)
        loadLinkedSections(root.element("constraints"), offeringTable);
    if (!bestEnrollments.isEmpty())
        assignBest(bestEnrollments);
    if (!currentEnrollments.isEmpty())
        assignCurrent(currentEnrollments);
    if (iMoveCriticalUp)
        moveCriticalRequestsUp();
    sLogger.debug("Model successfully loaded.");
}
Also used : HashMap(java.util.HashMap) SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) Document(org.dom4j.Document) Offering(org.cpsolver.studentsct.model.Offering) Placement(org.cpsolver.coursett.model.Placement) Enrollment(org.cpsolver.studentsct.model.Enrollment) Course(org.cpsolver.studentsct.model.Course)

Example 23 with Offering

use of org.cpsolver.studentsct.model.Offering in project cpsolver by UniTime.

the class CourseLimitCheck method check.

/**
 * Check for courses where the limit is below the number of students that
 * request the course
 *
 * @return false, if there is such a case
 */
public boolean check() {
    sLog.info("Checking for course limits...");
    boolean ret = true;
    for (Offering offering : getModel().getOfferings()) {
        boolean hasUnlimitedSection = false;
        if (iFixUnlimited)
            for (Config config : offering.getConfigs()) {
                for (Subpart subpart : config.getSubparts()) {
                    for (Section section : subpart.getSections()) {
                        if (section.getLimit() < 0)
                            hasUnlimitedSection = true;
                    }
                }
            }
        int offeringLimit = 0;
        int nrStudents = 0;
        for (Course course : offering.getCourses()) {
            if (course.getLimit() < 0) {
                offeringLimit = -1;
                continue;
            }
            if (iFixUnlimited && hasUnlimitedSection) {
                sLog.info("Course " + course + " made unlimited.");
                course.setLimit(-1);
                offeringLimit = -1;
                continue;
            }
            double total = 0;
            double lastLike = 0, real = 0;
            for (Request request : getModel().variables()) {
                if (request instanceof CourseRequest && ((CourseRequest) request).getCourses().contains(course)) {
                    total += request.getWeight();
                    if (request.getStudent().isDummy())
                        lastLike += request.getWeight();
                    else
                        real += request.getWeight();
                }
            }
            nrStudents += Math.round(total);
            offeringLimit += course.getLimit();
            if (Math.round(total) > course.getLimit()) {
                sLog.error("Course " + course + " is requested by " + sDF.format(total) + " students, but its limit is only " + course.getLimit());
                ret = false;
                iCSVFile.addLine(new CSVFile.CSVField[] { new CSVFile.CSVField(course.getName()), new CSVFile.CSVField(course.getLimit()), new CSVFile.CSVField(total), new CSVFile.CSVField(real), new CSVFile.CSVField(lastLike) });
                if (iUpZeroLimits && course.getLimit() == 0) {
                    int oldLimit = course.getLimit();
                    course.setLimit((int) Math.round(total));
                    sLog.info("  -- limit of course " + course + " increased to " + course.getLimit() + " (was " + oldLimit + ")");
                } else if (iUpNonZeroLimits && course.getLimit() > 0) {
                    int oldLimit = course.getLimit();
                    course.setLimit((int) Math.round(total));
                    sLog.info("  -- limit of course " + course + " increased to " + course.getLimit() + " (was " + oldLimit + ")");
                }
            }
        }
        if (iUpZeroLimits && offeringLimit == 0 && nrStudents > 0) {
            for (Config config : offering.getConfigs()) {
                for (Subpart subpart : config.getSubparts()) {
                    for (Section section : subpart.getSections()) {
                        int oldLimit = section.getLimit();
                        section.setLimit(Math.max(section.getLimit(), (int) Math.ceil(nrStudents / subpart.getSections().size())));
                        sLog.info("    -- limit of section " + section + " increased to " + section.getLimit() + " (was " + oldLimit + ")");
                    }
                }
            }
        } else if (iUpNonZeroLimits && offeringLimit >= 0 && nrStudents > offeringLimit) {
            double fact = ((double) nrStudents) / offeringLimit;
            for (Config config : offering.getConfigs()) {
                for (Subpart subpart : config.getSubparts()) {
                    for (Section section : subpart.getSections()) {
                        int oldLimit = section.getLimit();
                        section.setLimit((int) Math.ceil(fact * section.getLimit()));
                        sLog.info("    -- limit of section " + section + " increased to " + section.getLimit() + " (was " + oldLimit + ")");
                    }
                }
            }
        }
        if (offeringLimit >= 0) {
            int totalSectionLimit = 0;
            for (Config config : offering.getConfigs()) {
                int configLimit = -1;
                for (Subpart subpart : config.getSubparts()) {
                    int subpartLimit = 0;
                    for (Section section : subpart.getSections()) {
                        subpartLimit += section.getLimit();
                    }
                    if (configLimit < 0)
                        configLimit = subpartLimit;
                    else
                        configLimit = Math.min(configLimit, subpartLimit);
                }
                totalSectionLimit += configLimit;
            }
            if (totalSectionLimit < offeringLimit) {
                sLog.error("Offering limit of " + offering + " is " + offeringLimit + ", but total section limit is only " + totalSectionLimit);
                if (iUpZeroLimits && totalSectionLimit == 0) {
                    for (Config config : offering.getConfigs()) {
                        for (Subpart subpart : config.getSubparts()) {
                            for (Section section : subpart.getSections()) {
                                int oldLimit = section.getLimit();
                                section.setLimit(Math.max(section.getLimit(), (int) Math.ceil(((double) offeringLimit) / subpart.getSections().size())));
                                sLog.info("    -- limit of section " + section + " increased to " + section.getLimit() + " (was " + oldLimit + ")");
                            }
                        }
                    }
                } else if (iUpNonZeroLimits && totalSectionLimit > 0) {
                    double fact = ((double) offeringLimit) / totalSectionLimit;
                    for (Config config : offering.getConfigs()) {
                        for (Subpart subpart : config.getSubparts()) {
                            for (Section section : subpart.getSections()) {
                                int oldLimit = section.getLimit();
                                section.setLimit((int) Math.ceil(fact * section.getLimit()));
                                sLog.info("    -- limit of section " + section + " increased to " + section.getLimit() + " (was " + oldLimit + ")");
                            }
                        }
                    }
                }
            }
        }
    }
    return ret;
}
Also used : CourseRequest(org.cpsolver.studentsct.model.CourseRequest) CSVFile(org.cpsolver.ifs.util.CSVFile) Config(org.cpsolver.studentsct.model.Config) Subpart(org.cpsolver.studentsct.model.Subpart) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Request(org.cpsolver.studentsct.model.Request) Course(org.cpsolver.studentsct.model.Course) Offering(org.cpsolver.studentsct.model.Offering) Section(org.cpsolver.studentsct.model.Section)

Example 24 with Offering

use of org.cpsolver.studentsct.model.Offering in project cpsolver by UniTime.

the class Test method clone.

protected Course clone(Course course, long studentId, Student originalStudent, Map<Long, Section> classTable, StudentSectioningModel model) {
    Offering clonedOffering = new Offering(course.getOffering().getId(), course.getOffering().getName());
    clonedOffering.setModel(model);
    int courseLimit = course.getLimit();
    if (courseLimit >= 0) {
        courseLimit -= course.getEnrollments(assignment()).size();
        if (courseLimit < 0)
            courseLimit = 0;
        for (Iterator<Enrollment> i = course.getEnrollments(assignment()).iterator(); i.hasNext(); ) {
            Enrollment enrollment = i.next();
            if (enrollment.getStudent().getId() == studentId) {
                courseLimit++;
                break;
            }
        }
    }
    Course clonedCourse = new Course(course.getId(), course.getSubjectArea(), course.getCourseNumber(), clonedOffering, courseLimit, course.getProjected());
    clonedCourse.setNote(course.getNote());
    Hashtable<Config, Config> configs = new Hashtable<Config, Config>();
    Hashtable<Subpart, Subpart> subparts = new Hashtable<Subpart, Subpart>();
    Hashtable<Section, Section> sections = new Hashtable<Section, Section>();
    for (Iterator<Config> e = course.getOffering().getConfigs().iterator(); e.hasNext(); ) {
        Config config = e.next();
        int configLimit = config.getLimit();
        int configEnrollment = config.getEnrollments(assignment()).size();
        if (configLimit >= 0) {
            configLimit -= config.getEnrollments(assignment()).size();
            if (configLimit < 0)
                configLimit = 0;
            for (Iterator<Enrollment> i = config.getEnrollments(assignment()).iterator(); i.hasNext(); ) {
                Enrollment enrollment = i.next();
                if (enrollment.getStudent().getId() == studentId) {
                    configLimit++;
                    configEnrollment--;
                    break;
                }
            }
        }
        OnlineConfig clonedConfig = new OnlineConfig(config.getId(), configLimit, config.getName(), clonedOffering);
        clonedConfig.setInstructionalMethodId(config.getInstructionalMethodId());
        clonedConfig.setInstructionalMethodName(config.getInstructionalMethodName());
        clonedConfig.setInstructionalMethodReference(config.getInstructionalMethodReference());
        clonedConfig.setEnrollment(configEnrollment);
        configs.put(config, clonedConfig);
        for (Iterator<Subpart> f = config.getSubparts().iterator(); f.hasNext(); ) {
            Subpart subpart = f.next();
            Subpart clonedSubpart = new Subpart(subpart.getId(), subpart.getInstructionalType(), subpart.getName(), clonedConfig, (subpart.getParent() == null ? null : subparts.get(subpart.getParent())));
            clonedSubpart.setAllowOverlap(subpart.isAllowOverlap());
            clonedSubpart.setCredit(subpart.getCredit());
            subparts.put(subpart, clonedSubpart);
            for (Iterator<Section> g = subpart.getSections().iterator(); g.hasNext(); ) {
                Section section = g.next();
                int limit = section.getLimit();
                int enrl = section.getEnrollments(assignment()).size();
                if (limit >= 0) {
                    // limited section, deduct enrollments
                    limit -= section.getEnrollments(assignment()).size();
                    if (limit < 0)
                        // over-enrolled, but not unlimited
                        limit = 0;
                    if (studentId >= 0)
                        for (Enrollment enrollment : section.getEnrollments(assignment())) if (enrollment.getStudent().getId() == studentId) {
                            limit++;
                            enrl--;
                            break;
                        }
                }
                OnlineSection clonedSection = new OnlineSection(section.getId(), limit, section.getName(course.getId()), clonedSubpart, section.getPlacement(), section.getInstructors(), (section.getParent() == null ? null : sections.get(section.getParent())));
                clonedSection.setName(-1l, section.getName(-1l));
                clonedSection.setNote(section.getNote());
                clonedSection.setSpaceExpected(section.getSpaceExpected());
                clonedSection.setSpaceHeld(section.getSpaceHeld());
                clonedSection.setEnrollment(enrl);
                clonedSection.setCancelled(section.isCancelled());
                clonedSection.setEnabled(section.isEnabled());
                clonedSection.setOnline(section.isOnline());
                if (section.getIgnoreConflictWithSectionIds() != null)
                    for (Long id : section.getIgnoreConflictWithSectionIds()) clonedSection.addIgnoreConflictWith(id);
                if (limit > 0) {
                    double available = Math.round(section.getSpaceExpected() - limit);
                    clonedSection.setPenalty(available / section.getLimit());
                }
                sections.put(section, clonedSection);
                classTable.put(section.getId(), clonedSection);
            }
        }
    }
    if (course.getOffering().hasReservations()) {
        for (Reservation reservation : course.getOffering().getReservations()) {
            int reservationLimit = (int) Math.round(reservation.getLimit());
            if (reservationLimit >= 0) {
                reservationLimit -= reservation.getEnrollments(assignment()).size();
                if (reservationLimit < 0)
                    reservationLimit = 0;
                for (Iterator<Enrollment> i = reservation.getEnrollments(assignment()).iterator(); i.hasNext(); ) {
                    Enrollment enrollment = i.next();
                    if (enrollment.getStudent().getId() == studentId) {
                        reservationLimit++;
                        break;
                    }
                }
                if (reservationLimit <= 0 && !reservation.mustBeUsed())
                    continue;
            }
            boolean applicable = originalStudent != null && reservation.isApplicable(originalStudent);
            if (reservation instanceof CourseReservation)
                applicable = (course.getId() == ((CourseReservation) reservation).getCourse().getId());
            if (reservation instanceof org.cpsolver.studentsct.reservation.DummyReservation) {
                // the student is already enrolled in the course
                for (Enrollment enrollment : course.getEnrollments(assignment())) if (enrollment.getStudent().getId() == studentId) {
                    applicable = true;
                    break;
                }
            }
            Reservation clonedReservation = new OnlineReservation(0, reservation.getId(), clonedOffering, reservation.getPriority(), reservation.canAssignOverLimit(), reservationLimit, applicable, reservation.mustBeUsed(), reservation.isAllowOverlap(), reservation.isExpired());
            for (Config config : reservation.getConfigs()) clonedReservation.addConfig(configs.get(config));
            for (Map.Entry<Subpart, Set<Section>> entry : reservation.getSections().entrySet()) {
                Set<Section> clonedSections = new HashSet<Section>();
                for (Section section : entry.getValue()) clonedSections.add(sections.get(section));
                clonedReservation.getSections().put(subparts.get(entry.getKey()), clonedSections);
            }
        }
    }
    return clonedCourse;
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Config(org.cpsolver.studentsct.model.Config) CourseReservation(org.cpsolver.studentsct.reservation.CourseReservation) Reservation(org.cpsolver.studentsct.reservation.Reservation) Enrollment(org.cpsolver.studentsct.model.Enrollment) Course(org.cpsolver.studentsct.model.Course) HashSet(java.util.HashSet) CourseReservation(org.cpsolver.studentsct.reservation.CourseReservation) Hashtable(java.util.Hashtable) Offering(org.cpsolver.studentsct.model.Offering) Section(org.cpsolver.studentsct.model.Section) Subpart(org.cpsolver.studentsct.model.Subpart) Map(java.util.Map) HashMap(java.util.HashMap) AssignmentMap(org.cpsolver.ifs.assignment.AssignmentMap)

Example 25 with Offering

use of org.cpsolver.studentsct.model.Offering in project cpsolver by UniTime.

the class PriorityStudentWeights method main.

/**
 * Test case -- run to see the weights for a few courses
 * @param args program arguments
 */
public static void main(String[] args) {
    PriorityStudentWeights pw = new PriorityStudentWeights(new DataProperties());
    DecimalFormat df = new DecimalFormat("0.000000");
    Student s = new Student(0l);
    new CourseRequest(1l, 0, false, s, ToolBox.toList(new Course(1, "A", "1", new Offering(0, "A")), new Course(1, "A", "2", new Offering(0, "A")), new Course(1, "A", "3", new Offering(0, "A"))), false, null);
    new CourseRequest(2l, 1, false, s, ToolBox.toList(new Course(1, "B", "1", new Offering(0, "B")), new Course(1, "B", "2", new Offering(0, "B")), new Course(1, "B", "3", new Offering(0, "B"))), false, null);
    new CourseRequest(3l, 2, false, s, ToolBox.toList(new Course(1, "C", "1", new Offering(0, "C")), new Course(1, "C", "2", new Offering(0, "C")), new Course(1, "C", "3", new Offering(0, "C"))), false, null);
    new CourseRequest(4l, 3, false, s, ToolBox.toList(new Course(1, "D", "1", new Offering(0, "D")), new Course(1, "D", "2", new Offering(0, "D")), new Course(1, "D", "3", new Offering(0, "D"))), false, null);
    new CourseRequest(5l, 4, false, s, ToolBox.toList(new Course(1, "E", "1", new Offering(0, "E")), new Course(1, "E", "2", new Offering(0, "E")), new Course(1, "E", "3", new Offering(0, "E"))), false, null);
    new CourseRequest(6l, 5, true, s, ToolBox.toList(new Course(1, "F", "1", new Offering(0, "F")), new Course(1, "F", "2", new Offering(0, "F")), new Course(1, "F", "3", new Offering(0, "F"))), false, null);
    new CourseRequest(7l, 6, true, s, ToolBox.toList(new Course(1, "G", "1", new Offering(0, "G")), new Course(1, "G", "2", new Offering(0, "G")), new Course(1, "G", "3", new Offering(0, "G"))), false, null);
    Assignment<Request, Enrollment> assignment = new DefaultSingleAssignment<Request, Enrollment>();
    Placement p = new Placement(null, new TimeLocation(1, 90, 12, 0, 0, null, null, new BitSet(), 10), new ArrayList<RoomLocation>());
    for (Request r : s.getRequests()) {
        CourseRequest cr = (CourseRequest) r;
        double[] w = new double[] { 0.0, 0.0, 0.0 };
        for (int i = 0; i < cr.getCourses().size(); i++) {
            Config cfg = new Config(0l, -1, "", cr.getCourses().get(i).getOffering());
            Set<SctAssignment> sections = new HashSet<SctAssignment>();
            sections.add(new Section(0, 1, "x", new Subpart(0, "Lec", "Lec", cfg, null), p, null));
            Enrollment e = new Enrollment(cr, i, cfg, sections, assignment);
            w[i] = pw.getWeight(assignment, e, null, null);
        }
        System.out.println(cr + ": " + df.format(w[0]) + "  " + df.format(w[1]) + "  " + df.format(w[2]));
    }
    System.out.println("With one distance conflict:");
    for (Request r : s.getRequests()) {
        CourseRequest cr = (CourseRequest) r;
        double[] w = new double[] { 0.0, 0.0, 0.0 };
        for (int i = 0; i < cr.getCourses().size(); i++) {
            Config cfg = new Config(0l, -1, "", cr.getCourses().get(i).getOffering());
            Set<SctAssignment> sections = new HashSet<SctAssignment>();
            sections.add(new Section(0, 1, "x", new Subpart(0, "Lec", "Lec", cfg, null), p, null));
            Enrollment e = new Enrollment(cr, i, cfg, sections, assignment);
            Set<DistanceConflict.Conflict> dc = new HashSet<DistanceConflict.Conflict>();
            dc.add(new DistanceConflict.Conflict(s, e, (Section) sections.iterator().next(), e, (Section) sections.iterator().next()));
            w[i] = pw.getWeight(assignment, e, dc, null);
        }
        System.out.println(cr + ": " + df.format(w[0]) + "  " + df.format(w[1]) + "  " + df.format(w[2]));
    }
    System.out.println("With two distance conflicts:");
    for (Request r : s.getRequests()) {
        CourseRequest cr = (CourseRequest) r;
        double[] w = new double[] { 0.0, 0.0, 0.0 };
        for (int i = 0; i < cr.getCourses().size(); i++) {
            Config cfg = new Config(0l, -1, "", cr.getCourses().get(i).getOffering());
            Set<SctAssignment> sections = new HashSet<SctAssignment>();
            sections.add(new Section(0, 1, "x", new Subpart(0, "Lec", "Lec", cfg, null), p, null));
            Enrollment e = new Enrollment(cr, i, cfg, sections, assignment);
            Set<DistanceConflict.Conflict> dc = new HashSet<DistanceConflict.Conflict>();
            dc.add(new DistanceConflict.Conflict(s, e, (Section) sections.iterator().next(), e, (Section) sections.iterator().next()));
            dc.add(new DistanceConflict.Conflict(s, e, (Section) sections.iterator().next(), e, new Section(1, 1, "x", new Subpart(0, "Lec", "Lec", cfg, null), p, null)));
            w[i] = pw.getWeight(assignment, e, dc, null);
        }
        System.out.println(cr + ": " + df.format(w[0]) + "  " + df.format(w[1]) + "  " + df.format(w[2]));
    }
    System.out.println("With 25% time overlapping conflict:");
    for (Request r : s.getRequests()) {
        CourseRequest cr = (CourseRequest) r;
        double[] w = new double[] { 0.0, 0.0, 0.0 };
        for (int i = 0; i < cr.getCourses().size(); i++) {
            Config cfg = new Config(0l, -1, "", cr.getCourses().get(i).getOffering());
            Set<SctAssignment> sections = new HashSet<SctAssignment>();
            sections.add(new Section(0, 1, "x", new Subpart(0, "Lec", "Lec", cfg, null), p, null));
            Enrollment e = new Enrollment(cr, i, cfg, sections, assignment);
            Set<TimeOverlapsCounter.Conflict> toc = new HashSet<TimeOverlapsCounter.Conflict>();
            toc.add(new TimeOverlapsCounter.Conflict(s, 3, e, sections.iterator().next(), e, sections.iterator().next()));
            w[i] = pw.getWeight(assignment, e, null, toc);
        }
        System.out.println(cr + ": " + df.format(w[0]) + "  " + df.format(w[1]) + "  " + df.format(w[2]));
    }
    System.out.println("Disbalanced sections (by 2 / 10 students):");
    for (Request r : s.getRequests()) {
        CourseRequest cr = (CourseRequest) r;
        double[] w = new double[] { 0.0, 0.0, 0.0 };
        for (int i = 0; i < cr.getCourses().size(); i++) {
            Config cfg = new Config(0l, -1, "", cr.getCourses().get(i).getOffering());
            Set<SctAssignment> sections = new HashSet<SctAssignment>();
            Subpart x = new Subpart(0, "Lec", "Lec", cfg, null);
            Section a = new Section(0, 10, "x", x, p, null);
            new Section(1, 10, "y", x, p, null);
            sections.add(a);
            a.assigned(assignment, new Enrollment(s.getRequests().get(0), i, cfg, sections, assignment));
            a.assigned(assignment, new Enrollment(s.getRequests().get(0), i, cfg, sections, assignment));
            cfg.getContext(assignment).assigned(assignment, new Enrollment(s.getRequests().get(0), i, cfg, sections, assignment));
            cfg.getContext(assignment).assigned(assignment, new Enrollment(s.getRequests().get(0), i, cfg, sections, assignment));
            Enrollment e = new Enrollment(cr, i, cfg, sections, assignment);
            w[i] = pw.getWeight(assignment, e, null, null);
        }
        System.out.println(cr + ": " + df.format(w[0]) + "  " + df.format(w[1]) + "  " + df.format(w[2]));
    }
    System.out.println("Same choice sections:");
    pw.iMPP = true;
    for (Request r : s.getRequests()) {
        CourseRequest cr = (CourseRequest) r;
        double[] w = new double[] { 0.0, 0.0, 0.0 };
        for (int i = 0; i < cr.getCourses().size(); i++) {
            Config cfg = new Config(0l, -1, "", cr.getCourses().get(i).getOffering());
            Set<SctAssignment> sections = new HashSet<SctAssignment>();
            sections.add(new Section(0, 1, "x", new Subpart(0, "Lec", "Lec", cfg, null), p, null));
            Enrollment e = new Enrollment(cr, i, cfg, sections, assignment);
            Set<SctAssignment> other = new HashSet<SctAssignment>();
            other.add(new Section(1, 1, "x", new Subpart(0, "Lec", "Lec", cfg, null), p, null));
            cr.setInitialAssignment(new Enrollment(cr, i, cfg, other, assignment));
            w[i] = pw.getWeight(assignment, e, null, null);
        }
        System.out.println(cr + ": " + df.format(w[0]) + "  " + df.format(w[1]) + "  " + df.format(w[2]));
    }
    System.out.println("Same time sections:");
    for (Request r : s.getRequests()) {
        CourseRequest cr = (CourseRequest) r;
        double[] w = new double[] { 0.0, 0.0, 0.0 };
        for (int i = 0; i < cr.getCourses().size(); i++) {
            Config cfg = new Config(0l, -1, "", cr.getCourses().get(i).getOffering());
            Set<SctAssignment> sections = new HashSet<SctAssignment>();
            sections.add(new Section(0, 1, "x", new Subpart(0, "Lec", "Lec", cfg, null), p, null));
            Enrollment e = new Enrollment(cr, i, cfg, sections, assignment);
            Set<SctAssignment> other = new HashSet<SctAssignment>();
            other.add(new Section(1, 1, "x", new Subpart(0, "Lec", "Lec", cfg, null), p, null, new Instructor(1l, null, "Josef Novak", null)));
            cr.setInitialAssignment(new Enrollment(cr, i, cfg, other, assignment));
            w[i] = pw.getWeight(assignment, e, null, null);
        }
        System.out.println(cr + ": " + df.format(w[0]) + "  " + df.format(w[1]) + "  " + df.format(w[2]));
    }
    System.out.println("Different time sections:");
    Placement q = new Placement(null, new TimeLocation(1, 102, 12, 0, 0, null, null, new BitSet(), 10), new ArrayList<RoomLocation>());
    for (Request r : s.getRequests()) {
        CourseRequest cr = (CourseRequest) r;
        double[] w = new double[] { 0.0, 0.0, 0.0 };
        for (int i = 0; i < cr.getCourses().size(); i++) {
            Config cfg = new Config(0l, -1, "", cr.getCourses().get(i).getOffering());
            Set<SctAssignment> sections = new HashSet<SctAssignment>();
            sections.add(new Section(0, 1, "x", new Subpart(0, "Lec", "Lec", cfg, null), p, null));
            Enrollment e = new Enrollment(cr, i, cfg, sections, assignment);
            Set<SctAssignment> other = new HashSet<SctAssignment>();
            other.add(new Section(1, 1, "x", new Subpart(0, "Lec", "Lec", cfg, null), q, null));
            cr.setInitialAssignment(new Enrollment(cr, i, cfg, other, assignment));
            w[i] = pw.getWeight(assignment, e, null, null);
        }
        System.out.println(cr + ": " + df.format(w[0]) + "  " + df.format(w[1]) + "  " + df.format(w[2]));
    }
    System.out.println("Two sections, one same choice, one same time:");
    for (Request r : s.getRequests()) {
        CourseRequest cr = (CourseRequest) r;
        double[] w = new double[] { 0.0, 0.0, 0.0 };
        for (int i = 0; i < cr.getCourses().size(); i++) {
            Config cfg = new Config(0l, -1, "", cr.getCourses().get(i).getOffering());
            Set<SctAssignment> sections = new HashSet<SctAssignment>();
            sections.add(new Section(0, 1, "x", new Subpart(0, "Lec", "Lec", cfg, null), p, null));
            sections.add(new Section(1, 1, "y", new Subpart(1, "Rec", "Rec", cfg, null), p, null));
            Enrollment e = new Enrollment(cr, i, cfg, sections, assignment);
            Set<SctAssignment> other = new HashSet<SctAssignment>();
            other.add(new Section(2, 1, "x", new Subpart(0, "Lec", "Lec", cfg, null), p, null));
            other.add(new Section(3, 1, "y", new Subpart(1, "Rec", "Rec", cfg, null), p, null, new Instructor(1l, null, "Josef Novak", null)));
            cr.setInitialAssignment(new Enrollment(cr, i, cfg, other, assignment));
            w[i] = pw.getWeight(assignment, e, null, null);
        }
        System.out.println(cr + ": " + df.format(w[0]) + "  " + df.format(w[1]) + "  " + df.format(w[2]));
    }
}
Also used : TimeLocation(org.cpsolver.coursett.model.TimeLocation) Config(org.cpsolver.studentsct.model.Config) DecimalFormat(java.text.DecimalFormat) DistanceConflict(org.cpsolver.studentsct.extension.DistanceConflict) Instructor(org.cpsolver.studentsct.model.Instructor) DataProperties(org.cpsolver.ifs.util.DataProperties) Placement(org.cpsolver.coursett.model.Placement) Enrollment(org.cpsolver.studentsct.model.Enrollment) Course(org.cpsolver.studentsct.model.Course) HashSet(java.util.HashSet) RoomLocation(org.cpsolver.coursett.model.RoomLocation) Request(org.cpsolver.studentsct.model.Request) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) BitSet(java.util.BitSet) Student(org.cpsolver.studentsct.model.Student) Offering(org.cpsolver.studentsct.model.Offering) Section(org.cpsolver.studentsct.model.Section) TimeOverlapsCounter(org.cpsolver.studentsct.extension.TimeOverlapsCounter) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) DistanceConflict(org.cpsolver.studentsct.extension.DistanceConflict) Conflict(org.cpsolver.studentsct.extension.StudentQuality.Conflict) Subpart(org.cpsolver.studentsct.model.Subpart) DefaultSingleAssignment(org.cpsolver.ifs.assignment.DefaultSingleAssignment) SctAssignment(org.cpsolver.studentsct.model.SctAssignment)

Aggregations

Offering (org.cpsolver.studentsct.model.Offering)25 Section (org.cpsolver.studentsct.model.Section)18 Subpart (org.cpsolver.studentsct.model.Subpart)16 Course (org.cpsolver.studentsct.model.Course)15 Config (org.cpsolver.studentsct.model.Config)13 HashSet (java.util.HashSet)10 CourseRequest (org.cpsolver.studentsct.model.CourseRequest)10 Enrollment (org.cpsolver.studentsct.model.Enrollment)10 Request (org.cpsolver.studentsct.model.Request)10 HashMap (java.util.HashMap)8 Student (org.cpsolver.studentsct.model.Student)8 Element (org.dom4j.Element)8 ArrayList (java.util.ArrayList)7 TreeSet (java.util.TreeSet)6 DistanceConflict (org.cpsolver.studentsct.extension.DistanceConflict)5 TimeOverlapsCounter (org.cpsolver.studentsct.extension.TimeOverlapsCounter)5 DecimalFormat (java.text.DecimalFormat)4 Map (java.util.Map)4 Set (java.util.Set)4 Placement (org.cpsolver.coursett.model.Placement)4