org.cpsolver.instructor.constraints

## Class SameInstructorConstraint

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

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

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

  Same Instructor Constraint. Teaching requests linked with this constraint must/should have the same instructor assigned. If discouraged/prohibited, every pair of teaching requests should/must have 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/.
  Author:
    Tomáš Müller

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `class` | `SameInstructorConstraint.Context` Same Instructor 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
    `SameInstructorConstraint(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.
    `SameInstructorConstraint.Context` | `createAssignmentContext(Assignment<TeachingRequest.Variable,TeachingAssignment> assignment)` Create a new assignment context for the given assignment.
    `Long` | `getConstraintId()` Constraint id that was provided 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?
    `boolean` | `isSatisfiedPair(Assignment<TeachingRequest.Variable,TeachingAssignment> assignment, TeachingAssignment a1, TeachingAssignment a2)` Does a pair of teaching assignments satisfy this constraint?
    `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

    - #### SameInstructorConstraint

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

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

  - ### Method Detail

    - #### getConstraintId

          public Long getConstraintId()

      Constraint id that was provided 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

    - #### isSatisfiedPair

          public boolean isSatisfiedPair(Assignment<TeachingRequest.Variable,TeachingAssignment> assignment,
                                         TeachingAssignment a1,
                                         TeachingAssignment a2)

      Does a pair of teaching assignments satisfy this constraint?
      Parameters:
        `assignment` - current assignment
        `a1` - first teaching assignment
        `a2` - second teaching assignment
      Returns:
        True if the two assignments (of this constraint) have the same instructor (prohibited/preferred case) or a different instructor (prohibited/discouraged case).

    - #### 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:
        number of violated pairs weighted by the absolute value of the preference

    - #### createAssignmentContext

          public SameInstructorConstraint.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