org.cpsolver.coursett.constraint

## Class JenrlConstraint

- java.lang.Object
- - org.cpsolver.ifs.model.Constraint<V,T>
  - - org.cpsolver.ifs.model.BinaryConstraint<V,T>
    - - org.cpsolver.ifs.assignment.context.BinaryConstraintWithContext<Lecture,Placement,JenrlConstraint.JenrlConstraintContext>
      - - org.cpsolver.coursett.constraint.JenrlConstraint

- All Implemented Interfaces:
    Comparable<Constraint<Lecture,Placement>>, CanHoldContext, HasAssignmentContext<Lecture,Placement,JenrlConstraint.JenrlConstraintContext>, WeakeningConstraint<Lecture,Placement>

      public class JenrlConstraint
      extends BinaryConstraintWithContext<Lecture,Placement,JenrlConstraint.JenrlConstraintContext>
      implements WeakeningConstraint<Lecture,Placement>

  Join student enrollment constraint.
  This constraint is placed between all pairs of classes where there is at least one student attending both classes. It represents a number of student conflicts (number of joined enrollments), if the given two classes overlap in time.
  Also, it dynamically maintains the counter of all student conflicts. It is a soft constraint.
  Version:
    CourseTT 1.3 (University Course Timetabling)
    Copyright (C) 2006 - 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/.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `class` | `JenrlConstraint.JenrlConstraintContext`

  - ### Field Summary

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

      `iConstraintListeners, iId`

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

      `sMaxSize`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `JenrlConstraint()` Constructor

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `areStudentConflictsCommitted()`
    `boolean` | `areStudentConflictsDistance(Assignment<Lecture,Placement> assignment)`
    `boolean` | `areStudentConflictsDistance(Assignment<Lecture,Placement> assignment, Placement value)`
    `boolean` | `areStudentConflictsHard()`
    `boolean` | `areStudentConflictsWorkday(Assignment<Lecture,Placement> assignment, Placement value)`
    `void` | `computeConflicts(Assignment<Lecture,Placement> assignment, Placement value, Set<Placement> conflicts)` The only method which has to be implemented by any constraint.
    `JenrlConstraint.JenrlConstraintContext` | `createAssignmentContext(Assignment<Lecture,Placement> assignment)` Create a new assignment context for the given assignment.
    `void` | `decJenrl(Assignment<Lecture,Placement> assignment, Student student)` Decrement the number of joined enrollments (during student final sectioning)
    `Set<Student>` | `getInstructors()`
    `long` | `getJenrl()` Number of joined enrollments (during student final sectioning)
    `double` | `getJenrlWeight(Student student)`
    `String` | `getName()` Constraint's name -- for printing purposes
    `int` | `getNrInstructors()`
    `int` | `getNrStudents()`
    `Set<Student>` | `getStudents()`
    `void` | `incJenrl(Assignment<Lecture,Placement> assignment, Student student)` Increment the number of joined enrollments (during student final sectioning)
    `boolean` | `inConflict(Assignment<Lecture,Placement> assignment, Placement value)` Returns true if the given assignment is inconsistent with the existing assignments respecting this constraint.
    `boolean` | `isHard()` Returns true if the constraint is hard.
    `boolean` | `isInConflict(Assignment<Lecture,Placement> assignment)` True if the given two lectures overlap in time
    `static boolean` | `isInConflict(Placement p1, Placement p2, DistanceMetric m, int workDayLimit)` Returns true if the given placements are overlapping or they are back-to-back and too far for students.
    `boolean` | `isOfTheSameProblem()`
    `boolean` | `isToBeIgnored()` Returns true if there is `IgnoreStudentConflictsConstraint` between the two lectures.
    `double` | `jenrl()`
    `long` | `jenrl(Assignment<Lecture,Placement> assignment, Lecture variable, Placement value)` Number of joined enrollments if the given value is assigned to the given variable
    `double` | `priority()`
    `void` | `setModel(Model<Lecture,Placement> model)` Sets the model which the constraint belongs to
    `String` | `toString()`
    `void` | `weaken(Assignment<Lecture,Placement> assignment)` Weaken the constraint.
    `void` | `weaken(Assignment<Lecture,Placement> assignment, Placement value)` Weaken the constraint enough so that it can assign the given value.

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

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

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

      `addVariable, another, first, isFirst, second`

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

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

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

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

- - ### Constructor Detail

    - #### JenrlConstraint

          public JenrlConstraint()

      Constructor

  - ### 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 `BinaryConstraintWithContext<Lecture,Placement,JenrlConstraint.JenrlConstraintContext>`
      Parameters:
        `model` - problem model

    - #### computeConflicts

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

    - #### inConflict

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

      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
        `value` - given value
      Returns:
        true if there is a conflict with other assigned variables of the constraint

    - #### isInConflict

          public static boolean isInConflict(Placement p1,
                                             Placement p2,
                                             DistanceMetric m,
                                             int workDayLimit)

      Returns true if the given placements are overlapping or they are back-to-back and too far for students.
      Parameters:
        `p1` - first placement
        `p2` - second placement
        `m` - distance metrics
        `workDayLimit` - limit on the work-day
      Returns:
        true if there is a student conflict between the two placements

    - #### jenrl

          public long jenrl(Assignment<Lecture,Placement> assignment,
                            Lecture variable,
                            Placement value)

      Number of joined enrollments if the given value is assigned to the given variable
      Parameters:
        `assignment` - current assignment
        `variable` - a class
        `value` - class placement under consideration
      Returns:
        number of student conflicts caused by this constraint if assigned

    - #### isInConflict

          public boolean isInConflict(Assignment<Lecture,Placement> assignment)

      True if the given two lectures overlap in time
      Parameters:
        `assignment` - current assignment
      Returns:
        true if this constraint is conflicting

    - #### incJenrl

          public void incJenrl(Assignment<Lecture,Placement> assignment,
                               Student student)

      Increment the number of joined enrollments (during student final sectioning)
      Parameters:
        `assignment` - current assignment
        `student` - student added in between the two classes of this constraint

    - #### getJenrlWeight

          public double getJenrlWeight(Student student)

    - #### decJenrl

          public void decJenrl(Assignment<Lecture,Placement> assignment,
                               Student student)

      Decrement the number of joined enrollments (during student final sectioning)
      Parameters:
        `assignment` - current assignment
        `student` - student removed from between the two classes of this constraint

    - #### getJenrl

          public long getJenrl()

      Number of joined enrollments (during student final sectioning)
      Returns:
        number of joined enrollments

    - #### jenrl

          public double jenrl()

    - #### priority

          public double priority()

    - #### getNrStudents

          public int getNrStudents()

    - #### getStudents

          public Set<Student> getStudents()

    - #### getNrInstructors

          public int getNrInstructors()

    - #### getInstructors

          public Set<Student> getInstructors()

    - #### 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<Lecture,Placement>`
      Returns:
        true if the constraint is hard

    - #### getName

          public String getName()

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

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### areStudentConflictsHard

          public boolean areStudentConflictsHard()

    - #### areStudentConflictsDistance

          public boolean areStudentConflictsDistance(Assignment<Lecture,Placement> assignment)

    - #### areStudentConflictsCommitted

          public boolean areStudentConflictsCommitted()

    - #### areStudentConflictsDistance

          public boolean areStudentConflictsDistance(Assignment<Lecture,Placement> assignment,
                                                     Placement value)

    - #### areStudentConflictsWorkday

          public boolean areStudentConflictsWorkday(Assignment<Lecture,Placement> assignment,
                                                    Placement value)

    - #### isOfTheSameProblem

          public boolean isOfTheSameProblem()

    - #### weaken

          public void weaken(Assignment<Lecture,Placement> assignment)

      Description copied from interface: `WeakeningConstraint`
      Weaken the constraint. This method is called if the constraint participates in an unassigned of a variable.
      Specified by:
        `weaken` in interface `WeakeningConstraint<Lecture,Placement>`
      Parameters:
        `assignment` - current assignment

    - #### weaken

          public void weaken(Assignment<Lecture,Placement> assignment,
                             Placement value)

      Description copied from interface: `WeakeningConstraint`
      Weaken the constraint enough so that it can assign the given value.
      Specified by:
        `weaken` in interface `WeakeningConstraint<Lecture,Placement>`
      Parameters:
        `assignment` - current assignment
        `value` - a conflicting value to be assigned

    - #### isToBeIgnored

          public boolean isToBeIgnored()

      Returns true if there is `IgnoreStudentConflictsConstraint` between the two lectures.
      Returns:
        true if this constraint is to be ignored

    - #### createAssignmentContext

          public JenrlConstraint.JenrlConstraintContext createAssignmentContext(Assignment<Lecture,Placement> 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.
      Specified by:
        `createAssignmentContext` in interface `HasAssignmentContext<Lecture,Placement,JenrlConstraint.JenrlConstraintContext>`
      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