Search in sources :

Example 6 with RequestGroup

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

the class PriorityStudentWeights method getWeight.

@Override
public double getWeight(Assignment<Request, Enrollment> assignment, Enrollment enrollment) {
    double weight = getCachedWeight(enrollment.getRequest());
    switch(enrollment.getPriority()) {
        case 1:
            weight *= iFirstAlternativeFactor;
            break;
        case 2:
            weight *= iSecondAlternativeFactor;
            break;
    }
    if (enrollment.isCourseRequest() && iBalancingFactor != 0.0) {
        double configUsed = enrollment.getConfig().getEnrollmentTotalWeight(assignment, enrollment.getRequest()) + enrollment.getRequest().getWeight();
        double disbalanced = 0;
        double total = 0;
        for (Section section : enrollment.getSections()) {
            Subpart subpart = section.getSubpart();
            if (subpart.getSections().size() <= 1)
                continue;
            double used = section.getEnrollmentTotalWeight(assignment, enrollment.getRequest()) + enrollment.getRequest().getWeight();
            // sections have limits -> desired size is section limit x (total enrollment / total limit)
            // unlimited sections -> desired size is total enrollment / number of sections
            double desired = (subpart.getLimit() > 0 ? section.getLimit() * (configUsed / subpart.getLimit()) : configUsed / subpart.getSections().size());
            if (used > desired)
                disbalanced += Math.min(enrollment.getRequest().getWeight(), used - desired) / enrollment.getRequest().getWeight();
            else
                disbalanced -= Math.min(enrollment.getRequest().getWeight(), desired - used) / enrollment.getRequest().getWeight();
            total++;
        }
        if (disbalanced > 0)
            weight *= (1.0 - disbalanced / total * iBalancingFactor);
    }
    if (iMPP) {
        double difference = getDifference(enrollment);
        if (difference > 0.0)
            weight *= (1.0 - difference * iPerturbationFactor);
    }
    if (iSelectionFactor != 0.0) {
        double selection = getSelection(enrollment);
        if (selection > 0.0)
            weight *= (1.0 - selection * iSelectionFactor);
    }
    if (enrollment.isCourseRequest() && iGroupFactor != 0.0) {
        double sameGroup = 0.0;
        int groupCount = 0;
        for (RequestGroup g : ((CourseRequest) enrollment.getRequest()).getRequestGroups()) {
            if (g.getCourse().equals(enrollment.getCourse())) {
                sameGroup += g.getEnrollmentSpread(assignment, enrollment, iGroupBestRatio, iGroupFillRatio);
                groupCount++;
            }
        }
        if (groupCount > 0) {
            double difference = 1.0 - sameGroup / groupCount;
            weight *= (1.0 - difference * iGroupFactor);
        }
    }
    return round(weight);
}
Also used : CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Subpart(org.cpsolver.studentsct.model.Subpart) RequestGroup(org.cpsolver.studentsct.model.RequestGroup) Section(org.cpsolver.studentsct.model.Section)

Example 7 with RequestGroup

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

the class StudentSectioningXMLLoader method loadCourseRequest.

/**
     * Load course request
     * @param requestEl request element
     * @param student parent student
     * @param offeringTable offering table
     * @param courseTable course table
     * @return loaded course request
     */
public CourseRequest loadCourseRequest(Element requestEl, Student student, Map<Long, Offering> offeringTable, Map<Long, Course> courseTable) {
    List<Course> courses = new ArrayList<Course>();
    courses.add(courseTable.get(Long.valueOf(requestEl.attributeValue("course"))));
    for (Iterator<?> k = requestEl.elementIterator("alternative"); k.hasNext(); ) courses.add(courseTable.get(Long.valueOf(((Element) k.next()).attributeValue("course"))));
    Long timeStamp = null;
    if (requestEl.attributeValue("timeStamp") != null)
        timeStamp = Long.valueOf(requestEl.attributeValue("timeStamp"));
    CourseRequest courseRequest = new CourseRequest(Long.parseLong(requestEl.attributeValue("id")), Integer.parseInt(requestEl.attributeValue("priority")), "true".equals(requestEl.attributeValue("alternative")), student, courses, "true".equals(requestEl.attributeValue("waitlist", "false")), timeStamp);
    if (requestEl.attributeValue("weight") != null)
        courseRequest.setWeight(Double.parseDouble(requestEl.attributeValue("weight")));
    for (Iterator<?> k = requestEl.elementIterator("waitlisted"); k.hasNext(); ) {
        Element choiceEl = (Element) k.next();
        courseRequest.getWaitlistedChoices().add(new Choice(offeringTable.get(Long.valueOf(choiceEl.attributeValue("offering"))), choiceEl.getText()));
    }
    for (Iterator<?> k = requestEl.elementIterator("selected"); k.hasNext(); ) {
        Element choiceEl = (Element) k.next();
        courseRequest.getSelectedChoices().add(new Choice(offeringTable.get(Long.valueOf(choiceEl.attributeValue("offering"))), choiceEl.getText()));
    }
    groups: for (Iterator<?> k = requestEl.elementIterator("group"); k.hasNext(); ) {
        Element groupEl = (Element) k.next();
        long gid = Long.parseLong(groupEl.attributeValue("id"));
        String gname = groupEl.attributeValue("name", "g" + gid);
        Course course = courseTable.get(Long.valueOf(groupEl.attributeValue("course")));
        for (RequestGroup g : course.getRequestGroups()) {
            if (g.getId() == gid) {
                courseRequest.addRequestGroup(g);
                continue groups;
            }
        }
        courseRequest.addRequestGroup(new RequestGroup(gid, gname, course));
    }
    return courseRequest;
}
Also used : CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Choice(org.cpsolver.studentsct.model.Choice) RequestGroup(org.cpsolver.studentsct.model.RequestGroup) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Course(org.cpsolver.studentsct.model.Course)

Aggregations

RequestGroup (org.cpsolver.studentsct.model.RequestGroup)7 Course (org.cpsolver.studentsct.model.Course)6 Offering (org.cpsolver.studentsct.model.Offering)4 CourseRequest (org.cpsolver.studentsct.model.CourseRequest)3 Section (org.cpsolver.studentsct.model.Section)3 Subpart (org.cpsolver.studentsct.model.Subpart)3 Choice (org.cpsolver.studentsct.model.Choice)2 Element (org.dom4j.Element)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 TreeSet (java.util.TreeSet)1 RouletteWheelSelection (org.cpsolver.ifs.heuristics.RouletteWheelSelection)1 Constraint (org.cpsolver.ifs.model.Constraint)1 CSVFile (org.cpsolver.ifs.util.CSVFile)1 StudentSectioningModel (org.cpsolver.studentsct.StudentSectioningModel)1 Config (org.cpsolver.studentsct.model.Config)1 Enrollment (org.cpsolver.studentsct.model.Enrollment)1 Request (org.cpsolver.studentsct.model.Request)1