Search in sources :

Example 21 with TimeLocation

use of org.cpsolver.coursett.model.TimeLocation 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 22 with TimeLocation

use of org.cpsolver.coursett.model.TimeLocation in project cpsolver by UniTime.

the class StudentSectioningXMLLoader method loadFreeTime.

/**
     * Load free time request
     * @param requestEl request element
     * @param student parent student
     * @return loaded free time request
     */
public FreeTimeRequest loadFreeTime(Element requestEl, Student student) {
    TimeLocation time = new TimeLocation(Integer.parseInt(requestEl.attributeValue("days"), 2), Integer.parseInt(requestEl.attributeValue("start")), Integer.parseInt(requestEl.attributeValue("length")), 0, 0, requestEl.attributeValue("datePattern") == null ? null : Long.valueOf(requestEl.attributeValue("datePattern")), "", createBitSet(requestEl.attributeValue("dates")), 0);
    FreeTimeRequest request = new FreeTimeRequest(Long.parseLong(requestEl.attributeValue("id")), Integer.parseInt(requestEl.attributeValue("priority")), "true".equals(requestEl.attributeValue("alternative")), student, time);
    if (requestEl.attributeValue("weight") != null)
        request.setWeight(Double.parseDouble(requestEl.attributeValue("weight")));
    return request;
}
Also used : FreeTimeRequest(org.cpsolver.studentsct.model.FreeTimeRequest) TimeLocation(org.cpsolver.coursett.model.TimeLocation)

Example 23 with TimeLocation

use of org.cpsolver.coursett.model.TimeLocation in project cpsolver by UniTime.

the class StudentSectioningXMLLoader method loadTimetable.

/**
     * Load given timetable
     * @param timetableRoot document root in the course timetabling XML format
     * @return loaded timetable (map class id: assigned placement)
     */
protected Map<Long, Placement> loadTimetable(Element timetableRoot) {
    Map<Long, Placement> timetable = new HashMap<Long, Placement>();
    HashMap<Long, RoomLocation> rooms = new HashMap<Long, RoomLocation>();
    for (Iterator<?> i = timetableRoot.element("rooms").elementIterator("room"); i.hasNext(); ) {
        Element roomEl = (Element) i.next();
        Long roomId = Long.valueOf(roomEl.attributeValue("id"));
        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.put(roomId, room);
    }
    for (Iterator<?> i = timetableRoot.element("classes").elementIterator("class"); i.hasNext(); ) {
        Element classEl = (Element) i.next();
        Long classId = Long.valueOf(classEl.attributeValue("id"));
        TimeLocation time = null;
        Element timeEl = null;
        for (Iterator<?> j = classEl.elementIterator("time"); j.hasNext(); ) {
            Element e = (Element) j.next();
            if ("true".equals(e.attributeValue("solution", "false"))) {
                timeEl = e;
                break;
            }
        }
        if (timeEl != null) {
            time = new TimeLocation(Integer.parseInt(timeEl.attributeValue("days"), 2), Integer.parseInt(timeEl.attributeValue("start")), Integer.parseInt(timeEl.attributeValue("length")), 0, 0, classEl.attributeValue("datePattern") == null ? null : Long.valueOf(classEl.attributeValue("datePattern")), classEl.attributeValue("datePatternName", ""), createBitSet(classEl.attributeValue("dates")), Integer.parseInt(timeEl.attributeValue("breakTime", "0")));
            if (timeEl.attributeValue("pattern") != null)
                time.setTimePatternId(Long.valueOf(timeEl.attributeValue("pattern")));
        }
        List<RoomLocation> room = new ArrayList<RoomLocation>();
        for (Iterator<?> j = classEl.elementIterator("room"); j.hasNext(); ) {
            Element roomEl = (Element) j.next();
            if (!"true".equals(roomEl.attributeValue("solution", "false")))
                continue;
            room.add(rooms.get(Long.valueOf(roomEl.attributeValue("id"))));
        }
        Placement placement = (time == null ? null : new Placement(null, time, room));
        if (placement != null)
            timetable.put(classId, placement);
    }
    return timetable;
}
Also used : TimeLocation(org.cpsolver.coursett.model.TimeLocation) HashMap(java.util.HashMap) RoomLocation(org.cpsolver.coursett.model.RoomLocation) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) Placement(org.cpsolver.coursett.model.Placement)

Example 24 with TimeLocation

use of org.cpsolver.coursett.model.TimeLocation in project cpsolver by UniTime.

the class OverlapCheck method check.

/**
     * Check for overlapping sections that are attended by the same student
     * @param a current assignment
     * @return false, if there is such a case
     */
public boolean check(Assignment<Request, Enrollment> a) {
    sLog.info("Checking for overlaps...");
    boolean ret = true;
    for (Student student : getModel().getStudents()) {
        HashMap<TimeLocation, SctAssignment> times = new HashMap<TimeLocation, SctAssignment>();
        for (Request request : student.getRequests()) {
            Enrollment enrollment = a.getValue(request);
            if (enrollment == null)
                continue;
            for (SctAssignment assignment : enrollment.getAssignments()) {
                if (assignment.getTime() == null)
                    continue;
                for (TimeLocation time : times.keySet()) {
                    if (time.hasIntersection(assignment.getTime())) {
                        sLog.error("Student " + student + " assignment " + assignment + " overlaps with " + times.get(time));
                        ret = false;
                    }
                }
                times.put(assignment.getTime(), assignment);
            }
        }
    }
    return ret;
}
Also used : TimeLocation(org.cpsolver.coursett.model.TimeLocation) HashMap(java.util.HashMap) Request(org.cpsolver.studentsct.model.Request) Enrollment(org.cpsolver.studentsct.model.Enrollment) Student(org.cpsolver.studentsct.model.Student) SctAssignment(org.cpsolver.studentsct.model.SctAssignment)

Example 25 with TimeLocation

use of org.cpsolver.coursett.model.TimeLocation in project cpsolver by UniTime.

the class StudentSectioningXMLSaver method saveSection.

/**
     * Save section
     * @param sectionEl section element to be populated
     * @param section section to be saved
     */
protected void saveSection(Element sectionEl, Section section) {
    sectionEl.addAttribute("id", getId("section", section.getId()));
    sectionEl.addAttribute("limit", String.valueOf(section.getLimit()));
    if (section.isCancelled())
        sectionEl.addAttribute("cancelled", "true");
    if (section.getNameByCourse() != null)
        for (Map.Entry<Long, String> entry : section.getNameByCourse().entrySet()) sectionEl.addElement("cname").addAttribute("id", entry.getKey().toString()).setText(entry.getValue());
    if (section.getParent() != null)
        sectionEl.addAttribute("parent", getId("section", section.getParent().getId()));
    if (section.hasInstructors()) {
        for (Instructor instructor : section.getInstructors()) {
            Element instructorEl = sectionEl.addElement("instructor");
            instructorEl.addAttribute("id", getId("instructor", instructor.getId()));
            if (iShowNames && instructor.getName() != null)
                instructorEl.addAttribute("name", instructor.getName());
            if (iShowNames && instructor.getExternalId() != null)
                instructorEl.addAttribute("externalId", instructor.getExternalId());
            if (iShowNames && instructor.getEmail() != null)
                instructorEl.addAttribute("email", instructor.getExternalId());
        }
    }
    if (iShowNames)
        sectionEl.addAttribute("name", section.getName());
    if (section.getPlacement() != null) {
        TimeLocation tl = section.getPlacement().getTimeLocation();
        if (tl != null) {
            Element timeLocationEl = sectionEl.addElement("time");
            timeLocationEl.addAttribute("days", sDF[7].format(Long.parseLong(Integer.toBinaryString(tl.getDayCode()))));
            timeLocationEl.addAttribute("start", String.valueOf(tl.getStartSlot()));
            timeLocationEl.addAttribute("length", String.valueOf(tl.getLength()));
            if (tl.getBreakTime() != 0)
                timeLocationEl.addAttribute("breakTime", String.valueOf(tl.getBreakTime()));
            if (iShowNames && tl.getTimePatternId() != null)
                timeLocationEl.addAttribute("pattern", getId("timePattern", tl.getTimePatternId()));
            if (iShowNames && tl.getDatePatternId() != null)
                timeLocationEl.addAttribute("datePattern", tl.getDatePatternId().toString());
            if (iShowNames && tl.getDatePatternName() != null && tl.getDatePatternName().length() > 0)
                timeLocationEl.addAttribute("datePatternName", tl.getDatePatternName());
            timeLocationEl.addAttribute("dates", bitset2string(tl.getWeekCode()));
            if (iShowNames)
                timeLocationEl.setText(tl.getLongName(true));
        }
        for (RoomLocation rl : section.getRooms()) {
            Element roomLocationEl = sectionEl.addElement("room");
            roomLocationEl.addAttribute("id", getId("room", rl.getId()));
            if (iShowNames && rl.getBuildingId() != null)
                roomLocationEl.addAttribute("building", getId("building", rl.getBuildingId()));
            if (iShowNames && rl.getName() != null)
                roomLocationEl.addAttribute("name", rl.getName());
            roomLocationEl.addAttribute("capacity", String.valueOf(rl.getRoomSize()));
            if (rl.getPosX() != null && rl.getPosY() != null)
                roomLocationEl.addAttribute("location", rl.getPosX() + "," + rl.getPosY());
            if (rl.getIgnoreTooFar())
                roomLocationEl.addAttribute("ignoreTooFar", "true");
        }
    }
    if (iSaveOnlineSectioningInfo) {
        if (section.getSpaceHeld() != 0.0)
            sectionEl.addAttribute("hold", sStudentWeightFormat.format(section.getSpaceHeld()));
        if (section.getSpaceExpected() != 0.0)
            sectionEl.addAttribute("expect", sStudentWeightFormat.format(section.getSpaceExpected()));
    }
    if (section.getIgnoreConflictWithSectionIds() != null && !section.getIgnoreConflictWithSectionIds().isEmpty()) {
        Element ignoreEl = sectionEl.addElement("no-conflicts");
        for (Long sectionId : section.getIgnoreConflictWithSectionIds()) ignoreEl.addElement("section").addAttribute("id", getId("section", sectionId));
    }
}
Also used : TimeLocation(org.cpsolver.coursett.model.TimeLocation) RoomLocation(org.cpsolver.coursett.model.RoomLocation) Instructor(org.cpsolver.studentsct.model.Instructor) Element(org.dom4j.Element)

Aggregations

TimeLocation (org.cpsolver.coursett.model.TimeLocation)36 Placement (org.cpsolver.coursett.model.Placement)17 Lecture (org.cpsolver.coursett.model.Lecture)14 HashSet (java.util.HashSet)12 RoomLocation (org.cpsolver.coursett.model.RoomLocation)9 Constraint (org.cpsolver.ifs.model.Constraint)9 ArrayList (java.util.ArrayList)8 BitSet (java.util.BitSet)7 HashMap (java.util.HashMap)7 Element (org.dom4j.Element)7 WeakeningConstraint (org.cpsolver.ifs.model.WeakeningConstraint)6 DecimalFormat (java.text.DecimalFormat)5 List (java.util.List)4 Map (java.util.Map)4 TreeSet (java.util.TreeSet)4 RoomConstraint (org.cpsolver.coursett.constraint.RoomConstraint)4 GroupConstraint (org.cpsolver.coursett.constraint.GroupConstraint)3 InstructorConstraint (org.cpsolver.coursett.constraint.InstructorConstraint)3 SpreadConstraint (org.cpsolver.coursett.constraint.SpreadConstraint)3 Student (org.cpsolver.coursett.model.Student)3