org.cpsolver.instructor.constraints

## Class SameLinkConstraint

- java.lang.Object
- - org.cpsolver.ifs.model.Constraint<V,T>
  - - org.cpsolver.ifs.assignment.context.ConstraintWithContext<TeachingRequest.Variable,TeachingAssignment,SameLinkConstraint.Context>
    - - org.cpsolver.instructor.constraints.SameLinkConstraint

- All Implemented Interfaces:
    Comparable<Constraint<TeachingRequest.Variable,TeachingAssignment>>, CanHoldContext, HasAssignmentContext<TeachingRequest.Variable,TeachingAssignment,SameLinkConstraint.Context>

      public class SameLinkConstraint
      extends ConstraintWithContext<TeachingRequest.Variable,TeachingAssignment,SameLinkConstraint.Context>

  Same Link Constraint. Much like the `SameInstructorConstraint`, but it is possible to assign multiple instructors to the teaching requests of the same link. It is, however, prohibited (or discouraged) for an instructor to teach have teaching requests than the ones of the link. In prohibited / discouraged variant, each request must / should get a different instructor.
  Version:
    IFS 1.3 (Instructor Sectioning)
    Copyright (C) 2016 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/.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `class` | `SameLinkConstraint.Context` Same Link Constraint Context.

  - ### Field Summary

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

      `iConstraintListeners`

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

      `sMaxSize`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SameLinkConstraint(Long id, String name, String preference)` Constructor

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `computeConflicts(Assignment<TeachingRequest.Variable,TeachingAssignment> assignment, TeachingAssignment value, Set<TeachingAssignment> conflicts)` The only method which has to be implemented by any constraint.
    `SameLinkConstraint.Context` | `createAssignmentContext(Assignment<TeachingRequest.Variable,TeachingAssignment> assignment)` Create a new assignment context for the given assignment.
    `Long` | `getConstraintId()` Constraint id that was given in the constructor.
    `int` | `getCurrentPreference(Assignment<TeachingRequest.Variable,TeachingAssignment> assignment)` Current constraint preference (if soft)
    `int` | `getCurrentPreference(Assignment<TeachingRequest.Variable,TeachingAssignment> assignment, TeachingAssignment value)` Current constraint preference (if soft)
    `String` | `getName()` Constraint's name -- for printing purposes
    `int` | `getPreference()` Constraint preference that was provided in the constructor
    `boolean` | `isHard()` Returns true if the constraint is hard.
    `boolean` | `isProhibited()` Is prohibited?
    `boolean` | `isRequired()` Is required?
    `String` | `toString()`

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

      `assigned, getAssignmentContextReference, getContext, getContext, setAssignmentContextReference, setModel, unassigned`

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

      `addConstraintListener, addVariable, assignedVariables, compareTo, computeConflictsNoForwardCheck, constraintListeners, countAssignedVariables, countVariables, equals, getDescription, getId, getModel, hashCode, inConflict, isConsistent, removeConstraintListener, removeVariable, variables`

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

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

- - ### Constructor Detail

    - #### SameLinkConstraint

          public SameLinkConstraint(Long id,
                                    String name,
                                    String preference)

      Constructor
      Parameters:
        `id` - constraint id
        `name` - link name
        `preference` - constraint preference (R for required, etc.)

  - ### Method Detail

    - #### getConstraintId

          public Long getConstraintId()

      Constraint id that was given in the constructor.
      Returns:
        constraint id

    - #### getName

          public String getName()

      Description copied from class: `Constraint`
      Constraint's name -- for printing purposes
      Overrides:
        `getName` in class `Constraint<TeachingRequest.Variable,TeachingAssignment>`
      Returns:
        constraint name

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### isRequired

          public boolean isRequired()

      Is required?
      Returns:
        true if the constraint is required

    - #### isProhibited

          public boolean isProhibited()

      Is prohibited?
      Returns:
        true if the constraint is prohibited

    - #### getPreference

          public int getPreference()

      Constraint preference that was provided in the constructor
      Returns:
        constraint preference

    - #### isHard

          public boolean isHard()

      Description copied from class: `Constraint`
      Returns true if the constraint is hard. Only hard constraints are allowed to unassign a variable when there is a conflict with a value that is being assigned
      Overrides:
        `isHard` in class `Constraint<TeachingRequest.Variable,TeachingAssignment>`
      Returns:
        true if the constraint is hard

    - #### computeConflicts

          public void computeConflicts(Assignment<TeachingRequest.Variable,TeachingAssignment> assignment,
                                       TeachingAssignment value,
                                       Set<TeachingAssignment> conflicts)

      Description copied from class: `Constraint`
      The only method which has to be implemented by any constraint. It returns the values which needs to be unassigned in order to make this constraint consistent with the given value if it is assigned to its variable. The computed list of conflicting values is added to the given set of conflicts.
      Specified by:
        `computeConflicts` in class `Constraint<TeachingRequest.Variable,TeachingAssignment>`
      Parameters:
        `assignment` - current assignment
        `value` - value to be assigned to its variable
        `conflicts` - resultant set of conflicting values

    - #### getCurrentPreference

          public int getCurrentPreference(Assignment<TeachingRequest.Variable,TeachingAssignment> assignment,
                                          TeachingAssignment value)

      Current constraint preference (if soft)
      Parameters:
        `assignment` - current assignment
        `value` - proposed change
      Returns:
        change in the current preference value of this constraint

    - #### getCurrentPreference

          public int getCurrentPreference(Assignment<TeachingRequest.Variable,TeachingAssignment> assignment)

      Current constraint preference (if soft)
      Parameters:
        `assignment` - current assignment
      Returns:
        that is number of requests that are not of this link assigned to the instructors that have at least one request of this link if preferred; number of additional requests of this link given to the same instructor if discouraged

    - #### createAssignmentContext

          public SameLinkConstraint.Context createAssignmentContext(Assignment<TeachingRequest.Variable,TeachingAssignment> 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.
      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