Search in sources :

Example 11 with Config

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

the class StudentSchedulingAssistantWeights method best.

private double[] best(Assignment<Request, Enrollment> assignment, CourseRequest cr) {
    double[] cached = iCache.get(cr);
    if (cached != null)
        return cached;
    double bestTime = 0;
    Double bestOverExpected = null;
    Double bestAvgPenalty = null;
    double bestSelected = 0.0;
    for (Course course : cr.getCourses()) {
        for (Config config : course.getOffering().getConfigs()) {
            int size = config.getSubparts().size();
            double sectionsWithTime = 0;
            double overExpected = 0;
            double penalty = 0;
            double selectedSections = 0;
            for (Subpart subpart : config.getSubparts()) {
                boolean hasTime = false;
                Double sectionPenalty = null;
                Double sectionOverExpected = null;
                boolean hasSelection = false;
                for (Section section : subpart.getSections()) {
                    if (section.getLimit() == 0)
                        continue;
                    if (section.getTime() != null)
                        hasTime = true;
                    if (!cr.getSelectedChoices().isEmpty() && cr.isSelected(section))
                        hasSelection = true;
                    if (sectionPenalty == null || sectionPenalty > section.getPenalty())
                        sectionPenalty = section.getPenalty();
                    double oexp = getOverExpected(assignment, section, cr);
                    if (sectionOverExpected == null || sectionOverExpected > oexp)
                        sectionOverExpected = oexp;
                }
                if (hasTime)
                    sectionsWithTime++;
                if (sectionPenalty != null)
                    penalty += sectionPenalty;
                if (hasSelection)
                    selectedSections++;
                if (sectionOverExpected != null)
                    overExpected += sectionOverExpected;
            }
            if (sectionsWithTime / size > bestTime)
                bestTime = sectionsWithTime / size;
            if (bestOverExpected == null || overExpected < bestOverExpected)
                bestOverExpected = overExpected;
            if (bestAvgPenalty == null || penalty / size < bestAvgPenalty)
                bestAvgPenalty = penalty / size;
            if (selectedSections / size > bestSelected)
                bestSelected = selectedSections / size;
        }
    }
    cached = new double[] { bestTime, (bestOverExpected == null ? 0.0 : bestOverExpected), (bestAvgPenalty == null ? 0.0 : bestAvgPenalty), bestSelected };
    iCache.put(cr, cached);
    return cached;
}
Also used : Config(org.cpsolver.studentsct.model.Config) Subpart(org.cpsolver.studentsct.model.Subpart) Course(org.cpsolver.studentsct.model.Course) Section(org.cpsolver.studentsct.model.Section)

Example 12 with Config

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

the class SuggestionsBranchAndBound method values.

/**
     * Domain of a request    
     * @param request given request
     * @return possible enrollments (meeting the filter etc)
     */
protected List<Enrollment> values(final Request request) {
    if (!request.getStudent().canAssign(iAssignment, request))
        return new ArrayList<Enrollment>();
    List<Enrollment> values = iValues.get(request);
    if (values != null)
        return values;
    if (request instanceof CourseRequest) {
        CourseRequest cr = (CourseRequest) request;
        values = (cr.equals(iSelectedRequest) ? cr.getAvaiableEnrollments(iAssignment) : cr.getAvaiableEnrollmentsSkipSameTime(iAssignment));
        Collections.sort(values, new Comparator<Enrollment>() {

            @Override
            public int compare(Enrollment e1, Enrollment e2) {
                return iComparator.compare(iAssignment, e1, e2);
            }
        });
    } else {
        values = new ArrayList<Enrollment>();
        values.add(((FreeTimeRequest) request).createEnrollment());
    }
    if (canLeaveUnassigned(request)) {
        Config config = null;
        if (request instanceof CourseRequest)
            config = ((CourseRequest) request).getCourses().get(0).getOffering().getConfigs().get(0);
        values.add(new Enrollment(request, 0, config, new HashSet<Section>(), iAssignment));
    }
    iValues.put(request, values);
    if (request.equals(iSelectedRequest) && iFilter != null && request instanceof CourseRequest) {
        for (Iterator<Enrollment> i = values.iterator(); i.hasNext(); ) {
            Enrollment enrollment = i.next();
            if (enrollment.getAssignments() != null && !enrollment.getAssignments().isEmpty()) {
                boolean match = false;
                for (Iterator<Section> j = enrollment.getSections().iterator(); j.hasNext(); ) {
                    Section section = j.next();
                    if (iSelectedSection != null) {
                        if (section.getSubpart().getId() == iSelectedSection.getSubpart().getId()) {
                            if (iFilter.match(enrollment.getCourse(), section)) {
                                match = true;
                                break;
                            }
                        }
                        if (section.getSubpart().getConfig().getId() != iSelectedSection.getSubpart().getConfig().getId() && section.getSubpart().getInstructionalType().equals(iSelectedSection.getSubpart().getInstructionalType())) {
                            if (iFilter.match(enrollment.getCourse(), section)) {
                                match = true;
                                break;
                            }
                        }
                    } else {
                        if (iFilter.match(enrollment.getCourse(), section)) {
                            match = true;
                            break;
                        }
                    }
                }
                if (!match)
                    i.remove();
            }
        }
    }
    if (request.equals(iSelectedRequest))
        iMatched = values.size();
    return values;
}
Also used : CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Config(org.cpsolver.studentsct.model.Config) Enrollment(org.cpsolver.studentsct.model.Enrollment) Section(org.cpsolver.studentsct.model.Section) HashSet(java.util.HashSet)

Example 13 with Config

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

the class StudentChoiceOrder method avgNrChoices.

/** Average number of choices for each student 
     * @param student given student
     * @return average number of choices of the given student
     **/
public double avgNrChoices(Student student) {
    int nrRequests = 0;
    int nrChoices = 0;
    for (Request request : student.getRequests()) {
        if (request instanceof CourseRequest) {
            CourseRequest cr = (CourseRequest) request;
            for (Course course : cr.getCourses()) {
                for (Config config : course.getOffering().getConfigs()) {
                    Integer nrChoicesThisCfg = iCache.get(config);
                    if (nrChoicesThisCfg == null) {
                        nrChoicesThisCfg = new Integer(nrChoices(config, 0, new HashSet<Section>()));
                        iCache.put(config, nrChoicesThisCfg);
                    }
                    nrChoices += nrChoicesThisCfg.intValue();
                }
            }
            nrRequests++;
        }
    }
    return (nrRequests == 0 ? 0.0 : ((double) nrChoices) / nrRequests);
}
Also used : CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Config(org.cpsolver.studentsct.model.Config) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Request(org.cpsolver.studentsct.model.Request) Course(org.cpsolver.studentsct.model.Course) Section(org.cpsolver.studentsct.model.Section)

Example 14 with Config

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

the class Test method getPercDisbalancedSections.

public double getPercDisbalancedSections(Assignment<Request, Enrollment> assignment, double perc) {
    boolean balanceUnlimited = model().getProperties().getPropertyBoolean("General.BalanceUnlimited", false);
    double disb10Sections = 0, nrSections = 0;
    for (Offering offering : model().getOfferings()) {
        for (Config config : offering.getConfigs()) {
            double enrl = config.getEnrollmentTotalWeight(assignment, null);
            for (Subpart subpart : config.getSubparts()) {
                if (subpart.getSections().size() <= 1)
                    continue;
                nrSections += subpart.getSections().size();
                if (subpart.getLimit() > 0) {
                    // sections have limits -> desired size is section limit
                    // x (total enrollment / total limit)
                    double ratio = enrl / subpart.getLimit();
                    for (Section section : subpart.getSections()) {
                        double desired = ratio * section.getLimit();
                        if (Math.abs(desired - section.getEnrollmentTotalWeight(assignment, null)) >= Math.max(1.0, perc * section.getLimit()))
                            disb10Sections++;
                    }
                } else if (balanceUnlimited) {
                    // enrollment / number of sections
                    for (Section section : subpart.getSections()) {
                        double desired = enrl / subpart.getSections().size();
                        if (Math.abs(desired - section.getEnrollmentTotalWeight(assignment, null)) >= Math.max(1.0, perc * desired))
                            disb10Sections++;
                    }
                }
            }
        }
    }
    return 100.0 * disb10Sections / nrSections;
}
Also used : Config(org.cpsolver.studentsct.model.Config) Subpart(org.cpsolver.studentsct.model.Subpart) Offering(org.cpsolver.studentsct.model.Offering) Section(org.cpsolver.studentsct.model.Section)

Example 15 with Config

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

the class StudentSectioningXMLSaver method saveReservation.

/**
     * Save reservation
     * @param reservationEl reservation element to be populated
     * @param reservation reservation to be saved
     */
protected void saveReservation(Element reservationEl, Reservation reservation) {
    reservationEl.addAttribute("id", getId("reservation", reservation.getId()));
    reservationEl.addAttribute("expired", reservation.isExpired() ? "true" : "false");
    if (reservation instanceof GroupReservation) {
        GroupReservation gr = (GroupReservation) reservation;
        reservationEl.addAttribute("type", "group");
        for (Long studentId : gr.getStudentIds()) reservationEl.addElement("student").addAttribute("id", getId("student", studentId));
        if (gr.getReservationLimit() >= 0.0)
            reservationEl.addAttribute("limit", String.valueOf(gr.getReservationLimit()));
    } else if (reservation instanceof ReservationOverride) {
        reservationEl.addAttribute("type", "override");
        ReservationOverride o = (ReservationOverride) reservation;
        for (Long studentId : o.getStudentIds()) reservationEl.addElement("student").addAttribute("id", getId("student", studentId));
    } else if (reservation instanceof IndividualReservation) {
        reservationEl.addAttribute("type", "individual");
        for (Long studentId : ((IndividualReservation) reservation).getStudentIds()) reservationEl.addElement("student").addAttribute("id", getId("student", studentId));
    } else if (reservation instanceof CurriculumReservation) {
        reservationEl.addAttribute("type", "curriculum");
        CurriculumReservation cr = (CurriculumReservation) reservation;
        if (cr.getReservationLimit() >= 0.0)
            reservationEl.addAttribute("limit", String.valueOf(cr.getReservationLimit()));
        reservationEl.addAttribute("area", cr.getAcademicArea());
        for (String clasf : cr.getClassifications()) reservationEl.addElement("classification").addAttribute("code", clasf);
        for (String major : cr.getMajors()) reservationEl.addElement("major").addAttribute("code", major);
    } else if (reservation instanceof CourseReservation) {
        reservationEl.addAttribute("type", "course");
        CourseReservation cr = (CourseReservation) reservation;
        reservationEl.addAttribute("course", getId("course", cr.getCourse().getId()));
    } else if (reservation instanceof DummyReservation) {
        reservationEl.addAttribute("type", "dummy");
    }
    reservationEl.addAttribute("priority", String.valueOf(reservation.getPriority()));
    reservationEl.addAttribute("mustBeUsed", reservation.mustBeUsed() ? "true" : "false");
    reservationEl.addAttribute("allowOverlap", reservation.isAllowOverlap() ? "true" : "false");
    reservationEl.addAttribute("canAssignOverLimit", reservation.canAssignOverLimit() ? "true" : "false");
    for (Config config : reservation.getConfigs()) reservationEl.addElement("config").addAttribute("id", getId("config", config.getId()));
    for (Map.Entry<Subpart, Set<Section>> entry : reservation.getSections().entrySet()) {
        for (Section section : entry.getValue()) {
            reservationEl.addElement("section").addAttribute("id", getId("section", section.getId()));
        }
    }
}
Also used : GroupReservation(org.cpsolver.studentsct.reservation.GroupReservation) CourseReservation(org.cpsolver.studentsct.reservation.CourseReservation) TreeSet(java.util.TreeSet) Set(java.util.Set) BitSet(java.util.BitSet) IndividualReservation(org.cpsolver.studentsct.reservation.IndividualReservation) Config(org.cpsolver.studentsct.model.Config) Section(org.cpsolver.studentsct.model.Section) DummyReservation(org.cpsolver.studentsct.reservation.DummyReservation) CurriculumReservation(org.cpsolver.studentsct.reservation.CurriculumReservation) Subpart(org.cpsolver.studentsct.model.Subpart) ReservationOverride(org.cpsolver.studentsct.reservation.ReservationOverride) Map(java.util.Map)

Aggregations

Config (org.cpsolver.studentsct.model.Config)30 Section (org.cpsolver.studentsct.model.Section)23 Subpart (org.cpsolver.studentsct.model.Subpart)20 Course (org.cpsolver.studentsct.model.Course)13 Offering (org.cpsolver.studentsct.model.Offering)13 CourseRequest (org.cpsolver.studentsct.model.CourseRequest)11 Enrollment (org.cpsolver.studentsct.model.Enrollment)9 Request (org.cpsolver.studentsct.model.Request)8 HashSet (java.util.HashSet)6 TreeSet (java.util.TreeSet)6 DistanceConflict (org.cpsolver.studentsct.extension.DistanceConflict)5 TimeOverlapsCounter (org.cpsolver.studentsct.extension.TimeOverlapsCounter)5 BitSet (java.util.BitSet)4 Set (java.util.Set)4 Student (org.cpsolver.studentsct.model.Student)4 Reservation (org.cpsolver.studentsct.reservation.Reservation)4 DecimalFormat (java.text.DecimalFormat)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Hashtable (java.util.Hashtable)3