Search in sources :

Example 11 with Enrollment

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

the class DistanceConflict method countTotalNrConflicts.

/**
     * Compute the actual number of all distance conflicts. Should be equal to
     * {@link DistanceConflict#getTotalNrConflicts(Assignment)}.
     * @param assignment current assignment
     * @return computed number of all distance conflicts
     */
public int countTotalNrConflicts(Assignment<Request, Enrollment> assignment) {
    int total = 0;
    for (Request r1 : getModel().variables()) {
        if (assignment.getValue(r1) == null || !(r1 instanceof CourseRequest))
            continue;
        Enrollment e1 = assignment.getValue(r1);
        total += nrConflicts(e1);
        for (Request r2 : r1.getStudent().getRequests()) {
            Enrollment e2 = assignment.getValue(r2);
            if (e2 == null || r1.getId() >= r2.getId() || !(r2 instanceof CourseRequest))
                continue;
            total += nrConflicts(e1, e2);
        }
    }
    return total;
}
Also used : CourseRequest(org.cpsolver.studentsct.model.CourseRequest) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Request(org.cpsolver.studentsct.model.Request) Enrollment(org.cpsolver.studentsct.model.Enrollment)

Example 12 with Enrollment

use of org.cpsolver.studentsct.model.Enrollment 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 13 with Enrollment

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

the class Test method getMinMaxAvailableEnrollmentPenalty.

/**
     * Minimum and maximum available enrollment penalty, i.e.,
     * {@link Enrollment#getPenalty()} of all available enrollments
     * @param assignment current assignment
     * @param request a course request
     * @return minimum and maximum of the available enrollment penalty
     */
public static double[] getMinMaxAvailableEnrollmentPenalty(Assignment<Request, Enrollment> assignment, CourseRequest request) {
    List<Enrollment> enrollments = request.getAvaiableEnrollments(assignment);
    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 : Enrollment(org.cpsolver.studentsct.model.Enrollment)

Example 14 with Enrollment

use of org.cpsolver.studentsct.model.Enrollment 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 15 with Enrollment

use of org.cpsolver.studentsct.model.Enrollment 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)

Aggregations

Enrollment (org.cpsolver.studentsct.model.Enrollment)59 Request (org.cpsolver.studentsct.model.Request)47 CourseRequest (org.cpsolver.studentsct.model.CourseRequest)36 ArrayList (java.util.ArrayList)19 Section (org.cpsolver.studentsct.model.Section)19 HashSet (java.util.HashSet)17 Student (org.cpsolver.studentsct.model.Student)16 FreeTimeRequest (org.cpsolver.studentsct.model.FreeTimeRequest)15 Course (org.cpsolver.studentsct.model.Course)14 HashMap (java.util.HashMap)11 DataProperties (org.cpsolver.ifs.util.DataProperties)9 Config (org.cpsolver.studentsct.model.Config)9 Set (java.util.Set)8 TreeSet (java.util.TreeSet)8 Subpart (org.cpsolver.studentsct.model.Subpart)8 Map (java.util.Map)7 DefaultSingleAssignment (org.cpsolver.ifs.assignment.DefaultSingleAssignment)7 DistanceConflict (org.cpsolver.studentsct.extension.DistanceConflict)7 Offering (org.cpsolver.studentsct.model.Offering)7 File (java.io.File)6