org.cpsolver.studentsct.constraint

## Class LinkedSections

- java.lang.Object
- - org.cpsolver.studentsct.constraint.LinkedSections

-     public class LinkedSections
      extends Object

  Linked sections are sections (of different courses) that should be attended by the same students. If there are multiple sections of the same subpart, one or can be chosen randomly. For instance, if section A1 (of a course A) and section B1 (of a course B) are linked, a student requesting both courses must attend A1 if and only if he also attends B1.
  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
    --- | ---
    `static interface` | `LinkedSections.ConflictHandler` Helper interface to process conflicts in `computeConflicts(Enrollment, EnrollmentAssignment, ConflictHandler)`
    `static class` | `LinkedSections.CurrentAssignment` Current assignment -- default for `computeConflicts(Enrollment, EnrollmentAssignment, ConflictHandler)`
    `static interface` | `LinkedSections.EnrollmentAssignment` Interface to be able to provide a custom assignment to `computeConflicts(Enrollment, EnrollmentAssignment, ConflictHandler)`
    `class` | `LinkedSections.LinkedSectionsConstraint` Linked sections constraint -- to be created for each student that requests two or more offerings of this link

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `LinkedSections(Collection<Section> sections)` Constructor
    `LinkedSections(Section... sections)` Constructor

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `computeConflicts(Assignment<Request,Enrollment> assignment, Enrollment enrollment, LinkedSections.ConflictHandler conflicts)` Compute conflicting enrollments.
    `void` | `computeConflicts(Enrollment enrollment, LinkedSections.EnrollmentAssignment assignment, LinkedSections.ConflictHandler conflicts)` Compute conflicting enrollments.
    `void` | `createConstraints()` Create linked-section constraints for this link.
    `Set<Offering>` | `getOfferings()` Return offerings of this link
    `Set<Section>` | `getSections(Subpart subpart)` Return section (or sections) of a subpart of this link
    `Set<Subpart>` | `getSubparts(Offering offering)` Return subpart (or subparts) of an offering of this link
    `protected boolean` | `hasFullMatch(Enrollment enrollment)` Check if the given enrollment fully matches this constraint
    `Enrollment` | `inConflict(Assignment<Request,Enrollment> assignment, Enrollment enrollment)` Check for conflicts.
    `Enrollment` | `inConflict(Enrollment enrollment, LinkedSections.EnrollmentAssignment assignment)` Check for conflicts.
    `boolean` | `isMustBeUsed()` Return whether this constraint must be used
    `protected int` | `nrSharedOfferings(LinkedSections other)` Number of offerings that are shared with some other linked sections constraint
    `void` | `setMustBeUsed(boolean mustBeUsed)` Set whether this constraint must be used
    `String` | `toString()`

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

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

- - ### Constructor Detail

    - #### LinkedSections

          public LinkedSections(Section... sections)

      Constructor
      Parameters:
        `sections` - sections that are to be linked

    - #### LinkedSections

          public LinkedSections(Collection<Section> sections)

      Constructor
      Parameters:
        `sections` - sections that are to be linked

  - ### Method Detail

    - #### getOfferings

          public Set<Offering> getOfferings()

      Return offerings of this link
      Returns:
        offerings of this link

    - #### getSubparts

          public Set<Subpart> getSubparts(Offering offering)

      Return subpart (or subparts) of an offering of this link
      Parameters:
        `offering` - an offering of this link
      Returns:
        subpart (or subparts) of this offering in this link

    - #### getSections

          public Set<Section> getSections(Subpart subpart)

      Return section (or sections) of a subpart of this link
      Parameters:
        `subpart` - subpart of this link
      Returns:
        section (or sections) of this subpart in this link

    - #### createConstraints

          public void createConstraints()

      Create linked-section constraints for this link. A constraint is created for each student that has two or more offerings of this link.

    - #### computeConflicts

          public void computeConflicts(Assignment<Request,Enrollment> assignment,
                                       Enrollment enrollment,
                                       LinkedSections.ConflictHandler conflicts)

      Compute conflicting enrollments. If the given enrollment contains sections of this link (one for each subpart in `getSubparts(Offering)`), another assignment of this student is in a conflict, if it does not contain the appropriate sections from `getSubparts(Offering)` and `getSections(Subpart)`.
      Parameters:
        `assignment` - current assignment
        `enrollment` - given enrollment
        `conflicts` - found conflicts are given to this interface, see `LinkedSections.ConflictHandler.onConflict(Enrollment)`

    - #### computeConflicts

          public void computeConflicts(Enrollment enrollment,
                                       LinkedSections.EnrollmentAssignment assignment,
                                       LinkedSections.ConflictHandler conflicts)

      Compute conflicting enrollments. If the given enrollment contains sections of this link (one for each subpart in `getSubparts(Offering)`), another assignment of this student is in a conflict, if it does not contain the appropriate sections from `getSubparts(Offering)` and `getSections(Subpart)`.
      Parameters:
        `enrollment` - given enrollment
        `assignment` - custom assignment
        `conflicts` - found conflicts are given to this interface, see `LinkedSections.ConflictHandler.onConflict(Enrollment)`

    - #### hasFullMatch

          protected boolean hasFullMatch(Enrollment enrollment)

      Check if the given enrollment fully matches this constraint
      Parameters:
        `enrollment` - an enrollment
      Returns:
        true, if there is a full match

    - #### nrSharedOfferings

          protected int nrSharedOfferings(LinkedSections other)

      Number of offerings that are shared with some other linked sections constraint
      Parameters:
        `other` - the other constraint
      Returns:
        number of offerings in common

    - #### inConflict

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

      Check for conflicts. If the given enrollment contains sections of this link (one for each subpart in `getSubparts(Offering)`), another assignment of this student is in a conflict, if it does not contain the appropriate sections from `getSubparts(Offering)` and `getSections(Subpart)`.
      Parameters:
        `assignment` - current assignment
        `enrollment` - given enrollment
      Returns:
        conflicting enrollment

    - #### inConflict

          public Enrollment inConflict(Enrollment enrollment,
                                       LinkedSections.EnrollmentAssignment assignment)

      Check for conflicts. If the given enrollment contains sections of this link (one for each subpart in `getSubparts(Offering)`), another assignment of this student is in a conflict, if it does not contain the appropriate sections from `getSubparts(Offering)` and `getSections(Subpart)`.
      Parameters:
        `enrollment` - given enrollment
        `assignment` - custom assignment
      Returns:
        conflicting enrollment

    - #### isMustBeUsed

          public boolean isMustBeUsed()

      Return whether this constraint must be used
      Returns:
        if true, a pair of linked sections must be used when a student requests both courses

    - #### setMustBeUsed

          public void setMustBeUsed(boolean mustBeUsed)

      Set whether this constraint must be used
      Parameters:
        `mustBeUsed` - if true, a pair of linked sections must be used when a student requests both courses

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`