org.cpsolver.studentsct.extension

## Class DistanceConflict

- java.lang.Object
- - org.cpsolver.ifs.extension.Extension<V,T>
  - - org.cpsolver.ifs.assignment.context.ExtensionWithContext<Request,Enrollment,DistanceConflict.DistanceConflictContext>
    - - org.cpsolver.studentsct.extension.DistanceConflict

- All Implemented Interfaces:
    CanHoldContext, CanInheritContext<Request,Enrollment,DistanceConflict.DistanceConflictContext>, HasAssignmentContext<Request,Enrollment,DistanceConflict.DistanceConflictContext>, ModelListener<Request,Enrollment>

      public class DistanceConflict
      extends ExtensionWithContext<Request,Enrollment,DistanceConflict.DistanceConflictContext>
      implements ModelListener<Request,Enrollment>, CanInheritContext<Request,Enrollment,DistanceConflict.DistanceConflictContext>

  This extension computes student distant conflicts. Two sections that are attended by the same student are considered in a distance conflict if they are back-to-back taught in locations that are two far away. This means that the (walking) distance in minutes between the two classes are longer than the break time of the earlier class. See `DistanceMetric` for more details.
  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
  See Also:
    `TimeLocation`, `
    `

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `DistanceConflict.Conflict` A representation of a distance conflict
    `class` | `DistanceConflict.DistanceConflictContext`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static boolean` | `sDebug` Debug flag

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

      `sMaxSize`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DistanceConflict(DistanceMetric metrics, DataProperties properties)` Alternative constructor (for online student sectioning)
    `DistanceConflict(Solver<Request,Enrollment> solver, DataProperties properties)` Constructor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `afterAssigned(Assignment<Request,Enrollment> assignment, long iteration, Enrollment value)` Called after a value is assigned to a variable.
    `void` | `afterUnassigned(Assignment<Request,Enrollment> assignment, long iteration, Enrollment value)` Called after a value is unassigned from a variable.
    `Set<DistanceConflict.Conflict>` | `allConflicts(Assignment<Request,Enrollment> assignment, Enrollment enrollment)` The set of all conflicts (`DistanceConflict.Conflict` objects) of the given enrollment and other enrollments that are assignmed to the same student.
    `void` | `beforeAssigned(Assignment<Request,Enrollment> assignment, long iteration, Enrollment value)` Called before a value is assigned to a variable.
    `void` | `checkAllConflicts(Assignment<Request,Enrollment> assignment)` Checks the counter counting all conflicts
    `Set<DistanceConflict.Conflict>` | `computeAllConflicts(Assignment<Request,Enrollment> assignment)` Compute a set of all distance conflicts (`DistanceConflict.Conflict` objects).
    `Set<DistanceConflict.Conflict>` | `conflicts(Enrollment e1)` Return a set of distance conflicts (`DistanceConflict.Conflict` objects) of a (course) enrollment.
    `Set<DistanceConflict.Conflict>` | `conflicts(Enrollment e1, Enrollment e2)` Return a set of distance conflicts (`DistanceConflict.Conflict` objects) between given (course) enrollments.
    `int` | `countTotalNrConflicts(Assignment<Request,Enrollment> assignment)` Compute the actual number of all distance conflicts.
    `DistanceConflict.DistanceConflictContext` | `createAssignmentContext(Assignment<Request,Enrollment> assignment)` Create a new assignment context for the given assignment.
    `Set<DistanceConflict.Conflict>` | `getAllConflicts(Assignment<Request,Enrollment> assignment)` Return a set of all distance conflicts (`DistanceConflict.Conflict` objects).
    `protected int` | `getDistanceInMinutes(Placement p1, Placement p2)`
    `protected int` | `getDistanceInMinutes(RoomLocation r1, RoomLocation r2)`
    `DistanceMetric` | `getDistanceMetric()`
    `int` | `getTotalNrConflicts(Assignment<Request,Enrollment> assignment)` Actual number of all distance conflicts
    `int` | `getTotalNrShortConflicts(Assignment<Request,Enrollment> assignment)` Actual number of all distance conflicts of students that need short distances
    `boolean` | `inConflict(Student student, Section s1, Section s2)` Return true if the given two sections are in distance conflict.
    `DistanceConflict.DistanceConflictContext` | `inheritAssignmentContext(Assignment<Request,Enrollment> assignment, DistanceConflict.DistanceConflictContext parentContext)` Create a new assignment context for the given assignment.
    `int` | `nrConflicts(Enrollment e1)` Return number of distance conflict of a (course) enrollment.
    `int` | `nrConflicts(Enrollment e1, Enrollment e2)` Return number of distance conflicts that are between two enrollments.
    `String` | `toString()`

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

      `getAssignmentContextReference, getContext, getContext, init, setAssignmentContextReference, unregister`

    - ### Methods inherited from class org.cpsolver.ifs.extension.Extension

      `beforeUnassigned, constraintAdded, constraintRemoved, getModel, getProperties, getSolver, isRegistered, register, variableAdded, variableRemoved`

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

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

    - ### Methods inherited from interface org.cpsolver.ifs.model.ModelListener

      `beforeUnassigned, constraintAdded, constraintRemoved, init, variableAdded, variableRemoved`

- - ### Field Detail

    - #### sDebug

          public static boolean sDebug

      Debug flag

  - ### Constructor Detail

    - #### DistanceConflict

          public DistanceConflict(Solver<Request,Enrollment> solver,
                                  DataProperties properties)

      Constructor. Beside of other thigs, this constructor also uses `StudentSectioningModel.setDistanceConflict(DistanceConflict)` to set the this instance to the model.
      Parameters:
        `solver` - constraint solver
        `properties` - configuration

    - #### DistanceConflict

          public DistanceConflict(DistanceMetric metrics,
                                  DataProperties properties)

      Alternative constructor (for online student sectioning)
      Parameters:
        `metrics` - distance metrics
        `properties` - configuration

  - ### Method Detail

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### getDistanceMetric

          public DistanceMetric getDistanceMetric()

    - #### getDistanceInMinutes

          protected int getDistanceInMinutes(RoomLocation r1,
                                             RoomLocation r2)

    - #### getDistanceInMinutes

          protected int getDistanceInMinutes(Placement p1,
                                             Placement p2)

    - #### inConflict

          public boolean inConflict(Student student,
                                    Section s1,
                                    Section s2)

      Return true if the given two sections are in distance conflict. This means that the sections are back-to-back and that they are placed in locations that are two far.
      Parameters:
        `student` - a student
        `s1` - a section
        `s2` - a section
      Returns:
        true, if the given sections are in a distance conflict

    - #### nrConflicts

          public int nrConflicts(Enrollment e1)

      Return number of distance conflict of a (course) enrollment. It is the number of pairs of assignments of the enrollment that are in a distance conflict.
      Parameters:
        `e1` - an enrollment
      Returns:
        number of distance conflicts

    - #### nrConflicts

          public int nrConflicts(Enrollment e1,
                                 Enrollment e2)

      Return number of distance conflicts that are between two enrollments. It is the number of pairs of assignments of these enrollments that are in a distance conflict.
      Parameters:
        `e1` - an enrollment
        `e2` - an enrollment
      Returns:
        number of distance conflict between given enrollments

    - #### conflicts

          public Set<DistanceConflict.Conflict> conflicts(Enrollment e1)

      Return a set of distance conflicts (`DistanceConflict.Conflict` objects) of a (course) enrollment.
      Parameters:
        `e1` - an enrollment
      Returns:
        list of distance conflicts that are between assignment of the given enrollment

    - #### conflicts

          public Set<DistanceConflict.Conflict> conflicts(Enrollment e1,
                                                          Enrollment e2)

      Return a set of distance conflicts (`DistanceConflict.Conflict` objects) between given (course) enrollments.
      Parameters:
        `e1` - an enrollment
        `e2` - an enrollment
      Returns:
        list of distance conflicts that are between assignment of the given enrollments

    - #### allConflicts

          public Set<DistanceConflict.Conflict> allConflicts(Assignment<Request,Enrollment> assignment,
                                                             Enrollment enrollment)

      The set of all conflicts (`DistanceConflict.Conflict` objects) of the given enrollment and other enrollments that are assignmed to the same student.
      Parameters:
        `assignment` - current assignment
        `enrollment` - given enrollment
      Returns:
        set of all conflicts

    - #### checkAllConflicts

          public void checkAllConflicts(Assignment<Request,Enrollment> assignment)

      Checks the counter counting all conflicts
      Parameters:
        `assignment` - current assignment

    - #### getTotalNrConflicts

          public int getTotalNrConflicts(Assignment<Request,Enrollment> assignment)

      Actual number of all distance conflicts
      Parameters:
        `assignment` - current assignment
      Returns:
        cached number of all distance conflicts

    - #### getTotalNrShortConflicts

          public int getTotalNrShortConflicts(Assignment<Request,Enrollment> assignment)

      Actual number of all distance conflicts of students that need short distances
      Parameters:
        `assignment` - current assignment
      Returns:
        cached number of all distance conflicts

    - #### countTotalNrConflicts

          public int countTotalNrConflicts(Assignment<Request,Enrollment> assignment)

      Compute the actual number of all distance conflicts. Should be equal to `getTotalNrConflicts(Assignment)`.
      Parameters:
        `assignment` - current assignment
      Returns:
        computed number of all distance conflicts

    - #### computeAllConflicts

          public Set<DistanceConflict.Conflict> computeAllConflicts(Assignment<Request,Enrollment> assignment)

      Compute a set of all distance conflicts (`DistanceConflict.Conflict` objects).
      Parameters:
        `assignment` - current assignment
      Returns:
        computed set of all distance conflicts

    - #### getAllConflicts

          public Set<DistanceConflict.Conflict> getAllConflicts(Assignment<Request,Enrollment> assignment)

      Return a set of all distance conflicts (`DistanceConflict.Conflict` objects).
      Parameters:
        `assignment` - current assignment
      Returns:
        cached set of all distance conflicts

    - #### beforeAssigned

          public void beforeAssigned(Assignment<Request,Enrollment> assignment,
                                     long iteration,
                                     Enrollment value)

      Called before a value is assigned to a variable.
      Specified by:
        `beforeAssigned` in interface `ModelListener<Request,Enrollment>`
      Overrides:
        `beforeAssigned` in class `Extension<Request,Enrollment>`
      Parameters:
        `assignment` - current assignment
        `iteration` - current iteration
        `value` - value to be assigned

    - #### afterAssigned

          public void afterAssigned(Assignment<Request,Enrollment> assignment,
                                    long iteration,
                                    Enrollment value)

      Called after a value is assigned to a variable.
      Specified by:
        `afterAssigned` in interface `ModelListener<Request,Enrollment>`
      Overrides:
        `afterAssigned` in class `Extension<Request,Enrollment>`
      Parameters:
        `assignment` - current assignment
        `iteration` - current iteration
        `value` - value to be assigned

    - #### afterUnassigned

          public void afterUnassigned(Assignment<Request,Enrollment> assignment,
                                      long iteration,
                                      Enrollment value)

      Called after a value is unassigned from a variable.
      Specified by:
        `afterUnassigned` in interface `ModelListener<Request,Enrollment>`
      Overrides:
        `afterUnassigned` in class `Extension<Request,Enrollment>`
      Parameters:
        `assignment` - current assignment
        `iteration` - current iteration
        `value` - value to be unassigned

    - #### createAssignmentContext

          public DistanceConflict.DistanceConflictContext createAssignmentContext(Assignment<Request,Enrollment> 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<Request,Enrollment,DistanceConflict.DistanceConflictContext>`
      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

    - #### inheritAssignmentContext

          public DistanceConflict.DistanceConflictContext inheritAssignmentContext(Assignment<Request,Enrollment> assignment,
                                                                                   DistanceConflict.DistanceConflictContext parentContext)

      Description copied from interface: `CanInheritContext`
      Create a new assignment context for the given assignment. This method can be used to clone the parent context if desired.
      Specified by:
        `inheritAssignmentContext` in interface `CanInheritContext<Request,Enrollment,DistanceConflict.DistanceConflictContext>`
      Parameters:
        `assignment` - an assignment for which there needs to be an assignment context
        `parentContext` - context of the parent assignment
      Returns:
        a new instance of the assignment context, filled according to the given assignment