Search in sources :

Example 16 with Reservation

use of org.cpsolver.studentsct.reservation.Reservation in project cpsolver by UniTime.

the class ReservationLimit method inConflict.

/**
     * A given enrollment is conflicting, if the config's enrollment (computed by
     * {@link ConfigLimit#getEnrollmentWeight(Assignment, Config, Request)}) exceeds the
     * limit.
     * 
     * @param enrollment
     *            {@link Enrollment} that is being considered
     * @return true, if the enrollment cannot be assigned without exceeding the limit
     */
@Override
public boolean inConflict(Assignment<Request, Enrollment> assignment, Enrollment enrollment) {
    // enrollment's config
    Config config = enrollment.getConfig();
    // exclude free time requests
    if (config == null)
        return false;
    // enrollment's reservation
    Reservation reservation = enrollment.getReservation();
    // check reservation
    if (reservation != null) {
        // unlimited reservation
        if (reservation.getLimit() < 0)
            return false;
        // check remaning space
        if (reservation.getReservedAvailableSpace(assignment, enrollment.getRequest()) < enrollment.getRequest().getWeight())
            return true;
        // check reservation can assign over the limit
        if (reservation.canBatchAssignOverLimit())
            return false;
        // if not configuration reservation, check configuration unreserved space too
        return (!hasConfigReservation(enrollment) && getUnreservedSpace(assignment, config, enrollment.getRequest(), true) < 0.0);
    } else {
        // check unreserved space;
        return config.getOffering().getTotalUnreservedSpace() < enrollment.getRequest().getWeight() || config.getTotalUnreservedSpace() < enrollment.getRequest().getWeight() || getUnreservedSpace(assignment, config, enrollment.getRequest(), false) < 0.0;
    }
}
Also used : Reservation(org.cpsolver.studentsct.reservation.Reservation) Config(org.cpsolver.studentsct.model.Config)

Example 17 with Reservation

use of org.cpsolver.studentsct.reservation.Reservation in project cpsolver by UniTime.

the class Config method getTotalUnreservedSpaceNoCache.

private double getTotalUnreservedSpaceNoCache() {
    // (in which case there is no unreserved space)
    if (getLimit() < 0) {
        // exclude reservations that are not directly set on this section
        for (Reservation r : getConfigReservations()) {
            // ignore expired reservations
            if (r.isExpired())
                continue;
            // there is an unlimited reservation -> no unreserved space
            if (r.getLimit() < 0)
                return 0.0;
        }
        return Double.MAX_VALUE;
    }
    // we need to check all reservations linked with this section
    double available = getLimit(), reserved = 0, exclusive = 0;
    Set<Config> configs = new HashSet<Config>();
    reservations: for (Reservation r : getConfigReservations()) {
        // ignore expired reservations
        if (r.isExpired())
            continue;
        // unlimited reservation -> no unreserved space
        if (r.getLimit() < 0)
            return 0.0;
        for (Config s : r.getConfigs()) {
            if (s.equals(this))
                continue;
            if (s.getLimit() < 0)
                continue reservations;
            if (configs.add(s))
                available += s.getLimit();
        }
        reserved += r.getLimit();
        if (r.getConfigs().size() == 1)
            exclusive += r.getLimit();
    }
    return Math.min(available - reserved, getLimit() - exclusive);
}
Also used : Reservation(org.cpsolver.studentsct.reservation.Reservation) HashSet(java.util.HashSet)

Aggregations

Reservation (org.cpsolver.studentsct.reservation.Reservation)17 HashSet (java.util.HashSet)7 Config (org.cpsolver.studentsct.model.Config)5 ArrayList (java.util.ArrayList)4 Course (org.cpsolver.studentsct.model.Course)4 Section (org.cpsolver.studentsct.model.Section)4 CourseReservation (org.cpsolver.studentsct.reservation.CourseReservation)4 HashMap (java.util.HashMap)3 Set (java.util.Set)3 Enrollment (org.cpsolver.studentsct.model.Enrollment)3 Hashtable (java.util.Hashtable)2 TreeSet (java.util.TreeSet)2 AssignmentMap (org.cpsolver.ifs.assignment.AssignmentMap)2 CourseRequest (org.cpsolver.studentsct.model.CourseRequest)2 FreeTimeRequest (org.cpsolver.studentsct.model.FreeTimeRequest)2 Offering (org.cpsolver.studentsct.model.Offering)2 Subpart (org.cpsolver.studentsct.model.Subpart)2 CurriculumReservation (org.cpsolver.studentsct.reservation.CurriculumReservation)2 DummyReservation (org.cpsolver.studentsct.reservation.DummyReservation)2 GroupReservation (org.cpsolver.studentsct.reservation.GroupReservation)2