org.cpsolver.studentsct.reservation

## Class Reservation

- java.lang.Object
- - org.cpsolver.ifs.assignment.context.AbstractClassWithContext<Request,Enrollment,Reservation.ReservationContext>
  - - org.cpsolver.studentsct.reservation.Reservation

- All Implemented Interfaces:
    Comparable<Reservation>, AssignmentComparable<Reservation,Request,Enrollment>, CanHoldContext, CanInheritContext<Request,Enrollment,Reservation.ReservationContext>, HasAssignmentContext<Request,Enrollment,Reservation.ReservationContext>
  Direct Known Subclasses:
    CourseReservation, CurriculumReservation, DummyReservation, IndividualReservation, OnlineReservation, UniversalOverride

      public abstract class Reservation
      extends AbstractClassWithContext<Request,Enrollment,Reservation.ReservationContext>
      implements AssignmentComparable<Reservation,Request,Enrollment>, CanInheritContext<Request,Enrollment,Reservation.ReservationContext>

  Abstract reservation. This abstract class allow some section, courses, and other parts to be reserved to particular group of students. A reservation can be unlimited (any number of students of that particular group can attend a course, section, etc.) or with a limit (only given number of seats is reserved to the students of the particular group).
  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

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `class` | `Reservation.ReservationContext`

  - ### Field Summary

    - ### Fields inherited from interface org.cpsolver.ifs.assignment.context.CanHoldContext

      `sMaxSize`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Reservation(long id, Offering offering, int priority, boolean mustBeUsed, boolean canAssignOverLimit, boolean allowOverlap)` Constructor

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addConfig(Config config)` Add a configuration (of the offering `getOffering()`) to this reservation
    `void` | `addSection(Section section)`
    `void` | `addSection(Section section, boolean inclusive)` Add a section (of the offering `getOffering()`) to this reservation.
    `boolean` | `areRestrictionsInclusive()` Check if restrictions are inclusive (that is for each section, the reservation also contains all its parents and the configuration)
    `boolean` | `canAssignOverLimit()` True if can go over the course / config / section limit.
    `boolean` | `canBatchAssignOverLimit()` True if the batch solver can assign the reservation over the course / config / section limit.
    `boolean` | `canBreakLinkedSections()` Can break linked-section constraints when set to true
    `boolean` | `canEnroll(Assignment<Request,Enrollment> assignment, Enrollment enrollment)` True if the enrollment can be done using this reservation
    `int` | `compareTo(Assignment<Request,Enrollment> assignment, Reservation r)` Priority first, than restrictivity (more restrictive first), than availability (more available first), than id
    `int` | `compareTo(Reservation r)` Priority first, than restrictivity (more restrictive first), than id
    `Reservation.ReservationContext` | `createAssignmentContext(Assignment<Request,Enrollment> assignment)` Create a new assignment context for the given assignment.
    `Set<Config>` | `getConfigs()` One or more configurations on which the reservation is set (optional).
    `Set<Enrollment>` | `getEnrollments(Assignment<Request,Enrollment> assignment)` Enrollments assigned using this reservation
    `long` | `getId()` Reservation id
    `double` | `getLimit()` Reservation limit capped the limit cap (see `getLimitCap()`)
    `double` | `getLimit(Config config)` Reservation limit capped the limit cap (see `getLimitCap(Config)`) for a particular configuration
    `double` | `getLimitCap()` Compute limit cap (maximum number of students that can get into the offering using this reservation)
    `double` | `getLimitCap(Config config)` Compute limit cap (maximum number of students that can get into the offering using this reservation) for a particular configuration
    `Model<Request,Enrollment>` | `getModel()` Get the model.
    `Offering` | `getOffering()` Instructional offering on which the reservation is set.
    `int` | `getPriority()` Reservation priority (e.g., individual reservations first)
    `abstract double` | `getReservationLimit()` Reservation limit
    `double` | `getReservedAvailableSpace(Assignment<Request,Enrollment> assignment, Config config, Request excludeRequest)` Available reserved space for a particular config
    `double` | `getReservedAvailableSpace(Assignment<Request,Enrollment> assignment, Request excludeRequest)` Available reserved space
    `double` | `getRestrictivity()` Reservation restrictivity (estimated percentage of enrollments that include this reservation, 1.0 reservation on the whole offering)
    `Map<Subpart,Set<Section>>` | `getSections()` One or more sections on which the reservation is set (optional).
    `Set<Section>` | `getSections(Subpart subpart)` One or more sections on which the reservation is set (optional).
    `Reservation.ReservationContext` | `inheritAssignmentContext(Assignment<Request,Enrollment> assignment, Reservation.ReservationContext parentContext)` Create a new assignment context for the given assignment.
    `boolean` | `isAllowDisabled()` True if holding this reservation allows a student to attend a disabled class.
    `boolean` | `isAllowOverlap()` True if holding this reservation allows a student to have attend overlapping class.
    `boolean` | `isApplicable(Student student)` Deprecated.
    `abstract boolean` | `isApplicable(Student student, Course course)` Returns true if the student is applicable for the reservation
    `boolean` | `isExpired()` True if the reservation is expired.
    `boolean` | `isIncluded(Enrollment enrollment)` Return true if the given enrollment meets the reservation.
    `boolean` | `mustBeUsed()` If true, student must use the reservation (if applicable).
    `boolean` | `mustBeUsedIgnoreExpiration()` If true, student must use the reservation (if applicable).
    `boolean` | `neverIncluded()` No enrollment is matching this reservation when set to true
    `void` | `setAllowDisabled(boolean allowDisabled)` Set to true if holding this reservation allows a student to attend a disabled class
    `void` | `setAllowOverlap(boolean allowOverlap)` Set to true if holding this reservation allows a student to have attend overlapping class.
    `void` | `setBreakLinkedSections(boolean breakLinkedSections)` Can break linked-section constraints when set to true
    `void` | `setCanAssignOverLimit(boolean canAssignOverLimit)` Set to true if a student meeting this reservation can go over the course / config / section limit.
    `void` | `setExpired(boolean expired)` Set reservation expiration.
    `void` | `setMustBeUsed(boolean mustBeUsed)` Set to true if the student must use the reservation (if applicable)
    `void` | `setNeverIncluded(boolean neverIncluded)` No enrollment is matching this reservation when set to true
    `void` | `setPriority(int priority)` Set reservation priority (e.g., individual reservations first)

    - ### Methods inherited from class org.cpsolver.ifs.assignment.context.AbstractClassWithContext

      `getAssignmentContextReference, getContext, getContext, setAssignmentContextReference`

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

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### Reservation

          public Reservation(long id,
                             Offering offering,
                             int priority,
                             boolean mustBeUsed,
                             boolean canAssignOverLimit,
                             boolean allowOverlap)

      Constructor
      Parameters:
        `id` - reservation unique id
        `offering` - instructional offering on which the reservation is set
        `priority` - reservation priority
        `mustBeUsed` - must this reservation be used
        `canAssignOverLimit` - can assign over class / configuration / course limit
        `allowOverlap` - does this reservation allow for overlaps

  - ### Method Detail

    - #### getId

          public long getId()

      Reservation id
      Returns:
        reservation unique id

    - #### getReservationLimit

          public abstract double getReservationLimit()

      Reservation limit
      Returns:
        reservation limit, -1 for unlimited

    - #### getPriority

          public int getPriority()

      Reservation priority (e.g., individual reservations first)
      Returns:
        reservation priority

    - #### setPriority

          public void setPriority(int priority)

      Set reservation priority (e.g., individual reservations first)
      Parameters:
        `priority` - reservation priority

    - #### isApplicable

          public abstract boolean isApplicable(Student student,
                                               Course course)

      Returns true if the student is applicable for the reservation
      Parameters:
        `student` - a student
        `course` - a course
      Returns:
        true if student can use the reservation to get into the course / configuration / section

    - #### isApplicable

          @Deprecated
          public boolean isApplicable(Student student)

      Deprecated.

    - #### getOffering

          public Offering getOffering()

      Instructional offering on which the reservation is set.
      Returns:
        instructional offering

    - #### getConfigs

          public Set<Config> getConfigs()

      One or more configurations on which the reservation is set (optional).
      Returns:
        instructional offering configurations

    - #### addConfig

          public void addConfig(Config config)

      Add a configuration (of the offering `getOffering()`) to this reservation
      Parameters:
        `config` - instructional offering configuration

    - #### getSections

          public Map<Subpart,Set<Section>> getSections()

      One or more sections on which the reservation is set (optional).
      Returns:
        class restrictions

    - #### getSections

          public Set<Section> getSections(Subpart subpart)

      One or more sections on which the reservation is set (optional).
      Parameters:
        `subpart` - scheduling subpart
      Returns:
        class restrictions for the given scheduling subpart

    - #### addSection

          public void addSection(Section section,
                                 boolean inclusive)

      Add a section (of the offering `getOffering()`) to this reservation. This will also add all parent sections and the appropriate configuration to the offering.
      Parameters:
        `section` - a class restriction

    - #### addSection

          public void addSection(Section section)

    - #### isIncluded

          public boolean isIncluded(Enrollment enrollment)

      Return true if the given enrollment meets the reservation.
      Parameters:
        `enrollment` - given enrollment
      Returns:
        true if the given enrollment meets the reservation

    - #### canEnroll

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

      True if the enrollment can be done using this reservation
      Parameters:
        `assignment` - current assignment
        `enrollment` - given enrollment
      Returns:
        true if the given enrollment can be assigned

    - #### canAssignOverLimit

          public boolean canAssignOverLimit()

      True if can go over the course / config / section limit. Only to be used in the online sectioning.
      Returns:
        can assign over class / configuration / course limit

    - #### canBatchAssignOverLimit

          public boolean canBatchAssignOverLimit()

      True if the batch solver can assign the reservation over the course / config / section limit.
      Returns:
        `canAssignOverLimit()` and `StudentSectioningModel.getReservationCanAssignOverTheLimit()`

    - #### setCanAssignOverLimit

          public void setCanAssignOverLimit(boolean canAssignOverLimit)

      Set to true if a student meeting this reservation can go over the course / config / section limit.
      Parameters:
        `canAssignOverLimit` - can assign over class / configuration / course limit

    - #### mustBeUsed

          public boolean mustBeUsed()

      If true, student must use the reservation (if applicable). Expired reservations do not need to be used.
      Returns:
        must this reservation be used

    - #### mustBeUsedIgnoreExpiration

          public boolean mustBeUsedIgnoreExpiration()

      If true, student must use the reservation (if applicable). Expiration date is ignored.
      Returns:
        must this reservation be used

    - #### setMustBeUsed

          public void setMustBeUsed(boolean mustBeUsed)

      Set to true if the student must use the reservation (if applicable)
      Parameters:
        `mustBeUsed` - must this reservation be used

    - #### getRestrictivity

          public double getRestrictivity()

      Reservation restrictivity (estimated percentage of enrollments that include this reservation, 1.0 reservation on the whole offering)
      Returns:
        computed restrictivity

    - #### compareTo

          public int compareTo(Assignment<Request,Enrollment> assignment,
                               Reservation r)

      Priority first, than restrictivity (more restrictive first), than availability (more available first), than id
      Specified by:
        `compareTo` in interface `AssignmentComparable<Reservation,Request,Enrollment>`
      Parameters:
        `assignment` - current assignment
        `r` - other instance
      Returns:
        comparison of this instance and the given one

    - #### compareTo

          public int compareTo(Reservation r)

      Priority first, than restrictivity (more restrictive first), than id
      Specified by:
        `compareTo` in interface `Comparable<Reservation>`
      Specified by:
        `compareTo` in interface `AssignmentComparable<Reservation,Request,Enrollment>`

    - #### getLimitCap

          public double getLimitCap()

      Compute limit cap (maximum number of students that can get into the offering using this reservation)
      Returns:
        reservation limit cap

    - #### areRestrictionsInclusive

          public boolean areRestrictionsInclusive()

      Check if restrictions are inclusive (that is for each section, the reservation also contains all its parents and the configuration)

    - #### getLimitCap

          public double getLimitCap(Config config)

      Compute limit cap (maximum number of students that can get into the offering using this reservation) for a particular configuration
      Returns:
        reservation limit cap

    - #### getLimit

          public double getLimit()

      Reservation limit capped the limit cap (see `getLimitCap()`)
      Returns:
        reservation limit, -1 if unlimited

    - #### getLimit

          public double getLimit(Config config)

      Reservation limit capped the limit cap (see `getLimitCap(Config)`) for a particular configuration
      Parameters:
        `config` - configuration for which the limit is computed (restrictions on other configurations are ignored)
      Returns:
        reservation limit, -1 if unlimited

    - #### isAllowOverlap

          public boolean isAllowOverlap()

      True if holding this reservation allows a student to have attend overlapping class.
      Returns:
        does this reservation allow for overlaps

    - #### setAllowOverlap

          public void setAllowOverlap(boolean allowOverlap)

      Set to true if holding this reservation allows a student to have attend overlapping class.
      Parameters:
        `allowOverlap` - does this reservation allow for overlaps

    - #### isAllowDisabled

          public boolean isAllowDisabled()

      True if holding this reservation allows a student to attend a disabled class.
      Returns:
        does this reservation allow for disabled sections

    - #### setAllowDisabled

          public void setAllowDisabled(boolean allowDisabled)

      Set to true if holding this reservation allows a student to attend a disabled class
      Parameters:
        `allowDisabled` - does this reservation allow for disabled sections

    - #### setExpired

          public void setExpired(boolean expired)

      Set reservation expiration. If a reservation is expired, it works as ordinary reservation (especially the flags mutBeUsed and isAllowOverlap), except it does not block other students of getting into the offering / config / section.
      Parameters:
        `expired` - is this reservation expired

    - #### isExpired

          public boolean isExpired()

      True if the reservation is expired. If a reservation is expired, it works as ordinary reservation (especially the flags mutBeUsed and isAllowOverlap), except it does not block other students of getting into the offering / config / section.
      Returns:
        is this reservation expired

    - #### neverIncluded

          public boolean neverIncluded()

      No enrollment is matching this reservation when set to true

    - #### setNeverIncluded

          public void setNeverIncluded(boolean neverIncluded)

      No enrollment is matching this reservation when set to true

    - #### canBreakLinkedSections

          public boolean canBreakLinkedSections()

      Can break linked-section constraints when set to true

    - #### setBreakLinkedSections

          public void setBreakLinkedSections(boolean breakLinkedSections)

      Can break linked-section constraints when set to true

    - #### getModel

          public Model<Request,Enrollment> getModel()

      Description copied from class: `AbstractClassWithContext`
      Get the model. This is used to create an assignment context if needed.
      Specified by:
        `getModel` in class `AbstractClassWithContext<Request,Enrollment,Reservation.ReservationContext>`
      Returns:
        model

    - #### getReservedAvailableSpace

          public double getReservedAvailableSpace(Assignment<Request,Enrollment> assignment,
                                                  Request excludeRequest)

      Available reserved space
      Parameters:
        `assignment` - current assignment
        `excludeRequest` - excluding given request (if not null)
      Returns:
        available reserved space

    - #### getReservedAvailableSpace

          public double getReservedAvailableSpace(Assignment<Request,Enrollment> assignment,
                                                  Config config,
                                                  Request excludeRequest)

      Available reserved space for a particular config
      Parameters:
        `assignment` - current assignment
        `excludeRequest` - excluding given request (if not null)
      Returns:
        available reserved space

    - #### getEnrollments

          public Set<Enrollment> getEnrollments(Assignment<Request,Enrollment> assignment)

      Enrollments assigned using this reservation
      Parameters:
        `assignment` - current assignment
      Returns:
        assigned enrollments of this reservation

    - #### createAssignmentContext

          public Reservation.ReservationContext createAssignmentContext(Assignment<Request,Enrollment> assignment)

      Description copied from interface: `HasAssignmentContext`
      Create a new assignment context for the given assignment. If there are already some variables assigned in the value, the method should make sure that the context is appropriately initialized.
      Specified by:
        `createAssignmentContext` in interface `HasAssignmentContext<Request,Enrollment,Reservation.ReservationContext>`
      Parameters:
        `assignment` - an assignment for which there needs to be an assignment context
      Returns:
        a new instance of the assignment context, filled according to the given assignment

    - #### inheritAssignmentContext

          public Reservation.ReservationContext inheritAssignmentContext(Assignment<Request,Enrollment> assignment,
                                                                         Reservation.ReservationContext parentContext)

      Description copied from interface: `CanInheritContext`
      Create a new assignment context for the given assignment. This method can be used to clone the parent context if desired.
      Specified by:
        `inheritAssignmentContext` in interface `CanInheritContext<Request,Enrollment,Reservation.ReservationContext>`
      Parameters:
        `assignment` - an assignment for which there needs to be an assignment context
        `parentContext` - context of the parent assignment
      Returns:
        a new instance of the assignment context, filled according to the given assignment