Search in sources :

Example 51 with Placement

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

the class SolutionEvaluator method main.

public static void main(String[] args) throws Exception {
    ToolBox.configureLogging();
    DataProperties properties = ToolBox.loadProperties(new java.io.File(args[0]));
    properties.putAll(System.getProperties());
    TimetableModel model = new TimetableModel(properties);
    Assignment<Lecture, Placement> assignment = new DefaultSingleAssignment<Lecture, Placement>();
    TimetableXMLLoader loader = new TimetableXMLLoader(model, assignment);
    loader.setInputFile(new File(args[1]));
    loader.load();
    Solution<Lecture, Placement> solution = new Solution<Lecture, Placement>(model, assignment);
    Test.saveOutputCSV(solution, new File(args[2]));
}
Also used : Lecture(org.cpsolver.coursett.model.Lecture) Placement(org.cpsolver.coursett.model.Placement) DataProperties(org.cpsolver.ifs.util.DataProperties) DefaultSingleAssignment(org.cpsolver.ifs.assignment.DefaultSingleAssignment) TimetableModel(org.cpsolver.coursett.model.TimetableModel) File(java.io.File) File(java.io.File) Solution(org.cpsolver.ifs.solution.Solution)

Example 52 with Placement

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

the class StudentSectioningXMLLoader method load.

/**
     * Load data from the given XML root
     * @param root document root
     * @throws DocumentException
     */
protected void load(Element root) throws DocumentException {
    sLogger.debug("Root element: " + root.getName());
    if (!"sectioning".equals(root.getName())) {
        sLogger.error("Given XML file is not student sectioning problem.");
        return;
    }
    if (iLoadOfferings && getModel().getDistanceConflict() != null && root.element("travel-times") != null)
        loadTravelTimes(root.element("travel-times"), getModel().getDistanceConflict().getDistanceMetric());
    Map<Long, Placement> timetable = null;
    if (iTimetableFile != null) {
        sLogger.info("Reading timetable from " + iTimetableFile + " ...");
        Document timetableDocument = (new SAXReader()).read(iTimetableFile);
        Element timetableRoot = timetableDocument.getRootElement();
        if (!"timetable".equals(timetableRoot.getName())) {
            sLogger.error("Given XML file is not course timetabling problem.");
            return;
        }
        timetable = loadTimetable(timetableRoot);
    }
    Progress.getInstance(getModel()).load(root, true);
    Progress.getInstance(getModel()).message(Progress.MSGLEVEL_STAGE, "Restoring from backup ...");
    if (root.attributeValue("term") != null)
        getModel().getProperties().setProperty("Data.Term", root.attributeValue("term"));
    if (root.attributeValue("year") != null)
        getModel().getProperties().setProperty("Data.Year", root.attributeValue("year"));
    if (root.attributeValue("initiative") != null)
        getModel().getProperties().setProperty("Data.Initiative", root.attributeValue("initiative"));
    Map<Long, Offering> offeringTable = new HashMap<Long, Offering>();
    Map<Long, Course> courseTable = new HashMap<Long, Course>();
    if (iLoadOfferings && root.element("offerings") != null) {
        loadOfferings(root.element("offerings"), offeringTable, courseTable, timetable);
    } else {
        for (Offering offering : getModel().getOfferings()) {
            offeringTable.put(new Long(offering.getId()), offering);
            for (Course course : offering.getCourses()) {
                courseTable.put(new Long(course.getId()), course);
            }
        }
    }
    if (iLoadStudents && root.element("students") != null) {
        loadStudents(root.element("students"), offeringTable, courseTable);
    }
    if (iLoadOfferings && root.element("constraints") != null)
        loadLinkedSections(root.element("constraints"), offeringTable);
    sLogger.debug("Model successfully loaded.");
}
Also used : Placement(org.cpsolver.coursett.model.Placement) HashMap(java.util.HashMap) SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) Document(org.dom4j.Document) Course(org.cpsolver.studentsct.model.Course) Offering(org.cpsolver.studentsct.model.Offering)

Example 53 with Placement

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

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

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

the class InstructorConstraint method getAvailableArray.

@Deprecated
@SuppressWarnings("unchecked")
public List<Placement>[] getAvailableArray() {
    if (iUnavailabilities == null)
        return null;
    List<Placement>[] available = new List[Constants.SLOTS_PER_DAY * Constants.DAY_CODES.length];
    for (int i = 0; i < available.length; i++) available[i] = null;
    for (Placement p : iUnavailabilities) {
        for (Enumeration<Integer> e = p.getTimeLocation().getSlots(); e.hasMoreElements(); ) {
            int slot = e.nextElement();
            if (available[slot] == null)
                available[slot] = new ArrayList<Placement>(1);
            available[slot].add(p);
        }
    }
    return available;
}
Also used : Placement(org.cpsolver.coursett.model.Placement) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Placement (org.cpsolver.coursett.model.Placement)72 Lecture (org.cpsolver.coursett.model.Lecture)55 HashSet (java.util.HashSet)24 TimetableModel (org.cpsolver.coursett.model.TimetableModel)18 TimeLocation (org.cpsolver.coursett.model.TimeLocation)17 WeakeningConstraint (org.cpsolver.ifs.model.WeakeningConstraint)17 ArrayList (java.util.ArrayList)16 BitSet (java.util.BitSet)16 Constraint (org.cpsolver.ifs.model.Constraint)15 HashMap (java.util.HashMap)14 RoomLocation (org.cpsolver.coursett.model.RoomLocation)13 InstructorConstraint (org.cpsolver.coursett.constraint.InstructorConstraint)9 GlobalConstraint (org.cpsolver.ifs.model.GlobalConstraint)9 Student (org.cpsolver.coursett.model.Student)7 List (java.util.List)6 RoomConstraint (org.cpsolver.coursett.constraint.RoomConstraint)6 DataProperties (org.cpsolver.ifs.util.DataProperties)6 GroupConstraint (org.cpsolver.coursett.constraint.GroupConstraint)5 JenrlConstraint (org.cpsolver.coursett.constraint.JenrlConstraint)5 SpreadConstraint (org.cpsolver.coursett.constraint.SpreadConstraint)5