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;
}
}
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);
}
Aggregations