Search in sources :

Example 41 with Request

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

the class BacktrackSelection method init.

public void init(Solver<Request, Enrollment> solver, String name) {
    List<Request> variables = new ArrayList<Request>(iIncludeAssignedRequests ? solver.currentSolution().getModel().variables() : solver.currentSolution().getModel().unassignedVariables(solver.currentSolution().getAssignment()));
    Collections.shuffle(variables);
    iRequests = new LinkedList<Request>(variables);
    if (iRBtNSel == null) {
        try {
            iRBtNSel = new RandomizedBacktrackNeighbourSelection(solver.getProperties());
            iRBtNSel.init(solver);
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }
    Progress.getInstance(solver.currentSolution().getModel()).setPhase(name, variables.size());
}
Also used : RandomizedBacktrackNeighbourSelection(org.cpsolver.studentsct.heuristics.RandomizedBacktrackNeighbourSelection) ArrayList(java.util.ArrayList) Request(org.cpsolver.studentsct.model.Request)

Example 42 with Request

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

the class Test method updateSpace.

public static void updateSpace(Assignment<Request, Enrollment> assignment, Enrollment enrollment, boolean increment) {
    if (enrollment == null || !enrollment.isCourseRequest())
        return;
    for (Section section : enrollment.getSections()) section.setSpaceHeld(section.getSpaceHeld() + (increment ? 1.0 : -1.0));
    List<Enrollment> feasibleEnrollments = new ArrayList<Enrollment>();
    int totalLimit = 0;
    for (Enrollment enrl : enrollment.getRequest().values(assignment)) {
        if (!enrl.getCourse().equals(enrollment.getCourse()))
            continue;
        boolean overlaps = false;
        for (Request otherRequest : enrollment.getRequest().getStudent().getRequests()) {
            if (otherRequest.equals(enrollment.getRequest()) || !(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 change = enrollment.getRequest().getWeight() / (totalLimit > 0 ? totalLimit : feasibleEnrollments.size());
    for (Enrollment feasibleEnrollment : feasibleEnrollments) for (Section section : feasibleEnrollment.getSections()) {
        if (totalLimit > 0) {
            section.setSpaceExpected(section.getSpaceExpected() + (increment ? +change : -change) * feasibleEnrollment.getLimit());
        } else {
            section.setSpaceExpected(section.getSpaceExpected() + (increment ? +change : -change));
        }
    }
}
Also used : CourseRequest(org.cpsolver.studentsct.model.CourseRequest) ArrayList(java.util.ArrayList) Request(org.cpsolver.studentsct.model.Request) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) FreeTimeRequest(org.cpsolver.studentsct.model.FreeTimeRequest) Enrollment(org.cpsolver.studentsct.model.Enrollment) Section(org.cpsolver.studentsct.model.Section)

Example 43 with Request

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

the class EnrollmentSelection method isAllowed.

/** true, if it is allowed to assign given value 
     * @param assignment current assignment
     * @param value given value
     * @param conflicts conflicting assignments
     * @return true if it is allowed
     **/
public boolean isAllowed(Assignment<Request, Enrollment> assignment, Enrollment value, Set<Enrollment> conflicts) {
    if (value == null)
        return true;
    StudentSectioningModel model = (StudentSectioningModel) value.variable().getModel();
    if (model.getNrLastLikeRequests(false) == 0 || model.getNrRealRequests(false) == 0)
        return true;
    Request request = value.variable();
    if (request.getStudent().isDummy()) {
        if (conflicts == null)
            conflicts = value.variable().getModel().conflictValues(assignment, value);
        for (Enrollment conflict : conflicts) {
            if (!conflict.getRequest().getStudent().isDummy())
                return false;
        }
    } else {
        if (conflicts == null)
            conflicts = value.variable().getModel().conflictValues(assignment, value);
        if (conflicts.size() > (assignment.getValue(request) == null ? 1 : 0))
            return false;
    }
    return true;
}
Also used : Request(org.cpsolver.studentsct.model.Request) Enrollment(org.cpsolver.studentsct.model.Enrollment) StudentSectioningModel(org.cpsolver.studentsct.StudentSectioningModel)

Example 44 with Request

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

the class OnlineSelection method updateSpace.

/** Update online sectioning info after the given student is sectioned 
     * @param assignment current assignment
     * @param student student in question
     **/
public void updateSpace(Assignment<Request, Enrollment> assignment, Student student) {
    for (Request request : student.getRequests()) {
        if (!(request instanceof CourseRequest))
            continue;
        CourseRequest courseRequest = (CourseRequest) request;
        Enrollment enrollment = assignment.getValue(courseRequest);
        if (enrollment == null)
            // not enrolled --> no update
            return;
        for (Section section : enrollment.getSections()) {
            section.setSpaceHeld(section.getSpaceHeld() - courseRequest.getWeight());
        // sLog.debug("  -- space held for "+section+" decreased by 1 (to "+section.getSpaceHeld()+")");
        }
        List<Enrollment> feasibleEnrollments = new ArrayList<Enrollment>();
        for (Enrollment enrl : courseRequest.values(assignment)) {
            boolean overlaps = false;
            for (Request otherRequest : courseRequest.getStudent().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);
        }
        double decrement = courseRequest.getWeight() / feasibleEnrollments.size();
        for (Enrollment feasibleEnrollment : feasibleEnrollments) {
            for (Section section : feasibleEnrollment.getSections()) {
                section.setSpaceExpected(section.getSpaceExpected() - decrement);
            // sLog.debug("  -- space expected for "+section+" decreased by "+decrement+" (to "+section.getSpaceExpected()+")");
            }
        }
    }
}
Also used : CourseRequest(org.cpsolver.studentsct.model.CourseRequest) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Request(org.cpsolver.studentsct.model.Request) ArrayList(java.util.ArrayList) Enrollment(org.cpsolver.studentsct.model.Enrollment) Section(org.cpsolver.studentsct.model.Section)

Example 45 with Request

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

the class PriorityConstructionSelection method branchAndBound.

/**
     * Find best solution for the next student using {@link BranchBoundSelection}.
     * @param solution current selection
     * @return generated neighbour
     */
public Neighbour<Request, Enrollment> branchAndBound(Solution<Request, Enrollment> solution) {
    while (iStudentsEnumeration.hasNext()) {
        Student student = iStudentsEnumeration.next();
        Progress.getInstance(solution.getModel()).incProgress();
        /*
            if (student.nrRequests() < iCycle) {
                // not enough requests -> nothing to improve -> skip
                continue;
            }
            if (student.nrAssignedRequests() + 1 < iCycle) {
                // previous step cycle already did not improve the assignment -> skip
                continue;
            }
            */
        Neighbour<Request, Enrollment> neighbour = iBranchBoundSelection.getSelection(solution.getAssignment(), student).select();
        if (neighbour != null)
            return neighbour;
    }
    return null;
}
Also used : Request(org.cpsolver.studentsct.model.Request) Enrollment(org.cpsolver.studentsct.model.Enrollment) Student(org.cpsolver.studentsct.model.Student)

Aggregations

Request (org.cpsolver.studentsct.model.Request)65 CourseRequest (org.cpsolver.studentsct.model.CourseRequest)51 Enrollment (org.cpsolver.studentsct.model.Enrollment)47 FreeTimeRequest (org.cpsolver.studentsct.model.FreeTimeRequest)23 Section (org.cpsolver.studentsct.model.Section)22 ArrayList (java.util.ArrayList)21 Student (org.cpsolver.studentsct.model.Student)21 Course (org.cpsolver.studentsct.model.Course)20 HashSet (java.util.HashSet)18 HashMap (java.util.HashMap)14 Subpart (org.cpsolver.studentsct.model.Subpart)10 Map (java.util.Map)9 DataProperties (org.cpsolver.ifs.util.DataProperties)9 Config (org.cpsolver.studentsct.model.Config)8 Offering (org.cpsolver.studentsct.model.Offering)8 Set (java.util.Set)7 DefaultSingleAssignment (org.cpsolver.ifs.assignment.DefaultSingleAssignment)7 File (java.io.File)6 IOException (java.io.IOException)6 TreeSet (java.util.TreeSet)6