org.cpsolver.studentsct.model

## Class CourseRequest

- java.lang.Object
- - org.cpsolver.ifs.model.Variable<V,T>
  - - org.cpsolver.ifs.assignment.context.VariableWithContext<Request,Enrollment,Request.RequestContext>
    - - org.cpsolver.studentsct.model.Request
      - - org.cpsolver.studentsct.model.CourseRequest

- All Implemented Interfaces:
    Comparable<Request>, CanHoldContext, HasAssignmentContext<Request,Enrollment,Request.RequestContext>

      public class CourseRequest
      extends Request

  Representation of a request of a student for one or more course. A student requests one of the given courses, preferably the first one.
  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/interfaces inherited from class org.cpsolver.studentsct.model.Request

      `Request.RequestContext, Request.RequestPriority`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static boolean` | `sSameTimePrecise`

    - ### Fields inherited from class org.cpsolver.studentsct.model.Request

      `sCacheValues`

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

      `iIndex, iValue`

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

      `sMaxSize`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `CourseRequest(long id, int priority, boolean alternative, Student student, List<Course> courses, boolean waitlist, boolean critical, Long timeStamp)` Constructor
    `CourseRequest(long id, int priority, boolean alternative, Student student, List<Course> courses, boolean waitlist, Long timeStamp)` Constructor
    `CourseRequest(long id, int priority, boolean alternative, Student student, List<Course> courses, boolean waitlist, Request.RequestPriority importance, Long timeStamp)` Constructor

  - ### Method Summary

    All Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addRequestGroup(RequestGroup group)` Add request group to this request.
    `void` | `clearCache()` Clear cached min/max penalties and cached bound
    `void` | `clearReservationCache()` Clear reservation information that was cached on this section
    `void` | `clearRestrictionCache()` Clear restriction information that was cached on this request
    `List<Enrollment>` | `computeEnrollments(Assignment<Request,Enrollment> assignment)` Return all possible enrollments.
    `List<Enrollment>` | `computeRandomEnrollments(Assignment<Request,Enrollment> assignment, int limitEachConfig)` Return a subset of all enrollments -- randomly select only up to limitEachConfig enrollments of each config.
    `Enrollment` | `createEnrollment(Assignment<Request,Enrollment> assignment, Set<? extends SctAssignment> sections)` Create enrollment for the given list of sections.
    `Enrollment` | `createEnrollment(Course course, Set<? extends SctAssignment> sections, Reservation reservation)` Create enrollment for the given list of sections.
    `Enrollment` | `createEnrollment(Set<? extends SctAssignment> sections, Reservation reservation)` Create enrollment for the given list of sections.
    `boolean` | `equals(Object o)`
    `List<Enrollment>` | `getAvaiableEnrollments(Assignment<Request,Enrollment> assignment)` Return all enrollments that are available
    `List<Enrollment>` | `getAvaiableEnrollmentsSkipSameTime(Assignment<Request,Enrollment> assignment)` Return all enrollments that are available, pick only the first section of the sections with the same time (of each subpart, `Section` comparator is used)
    `double` | `getBound()` Estimated bound for this request -- it estimates the smallest value among all possible enrollments
    `Config` | `getConfig(long configId)` Return configuration of the requested courses with the given id
    `Course` | `getCourse(long courseId)` Return course of the requested courses with the given id
    `List<Course>` | `getCourses()` List of requested courses (in the correct order -- first is the requested course, second is the first alternative, etc.)
    `List<Enrollment>` | `getEnrollmentsSkipSameTime(Assignment<Request,Enrollment> assignment)` Return all possible enrollments, but pick only the first section of the sections with the same time (of each subpart, `Section` comparator is used).
    `Enrollment` | `getFixedValue()`
    `protected int` | `getMaxDomainSize()` Maximal domain size (i.e., number of enrollments of a course request), -1 if there is no limit.
    `double` | `getMaxPenalty()` Maximal penalty (maximum of `Offering.getMaxPenalty()` among requested courses)
    `float` | `getMinCredit()` Smallest credit provided by this request
    `double` | `getMinPenalty()` Minimal penalty (minimum of `Offering.getMinPenalty()` among requested courses)
    `String` | `getName()` Request name: A for alternative, 1 + priority, (w) when wait-list, list of course names
    `Set<RequestGroup>` | `getRequestGroups()` Lists request groups of this request
    `Request.RequestPriority` | `getRequestPriority()` Importance of the request.
    `Set<Choice>` | `getRequiredChoices()` Required choices
    `List<Reservation>` | `getReservations(Course course)` Get reservations for this course requests
    `List<Restriction>` | `getRestrictions(Course course)` Get restrictions for this course requests
    `Section` | `getSection(long sectionId)` Return section of the requested courses with the given id
    `Set<Choice>` | `getSelectedChoices()` Selected choices
    `List<Enrollment>` | `getSelectedEnrollments(Assignment<Request,Enrollment> assignment, boolean availableOnly)` Return all enrollments of the first course that are selected ( `isSelected(Section)` is true)
    `TreeSet<Reservation>` | `getSortedReservations(Assignment<Request,Enrollment> assignment, Course course)` Get reservations for this course requests ordered using `Reservation.compareTo(Assignment, Reservation)`
    `Subpart` | `getSubpart(long subpartId)` Return subpart of the requested courses with the given id
    `Long` | `getTimeStamp()` Time stamp of the request
    `Set<Choice>` | `getWaitlistedChoices()` Wait-listed choices
    `boolean` | `hasChildren()` Check if this request is `CourseRequest` and a parent of some other course
    `boolean` | `hasCourse(Course course)` Check if this request is `CourseRequest` and contains the given course.
    `boolean` | `hasReservations()` Return true if there is a reservation for a course of this request
    `boolean` | `hasRestrictions(Course course)` Return true if there is a restriction for a course of this request
    `boolean` | `hasSelection()` Return true if this request has any selection
    `boolean` | `hasSelection(Section section)` Return true when the given section has a preference (i.e., there is a matching selection), or when there is a section preference for a different configuration
    `boolean` | `isAssigned(Assignment<Request,Enrollment> assignment)` Return true if request is assigned.
    `boolean` | `isFixed()`
    `boolean` | `isMPP()` Return true if this request can track MPP
    `boolean` | `isNotAllowed(Course course, Config config)` Return true when there are restrictions for a course of this course request and the given config does not meet any of them
    `boolean` | `isNotAllowed(Course course, Section section)` Return true when there are restrictions for a course of this course request and the given section does not meet any of them
    `boolean` | `isNotAllowed(Enrollment e)` Return true when there are restrictions for a course of this course request and the given enrollment does not meet any of them
    `boolean` | `isRequired(Section section)` Return true when the given section is required (i.e., its choice is among required choices, or there are no requirements)
    `boolean` | `isSelected(Section section)` Return true when the given section is selected (i.e., its choice is among selected choices)
    `boolean` | `isWaitlist()` True if the student can be put on a wait-list (no alternative course request will be given instead)
    `boolean` | `isWaitlisted(Section section)` Return true when the given section is wait-listed (i.e., its choice is among wait-listed choices)
    `void` | `removeRequestGroup(RequestGroup group)` Removed request group from this request.
    `void` | `setCritical(boolean critical)` Deprecated.
    `void` | `setFixedValue(Enrollment constant)`
    `void` | `setRequestPriority(Request.RequestPriority priority)`
    `void` | `setWaitlist(boolean waitlist)` True if the student can be put on a wait-list (no alternative course request will be given instead)
    `String` | `toString()`
    `void` | `variableAssigned(Assignment<Request,Enrollment> assignment, long iteration, Enrollment enrollment)` Assign given enrollment to this request.
    `void` | `variableUnassigned(Assignment<Request,Enrollment> assignment, long iteration, Enrollment enrollment)` Unassign currently assigned enrollment from this request.

    - ### Methods inherited from class org.cpsolver.studentsct.model.Request

      `compareTo, createAssignmentContext, getId, getPriority, getStudent, getWeight, hashCode, isAlternative, isCritical, setPriority, setWeight, values`

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

      `getAssignmentContextReference, getContext, getContext, setAssignmentContextReference, setModel`

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

      `addContstraint, addVariableListener, assign, constraints, constraintVariables, getAssignment, getAssignment, getAssignments, getBestAssignment, getBestAssignmentIteration, getDescription, getExtra, getIndex, getInitialAssignment, getLastIteration, getModel, getVariableListeners, hardConstraints, hasAssignment, hasAssignment, hasInitialAssignment, hasValues, removeContstraint, removeInitialValue, removeValue, removeVariableListener, setAssignment, setBestAssignment, setExtra, setIndex, setInitialAssignment, setLastIteration, setValues, softConstraints, unassign, values`

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

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

- - ### Field Detail

    - #### sSameTimePrecise

          public static boolean sSameTimePrecise

  - ### Constructor Detail

    - #### CourseRequest

          public CourseRequest(long id,
                               int priority,
                               boolean alternative,
                               Student student,
                               List<Course> courses,
                               boolean waitlist,
                               boolean critical,
                               Long timeStamp)

      Constructor
      Parameters:
        `id` - request unique id
        `priority` - request priority
        `alternative` - true if the request is alternative (alternative request can be assigned instead of a non-alternative course requests, if it is left unassigned)
        `student` - appropriate student
        `courses` - list of requested courses (in the correct order -- first is the requested course, second is the first alternative, etc.)
        `waitlist` - time stamp of the request if the student can be put on a wait-list (no alternative course request will be given instead)
        `critical` - is the course request is critical for the student in order to move forward in their degree
        `timeStamp` - request time stamp

    - #### CourseRequest

          public CourseRequest(long id,
                               int priority,
                               boolean alternative,
                               Student student,
                               List<Course> courses,
                               boolean waitlist,
                               Request.RequestPriority importance,
                               Long timeStamp)

      Constructor
      Parameters:
        `id` - request unique id
        `priority` - request priority
        `alternative` - true if the request is alternative (alternative request can be assigned instead of a non-alternative course requests, if it is left unassigned)
        `student` - appropriate student
        `courses` - list of requested courses (in the correct order -- first is the requested course, second is the first alternative, etc.)
        `waitlist` - time stamp of the request if the student can be put on a wait-list (no alternative course request will be given instead)
        `importance` - request priority
        `timeStamp` - request time stamp

    - #### CourseRequest

          public CourseRequest(long id,
                               int priority,
                               boolean alternative,
                               Student student,
                               List<Course> courses,
                               boolean waitlist,
                               Long timeStamp)

      Constructor
      Parameters:
        `id` - request unique id
        `priority` - request priority
        `alternative` - true if the request is alternative (alternative request can be assigned instead of a non-alternative course requests, if it is left unassigned)
        `student` - appropriate student
        `courses` - list of requested courses (in the correct order -- first is the requested course, second is the first alternative, etc.)
        `waitlist` - time stamp of the request if the student can be put on a wait-list (no alternative course request will be given instead)
        `timeStamp` - request time stamp

  - ### Method Detail

    - #### getCourses

          public List<Course> getCourses()

      List of requested courses (in the correct order -- first is the requested course, second is the first alternative, etc.)
      Returns:
        requested course offerings

    - #### createEnrollment

          public Enrollment createEnrollment(Set<? extends SctAssignment> sections,
                                             Reservation reservation)

      Create enrollment for the given list of sections. The list of sections needs to be correct, i.e., a section for each subpart of a configuration of one of the requested courses.
      Parameters:
        `sections` - selected sections
        `reservation` - selected reservation
      Returns:
        enrollment

    - #### createEnrollment

          public Enrollment createEnrollment(Course course,
                                             Set<? extends SctAssignment> sections,
                                             Reservation reservation)

      Create enrollment for the given list of sections. The list of sections needs to be correct, i.e., a section for each subpart of a configuration of one of the requested courses.
      Parameters:
        `course` - selected course
        `sections` - selected sections
        `reservation` - selected reservation
      Returns:
        enrollment

    - #### createEnrollment

          public Enrollment createEnrollment(Assignment<Request,Enrollment> assignment,
                                             Set<? extends SctAssignment> sections)

      Create enrollment for the given list of sections. The list of sections needs to be correct, i.e., a section for each subpart of a configuration of one of the requested courses.
      Parameters:
        `assignment` - current assignment (to guess the reservation)
        `sections` - selected sections
      Returns:
        enrollment

    - #### getMaxDomainSize

          protected int getMaxDomainSize()

      Maximal domain size (i.e., number of enrollments of a course request), -1 if there is no limit.
      Returns:
        maximal domain size, -1 if unlimited

    - #### computeEnrollments

          public List<Enrollment> computeEnrollments(Assignment<Request,Enrollment> assignment)

      Return all possible enrollments.
      Specified by:
        `computeEnrollments` in class `Request`
      Parameters:
        `assignment` - current assignment
      Returns:
        list of all enrollments

    - #### computeRandomEnrollments

          public List<Enrollment> computeRandomEnrollments(Assignment<Request,Enrollment> assignment,
                                                           int limitEachConfig)

      Return a subset of all enrollments -- randomly select only up to limitEachConfig enrollments of each config.
      Parameters:
        `assignment` - current assignment
        `limitEachConfig` - maximal number of enrollments in each configuration
      Returns:
        computed enrollments

    - #### getAvaiableEnrollments

          public List<Enrollment> getAvaiableEnrollments(Assignment<Request,Enrollment> assignment)

      Return all enrollments that are available
      Parameters:
        `assignment` - current assignment
      Returns:
        all available enrollments

    - #### getSelectedEnrollments

          public List<Enrollment> getSelectedEnrollments(Assignment<Request,Enrollment> assignment,
                                                         boolean availableOnly)

      Return all enrollments of the first course that are selected ( `isSelected(Section)` is true)
      Parameters:
        `assignment` - current assignment
        `availableOnly` - pick only available sections
      Returns:
        selected enrollments

    - #### getAvaiableEnrollmentsSkipSameTime

          public List<Enrollment> getAvaiableEnrollmentsSkipSameTime(Assignment<Request,Enrollment> assignment)

      Return all enrollments that are available, pick only the first section of the sections with the same time (of each subpart, `Section` comparator is used)
      Parameters:
        `assignment` - current assignment
      Returns:
        available enrollments

    - #### getEnrollmentsSkipSameTime

          public List<Enrollment> getEnrollmentsSkipSameTime(Assignment<Request,Enrollment> assignment)

      Return all possible enrollments, but pick only the first section of the sections with the same time (of each subpart, `Section` comparator is used).
      Parameters:
        `assignment` - current assignment
      Returns:
        computed enrollments

    - #### getWaitlistedChoices

          public Set<Choice> getWaitlistedChoices()

      Wait-listed choices
      Returns:
        wait-listed choices

    - #### isWaitlisted

          public boolean isWaitlisted(Section section)

      Return true when the given section is wait-listed (i.e., its choice is among wait-listed choices)
      Parameters:
        `section` - given section
      Returns:
        true if the given section matches the wait-listed choices

    - #### getSelectedChoices

          public Set<Choice> getSelectedChoices()

      Selected choices
      Returns:
        selected choices

    - #### isSelected

          public boolean isSelected(Section section)

      Return true when the given section is selected (i.e., its choice is among selected choices)
      Parameters:
        `section` - given section
      Returns:
        true if the given section matches the selected choices

    - #### hasSelection

          public boolean hasSelection(Section section)

      Return true when the given section has a preference (i.e., there is a matching selection), or when there is a section preference for a different configuration
      Parameters:
        `section` - given section
      Returns:
        true if the there is a matching choice for the given section that is of the same offering

    - #### getRequiredChoices

          public Set<Choice> getRequiredChoices()

      Required choices
      Returns:
        required choices

    - #### isRequired

          public boolean isRequired(Section section)

      Return true when the given section is required (i.e., its choice is among required choices, or there are no requirements)
      Parameters:
        `section` - given section
      Returns:
        true if the given section matches the required choices

    - #### getName

          public String getName()

      Request name: A for alternative, 1 + priority, (w) when wait-list, list of course names
      Overrides:
        `getName` in class `Variable<Request,Enrollment>`
      Returns:
        variable name

    - #### isWaitlist

          public boolean isWaitlist()

      True if the student can be put on a wait-list (no alternative course request will be given instead)
      Returns:
        true if the request can be wait-listed

    - #### setWaitlist

          public void setWaitlist(boolean waitlist)

      True if the student can be put on a wait-list (no alternative course request will be given instead)
      Parameters:
        `waitlist` - true if the request can be wait-listed

    - #### setCritical

          @Deprecated
          public void setCritical(boolean critical)

      Deprecated.
      True if the course request is critical for the student in order to move forward in their degree
      Parameters:
        `critical` - true if the request is critical

    - #### getTimeStamp

          public Long getTimeStamp()

      Time stamp of the request
      Returns:
        request time stamp

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Variable<Request,Enrollment>`

    - #### getCourse

          public Course getCourse(long courseId)

      Return course of the requested courses with the given id
      Parameters:
        `courseId` - course offering id
      Returns:
        course of the given id

    - #### getConfig

          public Config getConfig(long configId)

      Return configuration of the requested courses with the given id
      Parameters:
        `configId` - instructional offering configuration unique id
      Returns:
        config of the given id

    - #### getSubpart

          public Subpart getSubpart(long subpartId)

      Return subpart of the requested courses with the given id
      Parameters:
        `subpartId` - scheduling subpart unique id
      Returns:
        subpart of the given id

    - #### getSection

          public Section getSection(long sectionId)

      Return section of the requested courses with the given id
      Parameters:
        `sectionId` - class unique id
      Returns:
        section of the given id

    - #### getMinPenalty

          public double getMinPenalty()

      Minimal penalty (minimum of `Offering.getMinPenalty()` among requested courses)
      Returns:
        minimal penalty

    - #### getMaxPenalty

          public double getMaxPenalty()

      Maximal penalty (maximum of `Offering.getMaxPenalty()` among requested courses)
      Returns:
        maximal penalty

    - #### clearCache

          public void clearCache()

      Clear cached min/max penalties and cached bound

    - #### getBound

          public double getBound()

      Estimated bound for this request -- it estimates the smallest value among all possible enrollments
      Specified by:
        `getBound` in class `Request`
      Returns:
        uppper bound

    - #### isAssigned

          public boolean isAssigned(Assignment<Request,Enrollment> assignment)

      Return true if request is assigned.
      Overrides:
        `isAssigned` in class `Request`
      Parameters:
        `assignment` - current assignment
      Returns:
        true if this request is assigned

    - #### equals

          public boolean equals(Object o)

      Overrides:
        `equals` in class `Request`

    - #### getReservations

          public List<Reservation> getReservations(Course course)

      Get reservations for this course requests
      Parameters:
        `course` - given course
      Returns:
        reservations for this course requests and the given course

    - #### getSortedReservations

          public TreeSet<Reservation> getSortedReservations(Assignment<Request,Enrollment> assignment,
                                                            Course course)

      Get reservations for this course requests ordered using `Reservation.compareTo(Assignment, Reservation)`
      Parameters:
        `course` - given course
      Returns:
        reservations for this course requests and the given course

    - #### hasReservations

          public boolean hasReservations()

      Return true if there is a reservation for a course of this request
      Returns:
        true if there is a reservation for a course of this request

    - #### clearReservationCache

          public void clearReservationCache()

      Clear reservation information that was cached on this section

    - #### getRestrictions

          public List<Restriction> getRestrictions(Course course)

      Get restrictions for this course requests
      Parameters:
        `course` - given course
      Returns:
        restrictions for this course requests and the given course

    - #### hasRestrictions

          public boolean hasRestrictions(Course course)

      Return true if there is a restriction for a course of this request
      Returns:
        true if there is a restriction for a course of this request

    - #### isNotAllowed

          public boolean isNotAllowed(Course course,
                                      Config config)

      Return true when there are restrictions for a course of this course request and the given config does not meet any of them

    - #### isNotAllowed

          public boolean isNotAllowed(Course course,
                                      Section section)

      Return true when there are restrictions for a course of this course request and the given section does not meet any of them

    - #### isNotAllowed

          public boolean isNotAllowed(Enrollment e)

      Return true when there are restrictions for a course of this course request and the given enrollment does not meet any of them

    - #### clearRestrictionCache

          public void clearRestrictionCache()

      Clear restriction information that was cached on this request

    - #### isMPP

          public boolean isMPP()

      Return true if this request can track MPP
      Overrides:
        `isMPP` in class `Request`
      Returns:
        true if the request is course request and it either has an initial enrollment

    - #### hasSelection

          public boolean hasSelection()

      Return true if this request has any selection
      Overrides:
        `hasSelection` in class `Request`
      Returns:
        true if the request is course request and has some selected choices.

    - #### addRequestGroup

          public void addRequestGroup(RequestGroup group)

      Add request group to this request.
      Parameters:
        `group` - request group to be added

    - #### removeRequestGroup

          public void removeRequestGroup(RequestGroup group)

      Removed request group from this request.
      Parameters:
        `group` - request group to be removed

    - #### getRequestGroups

          public Set<RequestGroup> getRequestGroups()

      Lists request groups of this request
      Returns:
        request groups of this course requests

    - #### variableAssigned

          public void variableAssigned(Assignment<Request,Enrollment> assignment,
                                       long iteration,
                                       Enrollment enrollment)

      Description copied from class: `Request`
      Assign given enrollment to this request. This method also calls `SctAssignment.assigned(Assignment, Enrollment)` on for all the assignments of the enrollment.
      Overrides:
        `variableAssigned` in class `Request`
      Parameters:
        `assignment` - current assignment
        `iteration` - current iteration
        `enrollment` - assigned value

    - #### variableUnassigned

          public void variableUnassigned(Assignment<Request,Enrollment> assignment,
                                         long iteration,
                                         Enrollment enrollment)

      Description copied from class: `Request`
      Unassign currently assigned enrollment from this request. This method also calls `SctAssignment.unassigned(Assignment, Enrollment)` on for all the assignments of the current enrollment.
      Overrides:
        `variableUnassigned` in class `Request`
      Parameters:
        `assignment` - current assignment
        `iteration` - current iteration
        `enrollment` - unassigned value

    - #### getMinCredit

          public float getMinCredit()

      Description copied from class: `Request`
      Smallest credit provided by this request
      Specified by:
        `getMinCredit` in class `Request`

    - #### getRequestPriority

          public Request.RequestPriority getRequestPriority()

      Description copied from class: `Request`
      Importance of the request. Higher priority requests are assigned before lower priority requests.
      Specified by:
        `getRequestPriority` in class `Request`

    - #### setRequestPriority

          public void setRequestPriority(Request.RequestPriority priority)

    - #### isFixed

          public boolean isFixed()

    - #### getFixedValue

          public Enrollment getFixedValue()

    - #### setFixedValue

          public void setFixedValue(Enrollment constant)

    - #### hasCourse

          public boolean hasCourse(Course course)

      Description copied from class: `Request`
      Check if this request is `CourseRequest` and contains the given course.
      Overrides:
        `hasCourse` in class `Request`

    - #### hasChildren

          public boolean hasChildren()

      Description copied from class: `Request`
      Check if this request is `CourseRequest` and a parent of some other course
      Overrides:
        `hasChildren` in class `Request`