Search in sources :

Example 6 with CourseRequest

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

the class StudentRequestXml method exportModel.

public static Document exportModel(Assignment<Request, Enrollment> assignment, StudentSectioningModel model) {
    Document document = DocumentHelper.createDocument();
    Element requestElement = document.addElement("request");
    requestElement.addAttribute("campus", model.getProperties().getProperty("Data.Initiative"));
    requestElement.addAttribute("year", model.getProperties().getProperty("Data.Year"));
    requestElement.addAttribute("term", model.getProperties().getProperty("Data.Term"));
    for (Student student : model.getStudents()) {
        Element studentElement = requestElement.addElement("student");
        studentElement.addAttribute("key", String.valueOf(student.getId()));
        Element courseRequestsElement = studentElement.addElement("updateCourseRequests");
        courseRequestsElement.addAttribute("commit", "true");
        Collections.sort(student.getRequests(), new Comparator<Request>() {

            @Override
            public int compare(Request r1, Request r2) {
                if (r1.isAlternative() != r2.isAlternative()) {
                    return (r1.isAlternative() ? 1 : -1);
                }
                return Double.compare(r1.getPriority(), r2.getPriority());
            }
        });
        boolean hasSchedule = false;
        for (Request request : student.getRequests()) {
            if (assignment.getValue(request) != null)
                hasSchedule = true;
            if (request instanceof FreeTimeRequest) {
                FreeTimeRequest ftReq = (FreeTimeRequest) request;
                Element ftReqElement = courseRequestsElement.addElement("freeTime");
                requestElement.addAttribute("days", ftReq.getTime().getDayHeader());
                int startSlot = ftReq.getTime().getStartSlot();
                int startTime = startSlot * Constants.SLOT_LENGTH_MIN + Constants.FIRST_SLOT_TIME_MIN;
                ftReqElement.addAttribute("startTime", s2zDF.format(startTime / 60) + s2zDF.format(startTime % 60));
                int endTime = startTime + ftReq.getTime().getLength() * Constants.SLOT_LENGTH_MIN - ftReq.getTime().getBreakTime();
                ftReqElement.addAttribute("endTime", s2zDF.format(endTime / 60) + s2zDF.format(endTime % 60));
                ftReqElement.addAttribute("length", String.valueOf(ftReq.getTime().getLength() * Constants.SLOT_LENGTH_MIN));
            } else {
                CourseRequest crReq = (CourseRequest) request;
                Element crReqElement = courseRequestsElement.addElement("courseOffering");
                Course course = crReq.getCourses().get(0);
                crReqElement.addAttribute("subjectArea", course.getSubjectArea());
                crReqElement.addAttribute("courseNumber", course.getCourseNumber());
                crReqElement.addAttribute("waitlist", crReq.isWaitlist() ? "true" : "false");
                crReqElement.addAttribute("critical", crReq.getRequestPriority() == RequestPriority.Critical ? "true" : "false");
                crReqElement.addAttribute("importance", crReq.getRequestPriority().name());
                crReqElement.addAttribute("alternative", crReq.isAlternative() ? "true" : "false");
                for (int i = 1; i < crReq.getCourses().size(); i++) {
                    Course altCourse = crReq.getCourses().get(i);
                    Element altCourseElement = crReqElement.addElement("alternative");
                    altCourseElement.addAttribute("subjectArea", altCourse.getSubjectArea());
                    altCourseElement.addAttribute("courseNumber", altCourse.getCourseNumber());
                }
            }
        }
        if (hasSchedule) {
            Element requestScheduleElement = studentElement.addElement("requestSchedule");
            requestScheduleElement.addAttribute("type", "commit");
            for (Request request : student.getRequests()) {
                if (request instanceof CourseRequest) {
                    CourseRequest crReq = (CourseRequest) request;
                    Enrollment enrollment = assignment.getValue(crReq);
                    if (enrollment == null)
                        continue;
                    Element crReqElement = requestScheduleElement.addElement("courseOffering");
                    Course course = enrollment.getCourse();
                    crReqElement.addAttribute("subjectArea", course.getSubjectArea());
                    crReqElement.addAttribute("courseNumber", course.getCourseNumber());
                    for (Section section : enrollment.getSections()) {
                        Element classEl = crReqElement.addElement("class");
                        classEl.addAttribute("id", section.getSubpart().getInstructionalType());
                        classEl.addAttribute("assignmentId", String.valueOf(section.getId()));
                    }
                }
            }
        }
    }
    return document;
}
Also used : FreeTimeRequest(org.cpsolver.studentsct.model.FreeTimeRequest) Element(org.dom4j.Element) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) FreeTimeRequest(org.cpsolver.studentsct.model.FreeTimeRequest) Request(org.cpsolver.studentsct.model.Request) Document(org.dom4j.Document) Student(org.cpsolver.studentsct.model.Student) Section(org.cpsolver.studentsct.model.Section) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Enrollment(org.cpsolver.studentsct.model.Enrollment) Course(org.cpsolver.studentsct.model.Course)

Example 7 with CourseRequest

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

the class StudentSectioningModel method computeOnlineSectioningInfos.

/**
 * Compute online student sectioning infos for all sections (see
 * {@link Section#getSpaceExpected()} and {@link Section#getSpaceHeld()}).
 * @param assignment current assignment
 */
public void computeOnlineSectioningInfos(Assignment<Request, Enrollment> assignment) {
    clearOnlineSectioningInfos();
    for (Student student : getStudents()) {
        if (!student.isDummy())
            continue;
        for (Request request : student.getRequests()) {
            if (!(request instanceof CourseRequest))
                continue;
            CourseRequest courseRequest = (CourseRequest) request;
            Enrollment enrollment = assignment.getValue(courseRequest);
            if (enrollment != null) {
                for (Section section : enrollment.getSections()) {
                    section.setSpaceHeld(courseRequest.getWeight() + section.getSpaceHeld());
                }
            }
            List<Enrollment> feasibleEnrollments = new ArrayList<Enrollment>();
            int totalLimit = 0;
            for (Enrollment enrl : courseRequest.values(assignment)) {
                boolean overlaps = false;
                for (Request otherRequest : student.getRequests()) {
                    if (otherRequest.equals(courseRequest) || !(otherRequest instanceof CourseRequest))
                        continue;
                    Enrollment otherErollment = assignment.getValue(otherRequest);
                    if (otherErollment == null)
                        continue;
                    if (enrl.isOverlapping(otherErollment)) {
                        overlaps = true;
                        break;
                    }
                }
                if (!overlaps) {
                    feasibleEnrollments.add(enrl);
                    if (totalLimit >= 0) {
                        int limit = enrl.getLimit();
                        if (limit < 0)
                            totalLimit = -1;
                        else
                            totalLimit += limit;
                    }
                }
            }
            double increment = courseRequest.getWeight() / (totalLimit > 0 ? totalLimit : feasibleEnrollments.size());
            for (Enrollment feasibleEnrollment : feasibleEnrollments) {
                for (Section section : feasibleEnrollment.getSections()) {
                    if (totalLimit > 0) {
                        section.setSpaceExpected(section.getSpaceExpected() + increment * feasibleEnrollment.getLimit());
                    } else {
                        section.setSpaceExpected(section.getSpaceExpected() + increment);
                    }
                }
            }
        }
    }
}
Also used : CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Request(org.cpsolver.studentsct.model.Request) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) ArrayList(java.util.ArrayList) Enrollment(org.cpsolver.studentsct.model.Enrollment) Student(org.cpsolver.studentsct.model.Student) Section(org.cpsolver.studentsct.model.Section) Constraint(org.cpsolver.ifs.model.Constraint)

Example 8 with CourseRequest

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

the class StudentSectioningModel method getTotalValue.

/**
 * Overall solution value
 * @param assignment current assignment
 * @param precise true if should be computed
 * @return solution value
 */
public double getTotalValue(Assignment<Request, Enrollment> assignment, boolean precise) {
    if (precise) {
        double total = 0;
        for (Request r : assignment.assignedVariables()) total += r.getWeight() * iStudentWeights.getWeight(assignment, assignment.getValue(r));
        if (iDistanceConflict != null)
            for (DistanceConflict.Conflict c : iDistanceConflict.computeAllConflicts(assignment)) total -= avg(c.getR1().getWeight(), c.getR2().getWeight()) * iStudentWeights.getDistanceConflictWeight(assignment, c);
        if (iTimeOverlaps != null)
            for (TimeOverlapsCounter.Conflict c : iTimeOverlaps.getContext(assignment).computeAllConflicts(assignment)) {
                if (c.getR1() != null)
                    total -= c.getR1Weight() * iStudentWeights.getTimeOverlapConflictWeight(assignment, c.getE1(), c);
                if (c.getR2() != null)
                    total -= c.getR2Weight() * iStudentWeights.getTimeOverlapConflictWeight(assignment, c.getE2(), c);
            }
        if (iStudentQuality != null)
            for (StudentQuality.Type t : StudentQuality.Type.values()) {
                for (StudentQuality.Conflict c : iStudentQuality.getContext(assignment).computeAllConflicts(t, assignment)) {
                    switch(c.getType().getType()) {
                        case REQUEST:
                            if (c.getR1() instanceof CourseRequest)
                                total -= c.getR1Weight() * iStudentWeights.getStudentQualityConflictWeight(assignment, c.getE1(), c);
                            else
                                total -= c.getR2Weight() * iStudentWeights.getStudentQualityConflictWeight(assignment, c.getE2(), c);
                            break;
                        case BOTH:
                            total -= c.getR1Weight() * iStudentWeights.getStudentQualityConflictWeight(assignment, c.getE1(), c);
                            total -= c.getR2Weight() * iStudentWeights.getStudentQualityConflictWeight(assignment, c.getE2(), c);
                            break;
                        case LOWER:
                            total -= avg(c.getR1().getWeight(), c.getR2().getWeight()) * iStudentWeights.getStudentQualityConflictWeight(assignment, c.getE1(), c);
                            break;
                        case HIGHER:
                            total -= avg(c.getR1().getWeight(), c.getR2().getWeight()) * iStudentWeights.getStudentQualityConflictWeight(assignment, c.getE1(), c);
                            break;
                    }
                }
            }
        return -total;
    }
    return getContext(assignment).getTotalValue();
}
Also used : CourseRequest(org.cpsolver.studentsct.model.CourseRequest) DistanceConflict(org.cpsolver.studentsct.extension.DistanceConflict) StudentConflict(org.cpsolver.studentsct.constraint.StudentConflict) Request(org.cpsolver.studentsct.model.Request) CourseRequest(org.cpsolver.studentsct.model.CourseRequest)

Example 9 with CourseRequest

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

the class StudentSectioningXMLLoader method loadStudents.

/**
 * Load students
 * @param studentsEl students element
 * @param offeringTable offering table
 * @param courseTable course table
 */
protected void loadStudents(Element studentsEl, Map<Long, Offering> offeringTable, Map<Long, Course> courseTable, List<Enrollment> bestEnrollments, List<Enrollment> currentEnrollments) {
    for (Iterator<?> i = studentsEl.elementIterator("student"); i.hasNext(); ) {
        Element studentEl = (Element) i.next();
        Student student = loadStudent(studentEl, offeringTable);
        if (iStudentFilter != null && !iStudentFilter.accept(student))
            continue;
        for (Iterator<?> j = studentEl.elementIterator(); j.hasNext(); ) {
            Element requestEl = (Element) j.next();
            Request request = loadRequest(requestEl, student, offeringTable, courseTable);
            if (request == null)
                continue;
            Element initialEl = requestEl.element("initial");
            if (iLoadInitial && initialEl != null) {
                Enrollment enrollment = loadEnrollment(initialEl, request);
                if (enrollment != null)
                    request.setInitialAssignment(enrollment);
            }
            Element currentEl = requestEl.element("current");
            if (iLoadCurrent && currentEl != null) {
                Enrollment enrollment = loadEnrollment(currentEl, request);
                if (enrollment != null)
                    currentEnrollments.add(enrollment);
            }
            Element bestEl = requestEl.element("best");
            if (iLoadBest && bestEl != null) {
                Enrollment enrollment = loadEnrollment(bestEl, request);
                if (enrollment != null)
                    bestEnrollments.add(enrollment);
            }
            Element fixedEl = requestEl.element("fixed");
            if (fixedEl != null && request instanceof CourseRequest)
                ((CourseRequest) request).setFixedValue(loadEnrollment(fixedEl, request));
        }
        getModel().addStudent(student);
    }
}
Also used : CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Element(org.dom4j.Element) Request(org.cpsolver.studentsct.model.Request) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) FreeTimeRequest(org.cpsolver.studentsct.model.FreeTimeRequest) Enrollment(org.cpsolver.studentsct.model.Enrollment) Student(org.cpsolver.studentsct.model.Student)

Example 10 with CourseRequest

use of org.cpsolver.studentsct.model.CourseRequest 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)

Aggregations

CourseRequest (org.cpsolver.studentsct.model.CourseRequest)67 Request (org.cpsolver.studentsct.model.Request)51 Enrollment (org.cpsolver.studentsct.model.Enrollment)37 Section (org.cpsolver.studentsct.model.Section)36 Course (org.cpsolver.studentsct.model.Course)26 FreeTimeRequest (org.cpsolver.studentsct.model.FreeTimeRequest)21 Subpart (org.cpsolver.studentsct.model.Subpart)21 ArrayList (java.util.ArrayList)20 HashSet (java.util.HashSet)18 Student (org.cpsolver.studentsct.model.Student)17 HashMap (java.util.HashMap)15 Config (org.cpsolver.studentsct.model.Config)13 Map (java.util.Map)11 Offering (org.cpsolver.studentsct.model.Offering)10 CSVFile (org.cpsolver.ifs.util.CSVFile)9 Set (java.util.Set)8 DistanceConflict (org.cpsolver.studentsct.extension.DistanceConflict)7 TreeSet (java.util.TreeSet)6 Constraint (org.cpsolver.ifs.model.Constraint)6 StudentQuality (org.cpsolver.studentsct.extension.StudentQuality)6