Search in sources :

Example 51 with Section

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

the class StudentSectioningXMLLoader method loadSection.

/**
     * Load section
     * @param sectionEl section element
     * @param subpart parent subpart
     * @param sectionTable section table (of the offering)
     * @param timetable provided timetable
     * @return loaded section
     */
@SuppressWarnings("deprecation")
protected Section loadSection(Element sectionEl, Subpart subpart, Map<Long, Section> sectionTable, Map<Long, Placement> timetable) {
    Section parentSection = null;
    if (sectionEl.attributeValue("parent") != null)
        parentSection = sectionTable.get(Long.valueOf(sectionEl.attributeValue("parent")));
    Placement placement = null;
    if (timetable != null) {
        placement = timetable.get(Long.parseLong(sectionEl.attributeValue("id")));
    } else {
        TimeLocation time = null;
        Element timeEl = sectionEl.element("time");
        if (timeEl != null) {
            time = new TimeLocation(Integer.parseInt(timeEl.attributeValue("days"), 2), Integer.parseInt(timeEl.attributeValue("start")), Integer.parseInt(timeEl.attributeValue("length")), 0, 0, timeEl.attributeValue("datePattern") == null ? null : Long.valueOf(timeEl.attributeValue("datePattern")), timeEl.attributeValue("datePatternName", ""), createBitSet(timeEl.attributeValue("dates")), Integer.parseInt(timeEl.attributeValue("breakTime", "0")));
            if (timeEl.attributeValue("pattern") != null)
                time.setTimePatternId(Long.valueOf(timeEl.attributeValue("pattern")));
        }
        List<RoomLocation> rooms = new ArrayList<RoomLocation>();
        for (Iterator<?> m = sectionEl.elementIterator("room"); m.hasNext(); ) {
            Element roomEl = (Element) m.next();
            Double posX = null, posY = null;
            if (roomEl.attributeValue("location") != null) {
                String loc = roomEl.attributeValue("location");
                posX = Double.valueOf(loc.substring(0, loc.indexOf(',')));
                posY = Double.valueOf(loc.substring(loc.indexOf(',') + 1));
            }
            RoomLocation room = new RoomLocation(Long.valueOf(roomEl.attributeValue("id")), roomEl.attributeValue("name", "R" + roomEl.attributeValue("id")), roomEl.attributeValue("building") == null ? null : Long.valueOf(roomEl.attributeValue("building")), 0, Integer.parseInt(roomEl.attributeValue("capacity")), posX, posY, "true".equals(roomEl.attributeValue("ignoreTooFar")), null);
            rooms.add(room);
        }
        placement = (time == null ? null : new Placement(null, time, rooms));
    }
    List<Instructor> instructors = new ArrayList<Instructor>();
    for (Iterator<?> m = sectionEl.elementIterator("instructor"); m.hasNext(); ) {
        Element instructorEl = (Element) m.next();
        instructors.add(new Instructor(Long.parseLong(instructorEl.attributeValue("id")), instructorEl.attributeValue("externalId"), instructorEl.attributeValue("name"), instructorEl.attributeValue("email")));
    }
    if (instructors.isEmpty() && sectionEl.attributeValue("instructorIds") != null)
        instructors = Instructor.toInstructors(sectionEl.attributeValue("instructorIds"), sectionEl.attributeValue("instructorNames"));
    Section section = new Section(Long.parseLong(sectionEl.attributeValue("id")), Integer.parseInt(sectionEl.attributeValue("limit")), sectionEl.attributeValue("name", "S" + sectionEl.attributeValue("id")), subpart, placement, instructors, parentSection);
    section.setSpaceHeld(Double.parseDouble(sectionEl.attributeValue("hold", "0.0")));
    section.setSpaceExpected(Double.parseDouble(sectionEl.attributeValue("expect", "0.0")));
    section.setCancelled("true".equalsIgnoreCase(sectionEl.attributeValue("cancelled", "false")));
    for (Iterator<?> m = sectionEl.elementIterator("cname"); m.hasNext(); ) {
        Element cNameEl = (Element) m.next();
        section.setName(Long.parseLong(cNameEl.attributeValue("id")), cNameEl.getText());
    }
    Element ignoreEl = sectionEl.element("no-conflicts");
    if (ignoreEl != null) {
        for (Iterator<?> m = ignoreEl.elementIterator("section"); m.hasNext(); ) section.addIgnoreConflictWith(Long.parseLong(((Element) m.next()).attributeValue("id")));
    }
    return section;
}
Also used : TimeLocation(org.cpsolver.coursett.model.TimeLocation) Placement(org.cpsolver.coursett.model.Placement) RoomLocation(org.cpsolver.coursett.model.RoomLocation) Element(org.dom4j.Element) Instructor(org.cpsolver.studentsct.model.Instructor) ArrayList(java.util.ArrayList) Section(org.cpsolver.studentsct.model.Section)

Example 52 with Section

use of org.cpsolver.studentsct.model.Section 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")));
    student.setExternalId(studentEl.attributeValue("externalId"));
    student.setName(studentEl.attributeValue("name"));
    student.setStatus(studentEl.attributeValue("status"));
    for (Iterator<?> j = studentEl.elementIterator(); j.hasNext(); ) {
        Element requestEl = (Element) j.next();
        if ("classification".equals(requestEl.getName())) {
            student.getAcademicAreaClasiffications().add(new AcademicAreaCode(requestEl.attributeValue("area"), requestEl.attributeValue("code")));
        } else if ("major".equals(requestEl.getName())) {
            student.getMajors().add(new AcademicAreaCode(requestEl.attributeValue("area"), requestEl.attributeValue("code")));
        } else if ("minor".equals(requestEl.getName())) {
            student.getMinors().add(new AcademicAreaCode(requestEl.attributeValue("area"), requestEl.attributeValue("code")));
        } 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())) {
            student.getAreaClassificationMajors().add(new AreaClassificationMajor(requestEl.attributeValue("area"), requestEl.attributeValue("classification"), requestEl.attributeValue("major")));
        }
    }
    return student;
}
Also used : AreaClassificationMajor(org.cpsolver.studentsct.model.AreaClassificationMajor) Unavailability(org.cpsolver.studentsct.model.Unavailability) Element(org.dom4j.Element) AcademicAreaCode(org.cpsolver.studentsct.model.AcademicAreaCode) Student(org.cpsolver.studentsct.model.Student) Offering(org.cpsolver.studentsct.model.Offering) Section(org.cpsolver.studentsct.model.Section)

Example 53 with Section

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

the class StudentSectioningXMLLoader method loadEnrollment.

/**
     * Load enrollment
     * @param enrollmentEl enrollment element (current, best, or initial)
     * @param request parent request
     * @return loaded enrollment
     */
protected Enrollment loadEnrollment(Element enrollmentEl, Request request) {
    if (request instanceof CourseRequest) {
        CourseRequest courseRequest = (CourseRequest) request;
        HashSet<Section> sections = new HashSet<Section>();
        for (Iterator<?> k = enrollmentEl.elementIterator("section"); k.hasNext(); ) {
            Element sectionEl = (Element) k.next();
            Section section = courseRequest.getSection(Long.parseLong(sectionEl.attributeValue("id")));
            sections.add(section);
        }
        Reservation reservation = null;
        if (enrollmentEl.attributeValue("reservation", null) != null) {
            long reservationId = Long.valueOf(enrollmentEl.attributeValue("reservation"));
            for (Course course : courseRequest.getCourses()) for (Reservation r : course.getOffering().getReservations()) if (r.getId() == reservationId) {
                reservation = r;
                break;
            }
        }
        if (!sections.isEmpty())
            return courseRequest.createEnrollment(sections, reservation);
    } else if (request instanceof FreeTimeRequest) {
        return ((FreeTimeRequest) request).createEnrollment();
    }
    return null;
}
Also used : FreeTimeRequest(org.cpsolver.studentsct.model.FreeTimeRequest) 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) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Element(org.dom4j.Element) Course(org.cpsolver.studentsct.model.Course) Section(org.cpsolver.studentsct.model.Section) HashSet(java.util.HashSet)

Example 54 with Section

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

the class LinkedSections method createConstraint.

/**
     * Create linked-section constraints for a given student
     */
private LinkedSectionsConstraint createConstraint(Student student) {
    List<Request> requests = new ArrayList<Request>();
    int nrOfferings = 0;
    requests: for (Request request : student.getRequests()) {
        if (request instanceof CourseRequest) {
            for (Course course : ((CourseRequest) request).getCourses()) {
                Map<Subpart, Set<Section>> subpartsThisOffering = iSections.get(course.getOffering());
                if (subpartsThisOffering != null) {
                    requests.add(request);
                    nrOfferings++;
                    continue requests;
                }
            }
        }
    }
    if (nrOfferings <= 1)
        return null;
    LinkedSectionsConstraint constraint = new LinkedSectionsConstraint(student, requests);
    student.getRequests().get(0).getModel().addConstraint(constraint);
    return constraint;
}
Also used : CourseRequest(org.cpsolver.studentsct.model.CourseRequest) ArrayList(java.util.ArrayList) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Request(org.cpsolver.studentsct.model.Request) Course(org.cpsolver.studentsct.model.Course) HashMap(java.util.HashMap) Map(java.util.Map) Section(org.cpsolver.studentsct.model.Section) Constraint(org.cpsolver.ifs.model.Constraint)

Example 55 with Section

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

the class StudentPreferencePenalties method setPenalties.

/**
     * Set the computed penalties to all sections of all requests of the given
     * student
     * @param student given student
     * @param distributionType penalty distribution type
     */
public static void setPenalties(Student student, int distributionType) {
    if (sDebug)
        sLog.debug("Setting penalties for " + student);
    StudentPreferencePenalties penalties = new StudentPreferencePenalties(distributionType);
    for (Request request : student.getRequests()) {
        if (!(request instanceof CourseRequest))
            continue;
        CourseRequest courseRequest = (CourseRequest) request;
        if (sDebug)
            sLog.debug("-- " + courseRequest);
        for (Course course : courseRequest.getCourses()) {
            if (sDebug)
                sLog.debug("  -- " + course.getName());
            for (Config config : course.getOffering().getConfigs()) {
                if (sDebug)
                    sLog.debug("    -- " + config.getName());
                for (Subpart subpart : config.getSubparts()) {
                    if (sDebug)
                        sLog.debug("      -- " + subpart.getName());
                    for (Section section : subpart.getSections()) {
                        section.setPenalty(penalties.getPenalty(section));
                        if (sDebug)
                            sLog.debug("        -- " + section);
                    }
                }
            }
        }
        courseRequest.clearCache();
    }
}
Also used : CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Config(org.cpsolver.studentsct.model.Config) Subpart(org.cpsolver.studentsct.model.Subpart) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) FreeTimeRequest(org.cpsolver.studentsct.model.FreeTimeRequest) Request(org.cpsolver.studentsct.model.Request) Course(org.cpsolver.studentsct.model.Course) Section(org.cpsolver.studentsct.model.Section)

Aggregations

Section (org.cpsolver.studentsct.model.Section)59 Subpart (org.cpsolver.studentsct.model.Subpart)34 CourseRequest (org.cpsolver.studentsct.model.CourseRequest)32 Config (org.cpsolver.studentsct.model.Config)23 Request (org.cpsolver.studentsct.model.Request)22 Course (org.cpsolver.studentsct.model.Course)19 Enrollment (org.cpsolver.studentsct.model.Enrollment)19 Offering (org.cpsolver.studentsct.model.Offering)17 HashSet (java.util.HashSet)14 FreeTimeRequest (org.cpsolver.studentsct.model.FreeTimeRequest)14 ArrayList (java.util.ArrayList)13 Set (java.util.Set)11 TreeSet (java.util.TreeSet)10 HashMap (java.util.HashMap)9 Map (java.util.Map)9 Element (org.dom4j.Element)9 Student (org.cpsolver.studentsct.model.Student)7 CSVFile (org.cpsolver.ifs.util.CSVFile)6 DistanceConflict (org.cpsolver.studentsct.extension.DistanceConflict)6 RoomLocation (org.cpsolver.coursett.model.RoomLocation)5