Search in sources :

Example 21 with Request

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

the class Test method getMinMaxEnrollmentPenalty.

/**
     * Minimum and maximum enrollment penalty, i.e.,
     * {@link Enrollment#getPenalty()} of all enrollments
     * @param request a course request
     * @return minimum and maximum of the enrollment penalty
     */
public static double[] getMinMaxEnrollmentPenalty(CourseRequest request) {
    List<Enrollment> enrollments = request.values(new EmptyAssignment<Request, Enrollment>());
    if (enrollments.isEmpty())
        return new double[] { 0, 0 };
    double min = Double.MAX_VALUE, max = Double.MIN_VALUE;
    for (Enrollment enrollment : enrollments) {
        double penalty = enrollment.getPenalty();
        min = Math.min(min, penalty);
        max = Math.max(max, penalty);
    }
    return new double[] { min, max };
}
Also used : Request(org.cpsolver.studentsct.model.Request) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Enrollment(org.cpsolver.studentsct.model.Enrollment)

Example 22 with Request

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

the class Test method batchSectioning.

/** Batch sectioning test 
     * @param cfg solver configuration
     * @return resultant solution
     **/
public static Solution<Request, Enrollment> batchSectioning(DataProperties cfg) {
    Solution<Request, Enrollment> solution = load(cfg);
    if (solution == null)
        return null;
    StudentSectioningModel model = (StudentSectioningModel) solution.getModel();
    if (cfg.getPropertyBoolean("Test.ComputeSectioningInfo", true))
        model.clearOnlineSectioningInfos();
    Progress.getInstance(model).addProgressListener(new ProgressWriter(System.out));
    solve(solution, cfg);
    return solution;
}
Also used : Request(org.cpsolver.studentsct.model.Request) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) ProgressWriter(org.cpsolver.ifs.util.ProgressWriter) Enrollment(org.cpsolver.studentsct.model.Enrollment)

Example 23 with Request

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

the class LinkedSections method computeConflicts.

/**
     * Compute conflicting enrollments. If the given enrollment contains sections of this link
     * (one for each subpart in {@link LinkedSections#getSubparts(Offering)}), another assignment
     * of this student is in a conflict, if it does not contain the appropriate sections from
     * {@link LinkedSections#getSubparts(Offering)} and {@link LinkedSections#getSections(Subpart)}.
     * 
     * @param enrollment given enrollment
     * @param assignment custom assignment 
     * @param conflicts found conflicts are given to this interface, see {@link ConflictHandler#onConflict(Enrollment)}
     */
public void computeConflicts(Enrollment enrollment, EnrollmentAssignment assignment, ConflictHandler conflicts) {
    if (enrollment == null || enrollment.getCourse() == null)
        return;
    Map<Subpart, Set<Section>> subparts = iSections.get(enrollment.getCourse().getOffering());
    if (subparts == null || subparts.isEmpty())
        return;
    boolean match = false, partial = false;
    for (Section section : enrollment.getSections()) {
        Set<Section> sections = subparts.get(section.getSubpart());
        if (sections != null) {
            if (sections.contains(section))
                match = true;
            else
                partial = true;
        }
    }
    boolean full = match && !partial;
    if (isMustBeUsed()) {
        if (!full) {
            // not full match -> conflict if there is no other linked section constraint with a full match
            // check if there is some other constraint taking care of this case
            boolean hasOtherMatch = false;
            for (LinkedSections other : enrollment.getStudent().getLinkedSections()) {
                if (other.hasFullMatch(enrollment) && nrSharedOfferings(other) > 1) {
                    hasOtherMatch = true;
                    break;
                }
            }
            // no other match -> problem
            if (!hasOtherMatch && !conflicts.onConflict(enrollment))
                return;
        }
    }
    if (full) {
        // full match -> check other enrollments
        for (int i = 0; i < enrollment.getStudent().getRequests().size(); i++) {
            Request request = enrollment.getStudent().getRequests().get(i);
            // given enrollment
            if (request.equals(enrollment.getRequest()))
                continue;
            Enrollment otherEnrollment = assignment.getEnrollment(request, i);
            // not assigned or not course request
            if (otherEnrollment == null || otherEnrollment.getCourse() == null)
                continue;
            Map<Subpart, Set<Section>> otherSubparts = iSections.get(otherEnrollment.getCourse().getOffering());
            // offering is not in the link
            if (otherSubparts == null || otherSubparts.isEmpty())
                continue;
            boolean otherMatch = false, otherPartial = false;
            for (Section section : otherEnrollment.getSections()) {
                Set<Section> otherSections = otherSubparts.get(section.getSubpart());
                if (otherSections != null) {
                    if (otherSections.contains(section))
                        otherMatch = true;
                    else
                        otherPartial = true;
                }
            }
            boolean otherFull = otherMatch && !otherPartial;
            // not full match -> conflict
            if (!otherFull && !conflicts.onConflict(otherEnrollment))
                return;
        }
    } else {
        // no or only partial match -> there should be no match in other offerings too
        for (int i = 0; i < enrollment.getStudent().getRequests().size(); i++) {
            Request request = enrollment.getStudent().getRequests().get(i);
            // given enrollment
            if (request.equals(enrollment.getRequest()))
                continue;
            Enrollment otherEnrollment = assignment.getEnrollment(request, i);
            // not assigned or not course request
            if (otherEnrollment == null || otherEnrollment.getCourse() == null)
                continue;
            Map<Subpart, Set<Section>> otherSubparts = iSections.get(otherEnrollment.getCourse().getOffering());
            // offering is not in the link
            if (otherSubparts == null || otherSubparts.isEmpty())
                continue;
            boolean otherMatch = false, otherPartial = false;
            for (Section section : otherEnrollment.getSections()) {
                Set<Section> otherSections = otherSubparts.get(section.getSubpart());
                if (otherSections != null) {
                    if (otherSections.contains(section))
                        otherMatch = true;
                    else
                        otherPartial = true;
                }
            }
            boolean otherFull = otherMatch && !otherPartial;
            // full match -> conflict
            if (otherFull && !conflicts.onConflict(otherEnrollment))
                return;
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Subpart(org.cpsolver.studentsct.model.Subpart) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Request(org.cpsolver.studentsct.model.Request) Enrollment(org.cpsolver.studentsct.model.Enrollment) Section(org.cpsolver.studentsct.model.Section) Constraint(org.cpsolver.ifs.model.Constraint)

Example 24 with Request

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

the class AssignInitialSelection method selectNeighbour.

@Override
public Neighbour<Request, Enrollment> selectNeighbour(Solution<Request, Enrollment> solution) {
    Student student = null;
    while ((student = nextStudent()) != null) {
        Progress.getInstance(solution.getModel()).incProgress();
        if (student.nrAssignedRequests(solution.getAssignment()) > 0)
            continue;
        Neighbour<Request, Enrollment> neighbour = new InitialSelection(student, solution.getAssignment()).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)

Example 25 with Request

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

the class BacktrackSelection method selectNeighbour.

@Override
public Neighbour<Request, Enrollment> selectNeighbour(Solution<Request, Enrollment> solution) {
    Request request = null;
    while ((request = nextRequest()) != null) {
        Progress.getInstance(solution.getModel()).incProgress();
        Neighbour<Request, Enrollment> n = iRBtNSel.selectNeighbour(solution, request);
        if (n != null && n.value(solution.getAssignment()) <= 0.0)
            return n;
    }
    return null;
}
Also used : Request(org.cpsolver.studentsct.model.Request) Enrollment(org.cpsolver.studentsct.model.Enrollment)

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