Search in sources :

Example 1 with Config

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

the class SectionLimitCheck method check.

/**
 * Check for sections that have more students enrolled than it is allowed,
 * i.e., the sum of requests weights is above the section limit
 * @param assignment current assignment
 * @return false, if there is such a case
 */
public boolean check(Assignment<Request, Enrollment> assignment) {
    sLog.info("Checking section limits...");
    boolean ret = true;
    for (Offering offering : getModel().getOfferings()) {
        for (Config config : offering.getConfigs()) {
            for (Subpart subpart : config.getSubparts()) {
                for (Section section : subpart.getSections()) {
                    if (section.getLimit() < 0)
                        continue;
                    double used = section.getEnrollmentWeight(assignment, null);
                    if (used - section.getMaxEnrollmentWeight(assignment) > section.getLimit()) {
                        sLog.error("Section " + section.getName() + " exceeds its limit " + sDF.format(used) + ">" + section.getLimit() + " for more than one student (W:" + section.getMaxEnrollmentWeight(assignment) + ")");
                        ret = false;
                    } else if (Math.round(used) > section.getLimit()) {
                        sLog.debug("Section " + section.getName() + " exceeds its limit " + sDF.format(used) + ">" + section.getLimit() + " for less than one student (W:" + section.getMaxEnrollmentWeight(assignment) + ")");
                    }
                }
            }
        }
    }
    return ret;
}
Also used : Config(org.cpsolver.studentsct.model.Config) Subpart(org.cpsolver.studentsct.model.Subpart) Offering(org.cpsolver.studentsct.model.Offering) Section(org.cpsolver.studentsct.model.Section)

Example 2 with Config

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

the class StudentSectioningModel method clearOnlineSectioningInfos.

/**
 * Empty online student sectioning infos for all sections (see
 * {@link Section#getSpaceExpected()} and {@link Section#getSpaceHeld()}).
 */
public void clearOnlineSectioningInfos() {
    for (Offering offering : iOfferings) {
        for (Config config : offering.getConfigs()) {
            for (Subpart subpart : config.getSubparts()) {
                for (Section section : subpart.getSections()) {
                    section.setSpaceExpected(0);
                    section.setSpaceHeld(0);
                }
            }
        }
    }
}
Also used : Config(org.cpsolver.studentsct.model.Config) Subpart(org.cpsolver.studentsct.model.Subpart) Offering(org.cpsolver.studentsct.model.Offering) Section(org.cpsolver.studentsct.model.Section)

Example 3 with Config

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

the class StudentSectioningXMLLoader method loadOfferings.

/**
 * Load offerings
 * @param offeringsEl offerings element
 * @param offeringTable offering table
 * @param courseTable course table
 * @param timetable provided timetable (null if to be loaded from the given document)
 */
protected void loadOfferings(Element offeringsEl, Map<Long, Offering> offeringTable, Map<Long, Course> courseTable, Map<Long, Placement> timetable) {
    HashMap<Long, Config> configTable = new HashMap<Long, Config>();
    HashMap<Long, Subpart> subpartTable = new HashMap<Long, Subpart>();
    HashMap<Long, Section> sectionTable = new HashMap<Long, Section>();
    for (Iterator<?> i = offeringsEl.elementIterator("offering"); i.hasNext(); ) {
        Element offeringEl = (Element) i.next();
        Offering offering = new Offering(Long.parseLong(offeringEl.attributeValue("id")), offeringEl.attributeValue("name", "O" + offeringEl.attributeValue("id")));
        offeringTable.put(Long.valueOf(offering.getId()), offering);
        getModel().addOffering(offering);
        for (Iterator<?> j = offeringEl.elementIterator("course"); j.hasNext(); ) {
            Element courseEl = (Element) j.next();
            Course course = loadCourse(courseEl, offering);
            courseTable.put(Long.valueOf(course.getId()), course);
        }
        for (Iterator<?> j = offeringEl.elementIterator("config"); j.hasNext(); ) {
            Element configEl = (Element) j.next();
            Config config = loadConfig(configEl, offering, subpartTable, sectionTable, timetable);
            configTable.put(config.getId(), config);
        }
        for (Iterator<?> j = offeringEl.elementIterator("reservation"); j.hasNext(); ) {
            Element reservationEl = (Element) j.next();
            loadReservation(reservationEl, offering, configTable, sectionTable);
        }
        for (Iterator<?> j = offeringEl.elementIterator("restriction"); j.hasNext(); ) {
            Element restrictionEl = (Element) j.next();
            loadRestriction(restrictionEl, offering, configTable, sectionTable);
        }
    }
}
Also used : HashMap(java.util.HashMap) Config(org.cpsolver.studentsct.model.Config) Subpart(org.cpsolver.studentsct.model.Subpart) Element(org.dom4j.Element) Course(org.cpsolver.studentsct.model.Course) Section(org.cpsolver.studentsct.model.Section) Offering(org.cpsolver.studentsct.model.Offering)

Example 4 with Config

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

the class StudentSectioningXMLSaver method saveReservation.

/**
 * Save reservation
 * @param reservationEl reservation element to be populated
 * @param reservation reservation to be saved
 */
protected void saveReservation(Element reservationEl, Reservation reservation) {
    reservationEl.addAttribute("id", getId("reservation", reservation.getId()));
    reservationEl.addAttribute("expired", reservation.isExpired() ? "true" : "false");
    if (reservation instanceof LearningCommunityReservation) {
        LearningCommunityReservation lc = (LearningCommunityReservation) reservation;
        reservationEl.addAttribute("type", "lc");
        for (Long studentId : lc.getStudentIds()) reservationEl.addElement("student").addAttribute("id", getId("student", studentId));
        if (lc.getReservationLimit() >= 0.0)
            reservationEl.addAttribute("limit", String.valueOf(lc.getReservationLimit()));
        reservationEl.addAttribute("course", getId("course", lc.getCourse().getId()));
    } else if (reservation instanceof GroupReservation) {
        GroupReservation gr = (GroupReservation) reservation;
        reservationEl.addAttribute("type", "group");
        for (Long studentId : gr.getStudentIds()) reservationEl.addElement("student").addAttribute("id", getId("student", studentId));
        if (gr.getReservationLimit() >= 0.0)
            reservationEl.addAttribute("limit", String.valueOf(gr.getReservationLimit()));
    } else if (reservation instanceof ReservationOverride) {
        reservationEl.addAttribute("type", "override");
        ReservationOverride o = (ReservationOverride) reservation;
        for (Long studentId : o.getStudentIds()) reservationEl.addElement("student").addAttribute("id", getId("student", studentId));
    } else if (reservation instanceof IndividualReservation) {
        reservationEl.addAttribute("type", "individual");
        for (Long studentId : ((IndividualReservation) reservation).getStudentIds()) reservationEl.addElement("student").addAttribute("id", getId("student", studentId));
    } else if (reservation instanceof CurriculumReservation) {
        reservationEl.addAttribute("type", (reservation instanceof CurriculumOverride ? "curriculum-override" : "curriculum"));
        CurriculumReservation cr = (CurriculumReservation) reservation;
        if (cr.getReservationLimit() >= 0.0)
            reservationEl.addAttribute("limit", String.valueOf(cr.getReservationLimit()));
        if (cr.getAcademicAreas().size() == 1)
            reservationEl.addAttribute("area", cr.getAcademicAreas().iterator().next());
        else {
            for (String area : cr.getAcademicAreas()) reservationEl.addElement("area").addAttribute("code", area);
        }
        for (String clasf : cr.getClassifications()) reservationEl.addElement("classification").addAttribute("code", clasf);
        for (String major : cr.getMajors()) {
            Element majorEl = reservationEl.addElement("major").addAttribute("code", major);
            Set<String> concentrations = cr.getConcentrations(major);
            if (concentrations != null)
                for (String conc : concentrations) majorEl.addElement("concentration").addAttribute("code", conc);
        }
        for (String minor : cr.getMinors()) reservationEl.addElement("minor").addAttribute("code", minor);
    } else if (reservation instanceof CourseReservation) {
        reservationEl.addAttribute("type", "course");
        CourseReservation cr = (CourseReservation) reservation;
        reservationEl.addAttribute("course", getId("course", cr.getCourse().getId()));
    } else if (reservation instanceof DummyReservation) {
        reservationEl.addAttribute("type", "dummy");
    }
    reservationEl.addAttribute("priority", String.valueOf(reservation.getPriority()));
    reservationEl.addAttribute("mustBeUsed", reservation.mustBeUsed() ? "true" : "false");
    reservationEl.addAttribute("allowOverlap", reservation.isAllowOverlap() ? "true" : "false");
    reservationEl.addAttribute("canAssignOverLimit", reservation.canAssignOverLimit() ? "true" : "false");
    reservationEl.addAttribute("allowDisabled", reservation.isAllowDisabled() ? "true" : "false");
    if (reservation.neverIncluded())
        reservationEl.addAttribute("neverIncluded", "true");
    if (reservation.canBreakLinkedSections())
        reservationEl.addAttribute("breakLinkedSections", "true");
    for (Config config : reservation.getConfigs()) reservationEl.addElement("config").addAttribute("id", getId("config", config.getId()));
    for (Map.Entry<Subpart, Set<Section>> entry : reservation.getSections().entrySet()) {
        for (Section section : entry.getValue()) {
            reservationEl.addElement("section").addAttribute("id", getId("section", section.getId()));
        }
    }
}
Also used : GroupReservation(org.cpsolver.studentsct.reservation.GroupReservation) CourseReservation(org.cpsolver.studentsct.reservation.CourseReservation) Set(java.util.Set) TreeSet(java.util.TreeSet) BitSet(java.util.BitSet) IndividualReservation(org.cpsolver.studentsct.reservation.IndividualReservation) Config(org.cpsolver.studentsct.model.Config) Element(org.dom4j.Element) CurriculumOverride(org.cpsolver.studentsct.reservation.CurriculumOverride) Section(org.cpsolver.studentsct.model.Section) DummyReservation(org.cpsolver.studentsct.reservation.DummyReservation) LearningCommunityReservation(org.cpsolver.studentsct.reservation.LearningCommunityReservation) CurriculumReservation(org.cpsolver.studentsct.reservation.CurriculumReservation) Subpart(org.cpsolver.studentsct.model.Subpart) ReservationOverride(org.cpsolver.studentsct.reservation.ReservationOverride) Map(java.util.Map)

Example 5 with Config

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

the class StudentSectioningXMLSaver method saveOffering.

/**
 * Save given offering
 * @param offeringEl offering element to be populated
 * @param offering offering to be saved
 */
protected void saveOffering(Element offeringEl, Offering offering) {
    offeringEl.addAttribute("id", getId("offering", offering.getId()));
    if (iShowNames)
        offeringEl.addAttribute("name", offering.getName());
    for (Course course : offering.getCourses()) {
        Element courseEl = offeringEl.addElement("course");
        saveCourse(courseEl, course);
    }
    for (Config config : offering.getConfigs()) {
        Element configEl = offeringEl.addElement("config");
        saveConfig(configEl, config);
    }
}
Also used : Config(org.cpsolver.studentsct.model.Config) Element(org.dom4j.Element) Course(org.cpsolver.studentsct.model.Course)

Aggregations

Config (org.cpsolver.studentsct.model.Config)33 Section (org.cpsolver.studentsct.model.Section)26 Subpart (org.cpsolver.studentsct.model.Subpart)23 Course (org.cpsolver.studentsct.model.Course)14 CourseRequest (org.cpsolver.studentsct.model.CourseRequest)13 Offering (org.cpsolver.studentsct.model.Offering)13 Enrollment (org.cpsolver.studentsct.model.Enrollment)11 Request (org.cpsolver.studentsct.model.Request)10 HashSet (java.util.HashSet)9 Set (java.util.Set)8 TreeSet (java.util.TreeSet)7 Reservation (org.cpsolver.studentsct.reservation.Reservation)7 Map (java.util.Map)6 Student (org.cpsolver.studentsct.model.Student)6 BitSet (java.util.BitSet)5 DistanceConflict (org.cpsolver.studentsct.extension.DistanceConflict)5 TimeOverlapsCounter (org.cpsolver.studentsct.extension.TimeOverlapsCounter)5 Element (org.dom4j.Element)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4