org.cpsolver.coursett.constraint

## Class ExtendedStudentConflicts

- java.lang.Object
- - org.cpsolver.ifs.model.Constraint<V,T>
  - - org.cpsolver.ifs.model.GlobalConstraint<Lecture,Placement>
    - - org.cpsolver.coursett.constraint.ExtendedStudentConflicts

- All Implemented Interfaces:
    Comparable<Constraint<Lecture,Placement>>, ModelListener<Lecture,Placement>

      public class ExtendedStudentConflicts
      extends GlobalConstraint<Lecture,Placement>
      implements ModelListener<Lecture,Placement>

  An experimental global constraint that does not allow any two classes that can be attended by the same student to have a conflict. The constraint checks any two classes of different offerings that share at least one student and that the student is allowed to take (not restricted by reservations). Class pairs included in the Ignore Student Conflicts constraints are ignored. Some classes may be excluded by using ExtendedStudentConflicts.IgnoreClasses parameter which may contain a regular expression matching class name(s).
  Pairs of classes of the same offering are checked, too. In this case, the course structure must allow the two classes to be attended together (e.g., they are from the same configuration), and at least one student in the offering is allowed to take both classes. This feature can be disabled by setting ExtendedStudentConflicts.CheckSameCourse to false.
  Version:
    CourseTT 1.3 (University Course Timetabling)
    Copyright (C) 2013 - 2024 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

- - ### Field Summary

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

      `iConstraintListeners, iId`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ExtendedStudentConflicts()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `afterAssigned(Assignment<Lecture,Placement> assignment, long iteration, Placement value)` Called after a value is assigned to its variable ( `Value.variable()`).
    `void` | `afterUnassigned(Assignment<Lecture,Placement> assignment, long iteration, Placement value)` Called after a value is unassigned from its variable ( `Value.variable()`).
    `void` | `beforeAssigned(Assignment<Lecture,Placement> assignment, long iteration, Placement value)` Called before a value is assigned to its variable ( `Value.variable()`).
    `void` | `beforeUnassigned(Assignment<Lecture,Placement> assignment, long iteration, Placement value)` Called before a value is unassigned from its variable ( `Value.variable()`).
    `protected boolean` | `checkStudentForStudentConflicts(Lecture l1, Lecture l2)`
    `protected void` | `clearCache()`
    `void` | `computeConflicts(Assignment<Lecture,Placement> assignment, Placement placement, Set<Placement> conflicts)` The only method which has to be implemented by any constraint.
    `void` | `constraintAdded(Constraint<Lecture,Placement> constraint)` Constraint is added to the model
    `void` | `constraintRemoved(Constraint<Lecture,Placement> constraint)` Constraint is removed from the model
    `protected List<Student>` | `getCommonStudents(Long offeringId1, Long offeringId2)`
    `String` | `getName()` Constraint's name -- for printing purposes
    `boolean` | `inConflict(Assignment<Lecture,Placement> assignment, Placement placement)` Returns true if the given assignment is inconsistent with the existing assignments respecting this constraint.
    `boolean` | `init(Solver<Lecture,Placement> solver)` Notification that the model was initialized by the solver.
    `boolean` | `isConsistent(Placement p1, Placement p2)` Returns true if the given assignments are consistent respecting this constraint.
    `protected boolean` | `isIgnoreClass(Lecture lecture)`
    `void` | `setModel(Model<Lecture,Placement> model)` Sets the model which the constraint belongs to
    `String` | `toString()`
    `void` | `variableAdded(Lecture variable)` Variable is added to the model
    `void` | `variableRemoved(Lecture variable)` Variable is removed from the model

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

      `addVariable, assigned, assignedVariables, countAssignedVariables, removeVariable, unassigned, variables`

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

      `addConstraintListener, compareTo, computeConflictsNoForwardCheck, constraintListeners, countVariables, equals, getDescription, getId, getModel, hashCode, isHard, removeConstraintListener`

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

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

- - ### Constructor Detail

    - #### ExtendedStudentConflicts

          public ExtendedStudentConflicts()

  - ### Method Detail

    - #### setModel

          public void setModel(Model<Lecture,Placement> model)

      Description copied from class: `Constraint`
      Sets the model which the constraint belongs to
      Overrides:
        `setModel` in class `Constraint<Lecture,Placement>`
      Parameters:
        `model` - problem model

    - #### clearCache

          protected void clearCache()

    - #### getCommonStudents

          protected List<Student> getCommonStudents(Long offeringId1,
                                                    Long offeringId2)

    - #### isIgnoreClass

          protected boolean isIgnoreClass(Lecture lecture)

    - #### checkStudentForStudentConflicts

          protected boolean checkStudentForStudentConflicts(Lecture l1,
                                                            Lecture l2)

    - #### computeConflicts

          public void computeConflicts(Assignment<Lecture,Placement> assignment,
                                       Placement placement,
                                       Set<Placement> 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<Lecture,Placement>`
      Parameters:
        `assignment` - current assignment
        `placement` - value to be assigned to its variable
        `conflicts` - resultant set of conflicting values

    - #### inConflict

          public boolean inConflict(Assignment<Lecture,Placement> assignment,
                                    Placement placement)

      Description copied from class: `Constraint`
      Returns true if the given assignment is inconsistent with the existing assignments respecting this constraint. This method is used by MAC (see `MacPropagation`).
      Overrides:
        `inConflict` in class `Constraint<Lecture,Placement>`
      Parameters:
        `assignment` - current assignment
        `placement` - given value
      Returns:
        true if there is a conflict with other assigned variables of the constraint

    - #### isConsistent

          public boolean isConsistent(Placement p1,
                                      Placement p2)

      Description copied from class: `Constraint`
      Returns true if the given assignments are consistent respecting this constraint. This method is used by MAC (see `MacPropagation`).
      Overrides:
        `isConsistent` in class `Constraint<Lecture,Placement>`
      Parameters:
        `p1` - a value
        `p2` - a value
      Returns:
        true if the constraint is ok with the assignment

    - #### getName

          public String getName()

      Description copied from class: `Constraint`
      Constraint's name -- for printing purposes
      Overrides:
        `getName` in class `GlobalConstraint<Lecture,Placement>`
      Returns:
        constraint name

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `GlobalConstraint<Lecture,Placement>`

    - #### variableAdded

          public void variableAdded(Lecture variable)

      Description copied from interface: `ModelListener`
      Variable is added to the model
      Specified by:
        `variableAdded` in interface `ModelListener<Lecture,Placement>`
      Parameters:
        `variable` - added variable

    - #### variableRemoved

          public void variableRemoved(Lecture variable)

      Description copied from interface: `ModelListener`
      Variable is removed from the model
      Specified by:
        `variableRemoved` in interface `ModelListener<Lecture,Placement>`
      Parameters:
        `variable` - removed variable

    - #### constraintAdded

          public void constraintAdded(Constraint<Lecture,Placement> constraint)

      Description copied from interface: `ModelListener`
      Constraint is added to the model
      Specified by:
        `constraintAdded` in interface `ModelListener<Lecture,Placement>`
      Parameters:
        `constraint` - added constraint

    - #### constraintRemoved

          public void constraintRemoved(Constraint<Lecture,Placement> constraint)

      Description copied from interface: `ModelListener`
      Constraint is removed from the model
      Specified by:
        `constraintRemoved` in interface `ModelListener<Lecture,Placement>`
      Parameters:
        `constraint` - removed constraint

    - #### beforeAssigned

          public void beforeAssigned(Assignment<Lecture,Placement> assignment,
                                     long iteration,
                                     Placement value)

      Description copied from interface: `ModelListener`
      Called before a value is assigned to its variable ( `Value.variable()`).
      Specified by:
        `beforeAssigned` in interface `ModelListener<Lecture,Placement>`
      Parameters:
        `assignment` - current assignment
        `iteration` - current iteration
        `value` - value to be assigned

    - #### beforeUnassigned

          public void beforeUnassigned(Assignment<Lecture,Placement> assignment,
                                       long iteration,
                                       Placement value)

      Description copied from interface: `ModelListener`
      Called before a value is unassigned from its variable ( `Value.variable()`).
      Specified by:
        `beforeUnassigned` in interface `ModelListener<Lecture,Placement>`
      Parameters:
        `assignment` - current assignment
        `iteration` - current iteration
        `value` - value to be unassigned

    - #### afterAssigned

          public void afterAssigned(Assignment<Lecture,Placement> assignment,
                                    long iteration,
                                    Placement value)

      Description copied from interface: `ModelListener`
      Called after a value is assigned to its variable ( `Value.variable()`).
      Specified by:
        `afterAssigned` in interface `ModelListener<Lecture,Placement>`
      Parameters:
        `assignment` - current assignment
        `iteration` - current iteration
        `value` - value to be assigned

    - #### afterUnassigned

          public void afterUnassigned(Assignment<Lecture,Placement> assignment,
                                      long iteration,
                                      Placement value)

      Description copied from interface: `ModelListener`
      Called after a value is unassigned from its variable ( `Value.variable()`).
      Specified by:
        `afterUnassigned` in interface `ModelListener<Lecture,Placement>`
      Parameters:
        `assignment` - current assignment
        `iteration` - current iteration
        `value` - value to be unassigned

    - #### init

          public boolean init(Solver<Lecture,Placement> solver)

      Description copied from interface: `ModelListener`
      Notification that the model was initialized by the solver.
      Specified by:
        `init` in interface `ModelListener<Lecture,Placement>`
      Parameters:
        `solver` - IFS solver
      Returns:
        true if successfully initialized