net.sf.cpsolver.studentsct.extension

## Class TimeOverlapsCounter

- java.lang.Object
- - net.sf.cpsolver.ifs.extension.Extension<Request,Enrollment>
  - - net.sf.cpsolver.studentsct.extension.TimeOverlapsCounter

- All Implemented Interfaces:
    ModelListener<Request,Enrollment>

      public class TimeOverlapsCounter
      extends Extension<Request,Enrollment>

  This extension computes time overlaps. Only sections that allow overlaps (see `Assignment.isAllowOverlap()`) can overlap. This class counts how many overlapping slots there are so that this number can be minimized.
  Version:
    StudentSct 1.2 (Student Sectioning)
    Copyright (C) 2007 - 2010 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
    --- | ---
    `static class` | `TimeOverlapsCounter.Conflict` A representation of a time overlapping conflict

  - ### Field Summary

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

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TimeOverlapsCounter(Solver<Request,Enrollment> solver, DataProperties properties)` Constructor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `afterAssigned(long iteration, Enrollment value)` Called after a value is assigned to a variable.
    `void` | `afterUnassigned(long iteration, Enrollment value)` Called after a value is unassigned from a variable.
    `Set<TimeOverlapsCounter.Conflict>` | `allConflicts(Enrollment enrollment)` The set of all conflicts (`TimeOverlapsCounter.Conflict` objects) of the given enrollment and other enrollments that are assigned to the same student.
    `void` | `assigned(long iteration, Enrollment value)` Called when a value is assigned to a variable.
    `void` | `beforeAssigned(long iteration, Enrollment value)` Called before a value is assigned to a variable.
    `void` | `checkTotalNrConflicts()`
    `Set<TimeOverlapsCounter.Conflict>` | `computeAllConflicts()` Compute a set of all time overlapping conflicts (`TimeOverlapsCounter.Conflict` objects).
    `Set<TimeOverlapsCounter.Conflict>` | `conflicts(Enrollment e1, Enrollment e2)` Return a set of time overlapping conflicts (`TimeOverlapsCounter.Conflict` objects) between given (course) enrollments.
    `int` | `countTotalNrConflicts()` Compute the actual number of all time overlapping conflicts.
    `Set<TimeOverlapsCounter.Conflict>` | `freeTimeConflicts(Enrollment enrollment)` Return a set of free time conflict of the given enrollment.
    `Set<TimeOverlapsCounter.Conflict>` | `getAllConflicts()` Return a set of all time overlapping conflicts (`TimeOverlapsCounter.Conflict` objects).
    `int` | `getTotalNrConflicts()` Actual number of all time overlapping conflicts
    `boolean` | `inConflict(Assignment a1, Assignment a2)` Return true if the given two assignments are overlapping.
    `boolean` | `init(Solver<Request,Enrollment> solver)` Initialize extension
    `int` | `nrAllConflicts(Enrollment enrollment)` Total sum of all conflict of the given enrollment and other enrollments that are assigned to the same student.
    `int` | `nrConflicts(Enrollment e1, Enrollment e2)` Return number of time overlapping conflicts that are between two enrollments.
    `int` | `nrFreeTimeConflicts(Enrollment enrollment)` Total sum of all free time conflict of the given enrollment.
    `int` | `share(Assignment a1, Assignment a2)` If the two sections are overlapping, return the number of slots of the overlap.
    `String` | `toString()`
    `void` | `unassigned(long iteration, Enrollment value)` Called when a value is unassigned from a variable.

    - ### Methods inherited from class net.sf.cpsolver.ifs.extension.Extension

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

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

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

- - ### Field Detail

    - #### sDebug

          public static boolean sDebug

      Debug flag

  - ### Constructor Detail

    - #### TimeOverlapsCounter

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

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

  - ### Method Detail

    - #### init

          public boolean init(Solver<Request,Enrollment> solver)

      Initialize extension
      Specified by:
        `init` in interface `ModelListener<Request,Enrollment>`
      Overrides:
        `init` in class `Extension<Request,Enrollment>`
      Parameters:
        `solver` - IFS solver

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### inConflict

          public boolean inConflict(Assignment a1,
                                    Assignment a2)

      Return true if the given two assignments are overlapping.
      Parameters:
        `a1` - an assignment
        `a2` - an assignment
      Returns:
        true, if the given sections are in an overlapping conflict

    - #### share

          public int share(Assignment a1,
                           Assignment a2)

      If the two sections are overlapping, return the number of slots of the overlap.
      Parameters:
        `a1` - an assignment
        `a2` - an assignment
      Returns:
        the number of overlapping slots against the number of slots of the smallest section

    - #### nrConflicts

          public int nrConflicts(Enrollment e1,
                                 Enrollment e2)

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

    - #### conflicts

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

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

    - #### nrAllConflicts

          public int nrAllConflicts(Enrollment enrollment)

      Total sum of all conflict of the given enrollment and other enrollments that are assigned to the same student.

    - #### nrFreeTimeConflicts

          public int nrFreeTimeConflicts(Enrollment enrollment)

      Total sum of all free time conflict of the given enrollment.

    - #### freeTimeConflicts

          public Set<TimeOverlapsCounter.Conflict> freeTimeConflicts(Enrollment enrollment)

      Return a set of free time conflict of the given enrollment.

    - #### allConflicts

          public Set<TimeOverlapsCounter.Conflict> allConflicts(Enrollment enrollment)

      The set of all conflicts (`TimeOverlapsCounter.Conflict` objects) of the given enrollment and other enrollments that are assigned to the same student.

    - #### assigned

          public void assigned(long iteration,
                               Enrollment value)

      Called when a value is assigned to a variable. Internal number of time overlapping conflicts is updated, see `getTotalNrConflicts()`.

    - #### unassigned

          public void unassigned(long iteration,
                                 Enrollment value)

      Called when a value is unassigned from a variable. Internal number of time overlapping conflicts is updated, see `getTotalNrConflicts()`.

    - #### getTotalNrConflicts

          public int getTotalNrConflicts()

      Actual number of all time overlapping conflicts

    - #### checkTotalNrConflicts

          public void checkTotalNrConflicts()

    - #### countTotalNrConflicts

          public int countTotalNrConflicts()

      Compute the actual number of all time overlapping conflicts. Should be equal to `getTotalNrConflicts()`.

    - #### computeAllConflicts

          public Set<TimeOverlapsCounter.Conflict> computeAllConflicts()

      Compute a set of all time overlapping conflicts (`TimeOverlapsCounter.Conflict` objects).

    - #### getAllConflicts

          public Set<TimeOverlapsCounter.Conflict> getAllConflicts()

      Return a set of all time overlapping conflicts (`TimeOverlapsCounter.Conflict` objects).

    - #### beforeAssigned

          public void beforeAssigned(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:
        `iteration` - current iteration
        `value` - value to be assigned

    - #### afterAssigned

          public void afterAssigned(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:
        `iteration` - current iteration
        `value` - value to be assigned

    - #### afterUnassigned

          public void afterUnassigned(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:
        `iteration` - current iteration
        `value` - value to be unassigned