Search in sources :

Example 6 with Offering

use of org.cpsolver.studentsct.model.Offering 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 7 with Offering

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

the class StudentSectioningXMLLoader method loadLinkedSections.

/**
 * Load linked sections
 * @param constraintsEl constraints element
 * @param offeringTable offering table
 */
protected void loadLinkedSections(Element constraintsEl, Map<Long, Offering> offeringTable) {
    for (Iterator<?> i = constraintsEl.elementIterator("linked-sections"); i.hasNext(); ) {
        Element linkedEl = (Element) i.next();
        List<Section> sections = new ArrayList<Section>();
        for (Iterator<?> j = linkedEl.elementIterator("section"); j.hasNext(); ) {
            Element sectionEl = (Element) j.next();
            Offering offering = offeringTable.get(Long.valueOf(sectionEl.attributeValue("offering")));
            sections.add(offering.getSection(Long.valueOf(sectionEl.attributeValue("id"))));
        }
        getModel().addLinkedSections("true".equals(linkedEl.attributeValue("mustBeUsed", "false")), sections);
    }
}
Also used : Element(org.dom4j.Element) ArrayList(java.util.ArrayList) Section(org.cpsolver.studentsct.model.Section) Offering(org.cpsolver.studentsct.model.Offering)

Example 8 with Offering

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

the class StudentSectioningXMLLoader method load.

public void load(Document document) {
    Element root = document.getRootElement();
    if (getModel() != null && root.element("travel-times") != null)
        loadTravelTimes(root.element("travel-times"), getModel().getDistanceMetric());
    Progress.getInstance(getModel()).load(root, true);
    Progress.getInstance(getModel()).message(Progress.MSGLEVEL_STAGE, "Restoring from backup ...");
    Map<Long, Offering> offeringTable = new HashMap<Long, Offering>();
    Map<Long, Course> courseTable = new HashMap<Long, Course>();
    if (root.element("offerings") != null) {
        loadOfferings(root.element("offerings"), offeringTable, courseTable, null);
    }
    List<Enrollment> bestEnrollments = new ArrayList<Enrollment>();
    List<Enrollment> currentEnrollments = new ArrayList<Enrollment>();
    if (root.element("students") != null) {
        loadStudents(root.element("students"), offeringTable, courseTable, bestEnrollments, currentEnrollments);
    }
    if (root.element("constraints") != null)
        loadLinkedSections(root.element("constraints"), offeringTable);
    if (!bestEnrollments.isEmpty())
        assignBest(bestEnrollments);
    if (!currentEnrollments.isEmpty())
        assignCurrent(currentEnrollments);
    if (iMoveCriticalUp)
        moveCriticalRequestsUp();
    boolean hasFixed = false;
    for (Request r : getModel().variables()) {
        if (r instanceof CourseRequest && ((CourseRequest) r).isFixed()) {
            hasFixed = true;
            break;
        }
    }
    if (hasFixed)
        getModel().addGlobalConstraint(new FixedAssignments());
}
Also used : HashMap(java.util.HashMap) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) Request(org.cpsolver.studentsct.model.Request) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) FreeTimeRequest(org.cpsolver.studentsct.model.FreeTimeRequest) Offering(org.cpsolver.studentsct.model.Offering) FixedAssignments(org.cpsolver.studentsct.constraint.FixedAssignments) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Enrollment(org.cpsolver.studentsct.model.Enrollment) Course(org.cpsolver.studentsct.model.Course)

Example 9 with Offering

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

the class StudentSectioningXMLSaver method saveOfferings.

/**
 * Save offerings
 * @param root document root
 */
protected void saveOfferings(Element root) {
    Element offeringsEl = root.addElement("offerings");
    for (Offering offering : getModel().getOfferings()) {
        Element offeringEl = offeringsEl.addElement("offering");
        saveOffering(offeringEl, offering);
        saveReservations(offeringEl, offering);
        saveRestrictions(offeringEl, offering);
    }
}
Also used : Element(org.dom4j.Element) Offering(org.cpsolver.studentsct.model.Offering)

Example 10 with Offering

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

the class StudentSectioningXMLSaver method saveLinkedSections.

/**
 * Save linked sections
 * @param root document root
 */
protected void saveLinkedSections(Element root) {
    Element constrainstEl = root.addElement("constraints");
    for (LinkedSections linkedSections : getModel().getLinkedSections()) {
        Element linkEl = constrainstEl.addElement("linked-sections");
        linkEl.addAttribute("mustBeUsed", linkedSections.isMustBeUsed() ? "true" : "false");
        for (Offering offering : linkedSections.getOfferings()) for (Subpart subpart : linkedSections.getSubparts(offering)) for (Section section : linkedSections.getSections(subpart)) linkEl.addElement("section").addAttribute("offering", getId("offering", offering.getId())).addAttribute("id", getId("section", section.getId()));
    }
}
Also used : LinkedSections(org.cpsolver.studentsct.constraint.LinkedSections) Subpart(org.cpsolver.studentsct.model.Subpart) Element(org.dom4j.Element) Offering(org.cpsolver.studentsct.model.Offering) Section(org.cpsolver.studentsct.model.Section)

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