org.cpsolver.studentsct.extension

## Class TimeOverlapsCounter

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

- All Implemented Interfaces:
    CanHoldContext, CanInheritContext<Request,Enrollment,TimeOverlapsCounter.TimeOverlapsCounterContext>, HasAssignmentContext<Request,Enrollment,TimeOverlapsCounter.TimeOverlapsCounterContext>, ModelListener<Request,Enrollment>

      public class TimeOverlapsCounter
      extends ExtensionWithContext<Request,Enrollment,TimeOverlapsCounter.TimeOverlapsCounterContext>
      implements CanInheritContext<Request,Enrollment,TimeOverlapsCounter.TimeOverlapsCounterContext>

  This extension computes time overlaps. Only sections that allow overlaps (see `SctAssignment.isAllowOverlap()`) can overlap. This class counts how many overlapping slots there are so that this number can be minimized.
  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

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `TimeOverlapsCounter.Conflict` A representation of a time overlapping conflict
    `class` | `TimeOverlapsCounter.TimeOverlapsCounterContext`

  - ### 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
    `TimeOverlapsCounter(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<TimeOverlapsCounter.Conflict>` | `allConflicts(Assignment<Request,Enrollment> assignment, 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` | `beforeAssigned(Assignment<Request,Enrollment> assignment, long iteration, Enrollment value)` Called before a value is assigned to a variable.
    `void` | `checkTotalNrConflicts(Assignment<Request,Enrollment> assignment)`
    `Set<TimeOverlapsCounter.Conflict>` | `conflicts(Enrollment enrollment)` Return a set of free and unavailability time conflict of the given enrollment.
    `Set<TimeOverlapsCounter.Conflict>` | `conflicts(Enrollment e1, Enrollment e2)` Return a set of time overlapping conflicts (`TimeOverlapsCounter.Conflict` objects) between given (course) enrollments.
    `TimeOverlapsCounter.TimeOverlapsCounterContext` | `createAssignmentContext(Assignment<Request,Enrollment> assignment)` Create a new assignment context for the given assignment.
    `Set<TimeOverlapsCounter.Conflict>` | `freeTimeConflicts(Enrollment enrollment)` Return a set of free time conflict of the given enrollment.
    `Set<TimeOverlapsCounter.Conflict>` | `getAllConflicts(Assignment<Request,Enrollment> assignment)` Return a set of all time overlapping conflicts (`TimeOverlapsCounter.Conflict` objects).
    `int` | `getTotalNrConflicts(Assignment<Request,Enrollment> assignment)` Actual number of all time overlapping conflicts
    `boolean` | `inConflict(SctAssignment a1, SctAssignment a2)` Return true if the given two assignments are overlapping.
    `TimeOverlapsCounter.TimeOverlapsCounterContext` | `inheritAssignmentContext(Assignment<Request,Enrollment> assignment, TimeOverlapsCounter.TimeOverlapsCounterContext parentContext)` Create a new assignment context for the given assignment.
    `Set<TimeOverlapsCounter.Conflict>` | `notAvailableTimeConflicts(Enrollment enrollment)` Return a set of unavailability time conflict of the given enrollment.
    `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` | `nrNotAvailableTimeConflicts(Enrollment enrollment)` Total sum of all unavailability time conflict of the given enrollment.
    `int` | `share(SctAssignment a1, SctAssignment a2)` If the two sections are overlapping, return the number of slots of the overlap.
    `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`

- - ### 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

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### inConflict

          public boolean inConflict(SctAssignment a1,
                                    SctAssignment 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(SctAssignment a1,
                           SctAssignment 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

    - #### nrFreeTimeConflicts

          public int nrFreeTimeConflicts(Enrollment enrollment)

      Total sum of all free time conflict of the given enrollment.
      Parameters:
        `enrollment` - given enrollment
      Returns:
        number of all free time conflicts of the given enrollment

    - #### freeTimeConflicts

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

      Return a set of free time conflict of the given enrollment.
      Parameters:
        `enrollment` - given enrollment
      Returns:
        set of all free time conflicts of the given enrollment

    - #### nrNotAvailableTimeConflicts

          public int nrNotAvailableTimeConflicts(Enrollment enrollment)

      Total sum of all unavailability time conflict of the given enrollment.
      Parameters:
        `enrollment` - given enrollment
      Returns:
        number of all unavailability time conflicts of the given enrollment

    - #### notAvailableTimeConflicts

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

      Return a set of unavailability time conflict of the given enrollment.
      Parameters:
        `enrollment` - given enrollment
      Returns:
        set of all unavailability time conflicts of the given enrollment

    - #### conflicts

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

      Return a set of free and unavailability time conflict of the given enrollment.
      Parameters:
        `enrollment` - given enrollment
      Returns:
        set of all free time conflicts of the given enrollment

    - #### getTotalNrConflicts

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

      Actual number of all time overlapping conflicts
      Parameters:
        `assignment` - current assignment
      Returns:
        total number of time overlapping conflicts

    - #### checkTotalNrConflicts

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

    - #### getAllConflicts

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

      Return a set of all time overlapping conflicts (`TimeOverlapsCounter.Conflict` objects).
      Parameters:
        `assignment` - current assignment
      Returns:
        set of all time overlapping conflicts in the assignment

    - #### 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

    - #### allConflicts

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

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

    - #### createAssignmentContext

          public TimeOverlapsCounter.TimeOverlapsCounterContext 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,TimeOverlapsCounter.TimeOverlapsCounterContext>`
      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 TimeOverlapsCounter.TimeOverlapsCounterContext inheritAssignmentContext(Assignment<Request,Enrollment> assignment,
                                                                                         TimeOverlapsCounter.TimeOverlapsCounterContext 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,TimeOverlapsCounter.TimeOverlapsCounterContext>`
      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