Search in sources :

Example 66 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) FreeTimeRequest(org.cpsolver.studentsct.model.FreeTimeRequest) Request(org.cpsolver.studentsct.model.Request) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Enrollment(org.cpsolver.studentsct.model.Enrollment)

Example 67 with CourseRequest

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

the class MultiCriteriaBranchAndBoundSelection method isAllowed.

public boolean isAllowed(int idx, Enrollment enrollment) {
    if (enrollment.isCourseRequest()) {
        CourseRequest request = (CourseRequest) enrollment.getRequest();
        if (iRequiredUnassinged != null && iRequiredUnassinged.contains(request))
            return false;
        Config reqConfig = iRequiredConfig.get(request);
        if (reqConfig != null) {
            if (!reqConfig.equals(enrollment.getConfig()))
                return false;
            Hashtable<Subpart, Section> reqSections = iRequiredSection.get(request);
            for (Section section : enrollment.getSections()) {
                Section reqSection = reqSections.get(section.getSubpart());
                if (reqSection == null)
                    continue;
                if (!section.equals(reqSection))
                    return false;
            }
        }
    } else if (iRequiredFreeTimes.contains(enrollment.getRequest())) {
        if (enrollment.getAssignments() == null || enrollment.getAssignments().isEmpty())
            return false;
    }
    return true;
}
Also used : CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Config(org.cpsolver.studentsct.model.Config) Subpart(org.cpsolver.studentsct.model.Subpart) Section(org.cpsolver.studentsct.model.Section)

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