Search in sources :

Example 46 with CourseRequest

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

the class MultiCriteriaBranchAndBoundSelection method backTrack.

/** branch & bound search */
public void backTrack(int idx) {
    if (iTimeout > 0 && (JProf.currentTimeMillis() - iT0) > iTimeout) {
        iTimeoutReached = true;
        return;
    }
    if (idx == iCurrentAssignment.length) {
        if (iBestAssignment == null || iComparator.compare(iAssignment, iCurrentAssignment, iBestAssignment) < 0)
            saveBest();
        return;
    } else if (iBestAssignment != null && !iComparator.canImprove(iAssignment, idx, iCurrentAssignment, iBestAssignment)) {
        return;
    }
    Request request = iStudent.getRequests().get(idx);
    if (!canAssign(request, idx)) {
        backTrack(idx + 1);
        return;
    }
    List<Enrollment> values = null;
    if (request instanceof CourseRequest) {
        CourseRequest courseRequest = (CourseRequest) request;
        if (!courseRequest.getSelectedChoices().isEmpty()) {
            values = courseRequest.getSelectedEnrollments(iAssignment, true);
            if (values != null && !values.isEmpty()) {
                boolean hasNoConflictValue = false;
                for (Enrollment enrollment : values) {
                    if (inConflict(idx, enrollment))
                        continue;
                    hasNoConflictValue = true;
                    iCurrentAssignment[idx] = enrollment;
                    backTrack(idx + 1);
                    iCurrentAssignment[idx] = null;
                }
                if (hasNoConflictValue && iBranchWhenSelectedHasNoConflict)
                    return;
            }
        }
        values = iValues.get(courseRequest);
        if (values == null) {
            values = values(courseRequest);
            iValues.put(courseRequest, values);
        }
    } else {
        values = request.computeEnrollments(iAssignment);
    }
    boolean hasNoConflictValue = false;
    for (Enrollment enrollment : values) {
        if (inConflict(idx, enrollment))
            continue;
        hasNoConflictValue = true;
        iCurrentAssignment[idx] = enrollment;
        backTrack(idx + 1);
        iCurrentAssignment[idx] = null;
    }
    if (canLeaveUnassigned(request) || (!hasNoConflictValue && request instanceof CourseRequest))
        backTrack(idx + 1);
}
Also used : CourseRequest(org.cpsolver.studentsct.model.CourseRequest) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) FreeTimeRequest(org.cpsolver.studentsct.model.FreeTimeRequest) Request(org.cpsolver.studentsct.model.Request) Enrollment(org.cpsolver.studentsct.model.Enrollment)

Example 47 with CourseRequest

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

the class MultiCriteriaBranchAndBoundSelection method setRequiredSections.

@Override
public void setRequiredSections(Hashtable<CourseRequest, Set<Section>> requiredSections) {
    if (requiredSections != null) {
        for (Map.Entry<CourseRequest, Set<Section>> entry : requiredSections.entrySet()) {
            Hashtable<Subpart, Section> subSection = new Hashtable<Subpart, Section>();
            iRequiredSection.put(entry.getKey(), subSection);
            for (Section section : entry.getValue()) {
                if (subSection.isEmpty())
                    iRequiredConfig.put(entry.getKey(), section.getSubpart().getConfig());
                subSection.put(section.getSubpart(), section);
            }
        }
    }
}
Also used : CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Set(java.util.Set) Hashtable(java.util.Hashtable) Subpart(org.cpsolver.studentsct.model.Subpart) HashMap(java.util.HashMap) Map(java.util.Map) Section(org.cpsolver.studentsct.model.Section)

Example 48 with CourseRequest

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

the class StudentPreferencePenalties method setPenalties.

/**
     * Set the computed penalties to all sections of all requests of the given
     * student
     * @param student given student
     * @param distributionType penalty distribution type
     */
public static void setPenalties(Student student, int distributionType) {
    if (sDebug)
        sLog.debug("Setting penalties for " + student);
    StudentPreferencePenalties penalties = new StudentPreferencePenalties(distributionType);
    for (Request request : student.getRequests()) {
        if (!(request instanceof CourseRequest))
            continue;
        CourseRequest courseRequest = (CourseRequest) request;
        if (sDebug)
            sLog.debug("-- " + courseRequest);
        for (Course course : courseRequest.getCourses()) {
            if (sDebug)
                sLog.debug("  -- " + course.getName());
            for (Config config : course.getOffering().getConfigs()) {
                if (sDebug)
                    sLog.debug("    -- " + config.getName());
                for (Subpart subpart : config.getSubparts()) {
                    if (sDebug)
                        sLog.debug("      -- " + subpart.getName());
                    for (Section section : subpart.getSections()) {
                        section.setPenalty(penalties.getPenalty(section));
                        if (sDebug)
                            sLog.debug("        -- " + section);
                    }
                }
            }
        }
        courseRequest.clearCache();
    }
}
Also used : CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Config(org.cpsolver.studentsct.model.Config) Subpart(org.cpsolver.studentsct.model.Subpart) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) FreeTimeRequest(org.cpsolver.studentsct.model.FreeTimeRequest) Request(org.cpsolver.studentsct.model.Request) Course(org.cpsolver.studentsct.model.Course) Section(org.cpsolver.studentsct.model.Section)

Example 49 with CourseRequest

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

the class StudentSctBBTest method getMessages.

/**
     * Return a list of messages ({@link Message} objects) from the sectioning
     * of the given student
     * @return enrollment messages
     */
public List<Message> getMessages() {
    Assignment<Request, Enrollment> assignment = getSolution().getAssignment();
    List<Message> ret = new ArrayList<Message>();
    ret.add(new Message(Message.sMsgLevelInfo, null, "<li>Solution found in " + iTime + " ms."));
    if (iTimeoutReached)
        ret.add(new Message(Message.sMsgLevelInfo, null, "<li>Time out reached, solution optimality can not be guaranteed."));
    for (Request request : getStudent().getRequests()) {
        if (!request.isAlternative() && assignment.getValue(request) == null) {
            ret.add(new Message(Message.sMsgLevelWarn, request, "<li>Unable to enroll to " + request + ", " + (request instanceof CourseRequest ? ((CourseRequest) request).getCourses().size() == 1 ? "course is" : "courses are" : "time is") + " not available."));
            Collection<Enrollment> values = (request instanceof CourseRequest ? (Collection<Enrollment>) ((CourseRequest) request).getAvaiableEnrollmentsSkipSameTime(assignment) : request.computeEnrollments(assignment));
            for (Iterator<Enrollment> f = values.iterator(); f.hasNext(); ) {
                Enrollment enrollment = f.next();
                Set<Enrollment> conf = conflictValues(assignment, enrollment);
                if (conf != null && !conf.isEmpty()) {
                    Enrollment conflict = conf.iterator().next();
                    if (conflict.equals(enrollment))
                        ret.add(new Message(Message.sMsgLevelInfo, request, "<ul>Assignment of " + enrollment.getName().replaceAll("\n", "<br>&nbsp;&nbsp;&nbsp;&nbsp;") + "<br> is not available."));
                    else
                        ret.add(new Message(Message.sMsgLevelInfo, request, "<ul>Assignment of " + enrollment.getName().replaceAll("\n", "<br>&nbsp;&nbsp;&nbsp;&nbsp;") + "<br> conflicts with " + conflict.getName().replaceAll("\n", "<br>&nbsp;&nbsp;&nbsp;&nbsp;") + "</ul>"));
                }
            }
        }
        if (request instanceof CourseRequest && assignment.getValue(request) != null) {
            CourseRequest courseRequest = (CourseRequest) request;
            Enrollment enrollment = assignment.getValue(request);
            List<Enrollment> selectedEnrollments = courseRequest.getSelectedEnrollments(assignment, false);
            if (selectedEnrollments != null && !selectedEnrollments.isEmpty() && !selectedEnrollments.contains(enrollment)) {
                Course course = (courseRequest.getSelectedChoices().iterator().next()).getOffering().getCourse(getStudent());
                Enrollment selected = selectedEnrollments.get(0);
                Set<Enrollment> conf = conflictValues(assignment, selected);
                if (conf != null && !conf.isEmpty()) {
                    ret.add(new Message(Message.sMsgLevelWarn, request, "<li>Unable to enroll selected enrollment for " + course.getName() + ", seleted " + (courseRequest.getSelectedChoices().size() == 1 ? "class is" : "classes are") + " conflicting with other choices."));
                    Enrollment conflict = conf.iterator().next();
                    if (conflict.equals(selected))
                        ret.add(new Message(Message.sMsgLevelInfo, request, "<ul>Assignment of " + selected.getName().replaceAll("\n", "<br>&nbsp;&nbsp;&nbsp;&nbsp;") + "<br> is not available."));
                    else
                        ret.add(new Message(Message.sMsgLevelInfo, request, "<ul>Assignment of " + selected.getName().replaceAll("\n", "<br>&nbsp;&nbsp;&nbsp;&nbsp;") + "<br> conflicts with " + conflict.getName().replaceAll("\n", "<br>&nbsp;&nbsp;&nbsp;&nbsp;") + "</ul>"));
                } else {
                    ret.add(new Message(Message.sMsgLevelWarn, request, "<li>Unable to enroll selected enrollment for " + course.getName() + "."));
                }
            }
        }
    }
    return ret;
}
Also used : CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Request(org.cpsolver.studentsct.model.Request) ArrayList(java.util.ArrayList) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Enrollment(org.cpsolver.studentsct.model.Enrollment) Collection(java.util.Collection) Course(org.cpsolver.studentsct.model.Course)

Aggregations

CourseRequest (org.cpsolver.studentsct.model.CourseRequest)49 Request (org.cpsolver.studentsct.model.Request)34 Section (org.cpsolver.studentsct.model.Section)31 Enrollment (org.cpsolver.studentsct.model.Enrollment)24 Course (org.cpsolver.studentsct.model.Course)22 FreeTimeRequest (org.cpsolver.studentsct.model.FreeTimeRequest)17 Subpart (org.cpsolver.studentsct.model.Subpart)17 ArrayList (java.util.ArrayList)16 HashSet (java.util.HashSet)16 HashMap (java.util.HashMap)13 Config (org.cpsolver.studentsct.model.Config)11 Student (org.cpsolver.studentsct.model.Student)11 Map (java.util.Map)10 Offering (org.cpsolver.studentsct.model.Offering)8 Set (java.util.Set)6 TreeSet (java.util.TreeSet)5 CSVFile (org.cpsolver.ifs.util.CSVFile)5 DataProperties (org.cpsolver.ifs.util.DataProperties)5 Comparator (java.util.Comparator)4 List (java.util.List)4