org.cpsolver.studentsct.extension

## Class StudentQuality

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

- All Implemented Interfaces:
    CanHoldContext, CanInheritContext<Request,Enrollment,StudentQuality.StudentQualityContext>, HasAssignmentContext<Request,Enrollment,StudentQuality.StudentQualityContext>, InfoProvider<Request,Enrollment>, ModelListener<Request,Enrollment>

      public class StudentQuality
      extends ExtensionWithContext<Request,Enrollment,StudentQuality.StudentQualityContext>
      implements ModelListener<Request,Enrollment>, CanInheritContext<Request,Enrollment,StudentQuality.StudentQualityContext>, InfoProvider<Request,Enrollment>

  This extension computes student schedule quality using various matrices. It replaces `TimeOverlapsCounter` and `DistanceConflict` extensions. Besides of time and distance conflicts, it also counts cases when a student has a lunch break conflict, travel time during the day, it can prefer or discourage student class back-to-backm and cases when a student has more than a given number of hours between the first and the last class on a day. See `StudentQuality.Type` 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/.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `class` | `StudentQuality.Conflict` A representation of a time overlapping conflict
    `static class` | `StudentQuality.Context` Context holding parameters and distance cache.
    `static class` | `StudentQuality.FreeTimes` Free times of a student
    `static class` | `StudentQuality.Nothing` Empty iterator
    `static interface` | `StudentQuality.Quality` Schedule quality interface
    `static class` | `StudentQuality.SingleTimeIterable` Early/late time
    `class` | `StudentQuality.StudentQualityContext` Assignment context
    `static class` | `StudentQuality.Type` Measured student qualities
    `static class` | `StudentQuality.Unavailabilities` Unavailabilities of a student
    `static class` | `StudentQuality.WeightType` Weighting types

  - ### Field Summary

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

      `sMaxSize`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `StudentQuality(DistanceMetric metrics, DataProperties properties)` Constructor
    `StudentQuality(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<StudentQuality.Conflict>` | `allConflicts(Assignment<Request,Enrollment> assignment, Enrollment enrollment)` All conflicts of the any type for the enrollment (including conflicts with other enrollments of the student)
    `void` | `beforeAssigned(Assignment<Request,Enrollment> assignment, long iteration, Enrollment value)` Called before a value is assigned to a variable
    `Set<StudentQuality.Conflict>` | `conflicts(Enrollment e1)` Conflicts of any type between classes of a single enrollment (or with free times, unavailabilities, etc.)
    `Set<StudentQuality.Conflict>` | `conflicts(Enrollment e1, Enrollment e2)` Conflicts of any type between two enrollments of a student.
    `Set<StudentQuality.Conflict>` | `conflicts(StudentQuality.Type type, Enrollment e1)` Conflicts of the given type between classes of a single enrollment (or with free times, unavailabilities, etc.)
    `Set<StudentQuality.Conflict>` | `conflicts(StudentQuality.Type type, Enrollment e1, Enrollment e2)` Conflicss of the given type between two enrollments of a student.
    `StudentQuality.StudentQualityContext` | `createAssignmentContext(Assignment<Request,Enrollment> assignment)` Create a new assignment context for the given assignment.
    `Set<StudentQuality.Conflict>` | `getAllConflicts(StudentQuality.Type type, Assignment<Request,Enrollment> assignment)` All conflicts of the given type for the given assignment
    `DistanceMetric` | `getDistanceMetric()` Current distance metric
    `void` | `getInfo(Assignment<Request,Enrollment> assignment, Map<String,String> info)` Adds some information into the table with information about the solution
    `void` | `getInfo(Assignment<Request,Enrollment> assignment, Map<String,String> info, Collection<Request> variables)` Adds some information into the table with information about the solution, only consider variables from the given set
    `StudentQuality.Context` | `getStudentQualityContext()` Student quality context
    `int` | `getTotalPenalty(Assignment<Request,Enrollment> assignment, StudentQuality.Type... types)` Total penalisation of given types
    `int` | `getTotalPenalty(StudentQuality.Type type, Assignment<Request,Enrollment> assignment)` Total penalisation of given type
    `boolean` | `hasDistanceConflict(Student student, Section s1, Section s2)`
    `void` | `checkTotalPenalty(Assignment<Request,Enrollment> assignment)` Re-check total penalization for the given assignment
    `void` | `checkTotalPenalty(StudentQuality.Type type, Assignment<Request,Enrollment> assignment)` Re-check total penalization for the given assignment and conflict type
    `StudentQuality.StudentQualityContext` | `inheritAssignmentContext(Assignment<Request,Enrollment> assignment, StudentQuality.StudentQualityContext parentContext)` Create a new assignment context for the given assignment.
    `boolean` | `isApplicable(StudentQuality.Type type, Student student, Request r1, Request r2)` Check whether the given type is applicable for the student and the two requests.
    `boolean` | `isDebug()` Is debugging enabled
    `int` | `penalty(StudentQuality.Type type, Enrollment e1)` Penalty of given type between classes of a single enrollment (or with free times, unavailabilities, etc.)
    `int` | `penalty(StudentQuality.Type type, Enrollment e1, Enrollment e2)` Penalisation of the given type between two enrollments of a student.
    `String` | `toString(Assignment<Request,Enrollment> assignment)`

    - ### 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, toString, wait, wait, wait`

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

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

- - ### Constructor Detail

    - #### StudentQuality

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

      Constructor
      Parameters:
        `solver` - student scheduling solver
        `properties` - solver configuration

    - #### StudentQuality

          public StudentQuality(DistanceMetric metrics,
                                DataProperties properties)

      Constructor
      Parameters:
        `metrics` - distance metric
        `properties` - solver configuration

  - ### Method Detail

    - #### getDistanceMetric

          public DistanceMetric getDistanceMetric()

      Current distance metric
      Returns:
        distance metric

    - #### isDebug

          public boolean isDebug()

      Is debugging enabled
      Returns:
        true when StudentQuality.Debug is true

    - #### getStudentQualityContext

          public StudentQuality.Context getStudentQualityContext()

      Student quality context

    - #### penalty

          public int penalty(StudentQuality.Type type,
                             Enrollment e1,
                             Enrollment e2)

      Penalisation of the given type between two enrollments of a student.

    - #### conflicts

          public Set<StudentQuality.Conflict> conflicts(StudentQuality.Type type,
                                                        Enrollment e1,
                                                        Enrollment e2)

      Conflicss of the given type between two enrollments of a student.

    - #### conflicts

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

      Conflicts of any type between two enrollments of a student.

    - #### conflicts

          public Set<StudentQuality.Conflict> conflicts(StudentQuality.Type type,
                                                        Enrollment e1)

      Conflicts of the given type between classes of a single enrollment (or with free times, unavailabilities, etc.)

    - #### conflicts

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

      Conflicts of any type between classes of a single enrollment (or with free times, unavailabilities, etc.)

    - #### penalty

          public int penalty(StudentQuality.Type type,
                             Enrollment e1)

      Penalty of given type between classes of a single enrollment (or with free times, unavailabilities, etc.)

    - #### isApplicable

          public boolean isApplicable(StudentQuality.Type type,
                                      Student student,
                                      Request r1,
                                      Request r2)

      Check whether the given type is applicable for the student and the two requests.

    - #### getTotalPenalty

          public int getTotalPenalty(StudentQuality.Type type,
                                     Assignment<Request,Enrollment> assignment)

      Total penalisation of given type

    - #### getTotalPenalty

          public int getTotalPenalty(Assignment<Request,Enrollment> assignment,
                                     StudentQuality.Type... types)

      Total penalisation of given types

    - #### checkTotalPenalty

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

      Re-check total penalization for the given assignment

    - #### checkTotalPenalty

          public void checkTotalPenalty(StudentQuality.Type type,
                                        Assignment<Request,Enrollment> assignment)

      Re-check total penalization for the given assignment and conflict type

    - #### getAllConflicts

          public Set<StudentQuality.Conflict> getAllConflicts(StudentQuality.Type type,
                                                              Assignment<Request,Enrollment> assignment)

      All conflicts of the given type for the given assignment

    - #### allConflicts

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

      All conflicts of the any type for the enrollment (including conflicts with other enrollments of the student)

    - #### beforeAssigned

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

      Description copied from class: `Extension`
      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)

      Description copied from class: `Extension`
      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)

      Description copied from class: `Extension`
      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 StudentQuality.StudentQualityContext 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,StudentQuality.StudentQualityContext>`
      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 StudentQuality.StudentQualityContext inheritAssignmentContext(Assignment<Request,Enrollment> assignment,
                                                                               StudentQuality.StudentQualityContext 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,StudentQuality.StudentQualityContext>`
      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

    - #### getInfo

          public void getInfo(Assignment<Request,Enrollment> assignment,
                              Map<String,String> info)

      Description copied from interface: `InfoProvider`
      Adds some information into the table with information about the solution
      Specified by:
        `getInfo` in interface `InfoProvider<Request,Enrollment>`
      Parameters:
        `assignment` - current assignment
        `info` - info table

    - #### getInfo

          public void getInfo(Assignment<Request,Enrollment> assignment,
                              Map<String,String> info,
                              Collection<Request> variables)

      Description copied from interface: `InfoProvider`
      Adds some information into the table with information about the solution, only consider variables from the given set
      Specified by:
        `getInfo` in interface `InfoProvider<Request,Enrollment>`
      Parameters:
        `assignment` - current assignment
        `info` - info table
        `variables` - sub-problem

    - #### toString

          public String toString(Assignment<Request,Enrollment> assignment)

    - #### hasDistanceConflict

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