Search in sources :

Example 1 with DummyReservation

use of org.cpsolver.studentsct.reservation.DummyReservation in project cpsolver by UniTime.

the class StudentSectioningXMLLoader method loadReservation.

/**
     * Load reservation
     * @param reservationEl reservation element
     * @param offering parent offering
     * @param configTable config table (of the offering)
     * @param sectionTable section table (of the offering)
     * @return loaded reservation
     */
protected Reservation loadReservation(Element reservationEl, Offering offering, HashMap<Long, Config> configTable, HashMap<Long, Section> sectionTable) {
    Reservation r = null;
    if ("individual".equals(reservationEl.attributeValue("type"))) {
        Set<Long> studentIds = new HashSet<Long>();
        for (Iterator<?> k = reservationEl.elementIterator("student"); k.hasNext(); ) {
            Element studentEl = (Element) k.next();
            studentIds.add(Long.parseLong(studentEl.attributeValue("id")));
        }
        r = new IndividualReservation(Long.valueOf(reservationEl.attributeValue("id")), offering, studentIds);
    } else if ("group".equals(reservationEl.attributeValue("type"))) {
        Set<Long> studentIds = new HashSet<Long>();
        for (Iterator<?> k = reservationEl.elementIterator("student"); k.hasNext(); ) {
            Element studentEl = (Element) k.next();
            studentIds.add(Long.parseLong(studentEl.attributeValue("id")));
        }
        r = new GroupReservation(Long.valueOf(reservationEl.attributeValue("id")), Double.parseDouble(reservationEl.attributeValue("limit", "-1")), offering, studentIds);
    } else if ("curriculum".equals(reservationEl.attributeValue("type"))) {
        List<String> classifications = new ArrayList<String>();
        for (Iterator<?> k = reservationEl.elementIterator("classification"); k.hasNext(); ) {
            Element clasfEl = (Element) k.next();
            classifications.add(clasfEl.attributeValue("code"));
        }
        List<String> majors = new ArrayList<String>();
        for (Iterator<?> k = reservationEl.elementIterator("major"); k.hasNext(); ) {
            Element majorEl = (Element) k.next();
            majors.add(majorEl.attributeValue("code"));
        }
        r = new CurriculumReservation(Long.valueOf(reservationEl.attributeValue("id")), Double.parseDouble(reservationEl.attributeValue("limit", "-1")), offering, reservationEl.attributeValue("area"), classifications, majors);
    } else if ("course".equals(reservationEl.attributeValue("type"))) {
        long courseId = Long.parseLong(reservationEl.attributeValue("course"));
        for (Course course : offering.getCourses()) {
            if (course.getId() == courseId)
                r = new CourseReservation(Long.valueOf(reservationEl.attributeValue("id")), course);
        }
    } else if ("dummy".equals(reservationEl.attributeValue("type"))) {
        r = new DummyReservation(offering);
    } else if ("override".equals(reservationEl.attributeValue("type"))) {
        Set<Long> studentIds = new HashSet<Long>();
        for (Iterator<?> k = reservationEl.elementIterator("student"); k.hasNext(); ) {
            Element studentEl = (Element) k.next();
            studentIds.add(Long.parseLong(studentEl.attributeValue("id")));
        }
        r = new ReservationOverride(Long.valueOf(reservationEl.attributeValue("id")), offering, studentIds);
    }
    if (r == null) {
        sLogger.error("Unknown reservation type " + reservationEl.attributeValue("type"));
        return null;
    }
    r.setExpired("true".equals(reservationEl.attributeValue("expired", "false")));
    for (Iterator<?> k = reservationEl.elementIterator("config"); k.hasNext(); ) {
        Element configEl = (Element) k.next();
        r.addConfig(configTable.get(Long.parseLong(configEl.attributeValue("id"))));
    }
    for (Iterator<?> k = reservationEl.elementIterator("section"); k.hasNext(); ) {
        Element sectionEl = (Element) k.next();
        r.addSection(sectionTable.get(Long.parseLong(sectionEl.attributeValue("id"))));
    }
    r.setPriority(Integer.parseInt(reservationEl.attributeValue("priority", String.valueOf(r.getPriority()))));
    r.setMustBeUsed("true".equals(reservationEl.attributeValue("mustBeUsed", r.mustBeUsed() ? "true" : "false")));
    r.setAllowOverlap("true".equals(reservationEl.attributeValue("allowOverlap", r.isAllowOverlap() ? "true" : "false")));
    r.setCanAssignOverLimit("true".equals(reservationEl.attributeValue("canAssignOverLimit", r.canAssignOverLimit() ? "true" : "false")));
    return r;
}
Also used : GroupReservation(org.cpsolver.studentsct.reservation.GroupReservation) CourseReservation(org.cpsolver.studentsct.reservation.CourseReservation) HashSet(java.util.HashSet) Set(java.util.Set) BitSet(java.util.BitSet) IndividualReservation(org.cpsolver.studentsct.reservation.IndividualReservation) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) DummyReservation(org.cpsolver.studentsct.reservation.DummyReservation) IndividualReservation(org.cpsolver.studentsct.reservation.IndividualReservation) GroupReservation(org.cpsolver.studentsct.reservation.GroupReservation) CourseReservation(org.cpsolver.studentsct.reservation.CourseReservation) Reservation(org.cpsolver.studentsct.reservation.Reservation) DummyReservation(org.cpsolver.studentsct.reservation.DummyReservation) CurriculumReservation(org.cpsolver.studentsct.reservation.CurriculumReservation) CurriculumReservation(org.cpsolver.studentsct.reservation.CurriculumReservation) ReservationOverride(org.cpsolver.studentsct.reservation.ReservationOverride) Iterator(java.util.Iterator) Course(org.cpsolver.studentsct.model.Course) HashSet(java.util.HashSet)

Example 2 with DummyReservation

use of org.cpsolver.studentsct.reservation.DummyReservation 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 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", "curriculum");
        CurriculumReservation cr = (CurriculumReservation) reservation;
        if (cr.getReservationLimit() >= 0.0)
            reservationEl.addAttribute("limit", String.valueOf(cr.getReservationLimit()));
        reservationEl.addAttribute("area", cr.getAcademicArea());
        for (String clasf : cr.getClassifications()) reservationEl.addElement("classification").addAttribute("code", clasf);
        for (String major : cr.getMajors()) reservationEl.addElement("major").addAttribute("code", major);
    } 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");
    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) TreeSet(java.util.TreeSet) Set(java.util.Set) BitSet(java.util.BitSet) IndividualReservation(org.cpsolver.studentsct.reservation.IndividualReservation) Config(org.cpsolver.studentsct.model.Config) Section(org.cpsolver.studentsct.model.Section) DummyReservation(org.cpsolver.studentsct.reservation.DummyReservation) CurriculumReservation(org.cpsolver.studentsct.reservation.CurriculumReservation) Subpart(org.cpsolver.studentsct.model.Subpart) ReservationOverride(org.cpsolver.studentsct.reservation.ReservationOverride) Map(java.util.Map)

Aggregations

BitSet (java.util.BitSet)2 Set (java.util.Set)2 CourseReservation (org.cpsolver.studentsct.reservation.CourseReservation)2 CurriculumReservation (org.cpsolver.studentsct.reservation.CurriculumReservation)2 DummyReservation (org.cpsolver.studentsct.reservation.DummyReservation)2 GroupReservation (org.cpsolver.studentsct.reservation.GroupReservation)2 IndividualReservation (org.cpsolver.studentsct.reservation.IndividualReservation)2 ReservationOverride (org.cpsolver.studentsct.reservation.ReservationOverride)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 TreeSet (java.util.TreeSet)1 Config (org.cpsolver.studentsct.model.Config)1 Course (org.cpsolver.studentsct.model.Course)1 Section (org.cpsolver.studentsct.model.Section)1 Subpart (org.cpsolver.studentsct.model.Subpart)1 Reservation (org.cpsolver.studentsct.reservation.Reservation)1 Element (org.dom4j.Element)1