org.cpsolver.studentsct.constraint

## Class ReservationLimit

- java.lang.Object
- - org.cpsolver.ifs.model.Constraint<V,T>
  - - org.cpsolver.ifs.model.GlobalConstraint<Request,Enrollment>
    - - org.cpsolver.studentsct.constraint.ReservationLimit

- All Implemented Interfaces:
    Comparable<Constraint<Request,Enrollment>>

      public class ReservationLimit
      extends GlobalConstraint<Request,Enrollment>

  Reservation limit constraint. This global constraint ensures that a limit of each reservation is not exceeded. This means that the total sum of weights of course requests (see `Request.getWeight()`) enrolled into a reservation is below the reservation's limit (see `Reservation.getLimit()`). It also ensures that the desired space is reserved in the enrollment's offering and configuration.
  Parameters:

  Related Solver Parameters
  Parameter | Type | Comment
  --- | --- | ---
  ReservationLimit.PreferDummyStudents | `Boolean` | If true, requests of dummy (last-like) students are preferred to be selected as conflicting.

  Version:
    StudentSct 1.3 (Student Sectioning)
    Copyright (C) 2007 - 2014 Tomáš Müller
    muller@unitime.org
    http://muller.unitime.org
    This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
    This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    You should have received a copy of the GNU Lesser General Public License along with this library; if not see http://www.gnu.org/licenses/.
  Author:
    Tomáš Müller

- - ### Field Summary

    - ### Fields inherited from class org.cpsolver.ifs.model.Constraint

      `iConstraintListeners, iId`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ReservationLimit(DataProperties cfg)` Constructor

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `computeConflicts(Assignment<Request,Enrollment> assignment, Enrollment enrollment, Set<Enrollment> conflicts)` A given enrollment is conflicting, if the reservation's remaining available space (computed by `Reservation.getReservedAvailableSpace(Assignment, Request)`) is below the requests weight `Request.getWeight()`.
    `static double` | `getUnreservedSpace(Assignment<Request,Enrollment> assignment, Config config, Request request, boolean hasReservation)` Remaining unreserved space in a config if the given request is assigned.
    `boolean` | `inConflict(Assignment<Request,Enrollment> assignment, Enrollment enrollment)` A given enrollment is conflicting, if the config's enrollment (computed by `ConfigLimit.getEnrollmentWeight(Assignment, Config, Request)`) exceeds the limit.
    `String` | `toString()`

    - ### Methods inherited from class org.cpsolver.ifs.model.GlobalConstraint

      `addVariable, assigned, assignedVariables, countAssignedVariables, removeVariable, unassigned, variables`

    - ### Methods inherited from class org.cpsolver.ifs.model.Constraint

      `addConstraintListener, compareTo, computeConflictsNoForwardCheck, constraintListeners, countVariables, equals, getDescription, getId, getModel, getName, hashCode, isConsistent, isHard, removeConstraintListener, setModel`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### ReservationLimit

          public ReservationLimit(DataProperties cfg)

      Constructor
      Parameters:
        `cfg` - solver configuration

  - ### Method Detail

    - #### getUnreservedSpace

          public static double getUnreservedSpace(Assignment<Request,Enrollment> assignment,
                                                  Config config,
                                                  Request request,
                                                  boolean hasReservation)

      Remaining unreserved space in a config if the given request is assigned. In order to overcome rounding problems with last-like students ( e.g., 5 students are projected to two sections of limit 2 -- each section can have up to 3 of these last-like students), the weight of the request with the highest weight in the section is changed to a small nominal weight.
      Parameters:
        `assignment` - current assignment
        `config` - a config that is of concern
        `request` - a request of a student to be assigned containing the given section
        `hasReservation` - true if the enrollment in question has a reservation (only not matching the given configuration)
      Returns:
        config's new unreserved space

    - #### computeConflicts

          public void computeConflicts(Assignment<Request,Enrollment> assignment,
                                       Enrollment enrollment,
                                       Set<Enrollment> conflicts)

      A given enrollment is conflicting, if the reservation's remaining available space (computed by `Reservation.getReservedAvailableSpace(Assignment, Request)`) is below the requests weight `Request.getWeight()`.
      If the limit is breached, one or more existing enrollments are selected as conflicting until there is enough space in the reservation. Similarly, if the enrollment does not have the reservation, it is checked that there is enough unreserved space in the desired configuration.
      Specified by:
        `computeConflicts` in class `Constraint<Request,Enrollment>`
      Parameters:
        `enrollment` - `Enrollment` that is being considered
        `conflicts` - all computed conflicting requests are added into this set
        `assignment` - current assignment

    - #### inConflict

          public boolean inConflict(Assignment<Request,Enrollment> assignment,
                                    Enrollment enrollment)

      A given enrollment is conflicting, if the config's enrollment (computed by `ConfigLimit.getEnrollmentWeight(Assignment, Config, Request)`) exceeds the limit.
      Overrides:
        `inConflict` in class `Constraint<Request,Enrollment>`
      Parameters:
        `enrollment` - `Enrollment` that is being considered
        `assignment` - current assignment
      Returns:
        true, if the enrollment cannot be assigned without exceeding the limit

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`