org.cpsolver.instructor.constraints

## Class GroupConstraint

- java.lang.Object
- - org.cpsolver.ifs.model.Constraint<V,T>
  - - org.cpsolver.ifs.model.GlobalConstraint<TeachingRequest.Variable,TeachingAssignment>
    - - org.cpsolver.instructor.constraints.GroupConstraint

- All Implemented Interfaces:
    Comparable<Constraint<TeachingRequest.Variable,TeachingAssignment>>

      public class GroupConstraint
      extends GlobalConstraint<TeachingRequest.Variable,TeachingAssignment>

  Group Constraint. This constraint implements many of the course timetabling group and flexible constraints. See `GroupConstraint.ConstraintType` for the list, and the appropriate `GroupConstraint.ConstraintType` or `FlexibleConstraint` constraint for their description. Because the instructor - class assignments are dynamic, the constraints are implemented by a single group constraint.
  Version:
    IFS 1.4 (Instructor Sectioning)
    Copyright (C) 2024 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` | `GroupConstraint.Block` Block of sections that go one after the other without any gap.
    `static interface` | `GroupConstraint.Check` Group constraint check interface
    `static interface` | `GroupConstraint.ConstraintCreator<P>` Factory class for group constraints with parameters
    `static class` | `GroupConstraint.ConstraintType` Distribution types and their implementation
    `static interface` | `GroupConstraint.ConstraintTypeInterface` Interface for a distribution constraint type, including its implementation
    `static class` | `GroupConstraint.Distribution` Wrapper class representing one distribution preference set on an instructor.
    `static class` | `GroupConstraint.PairCheck` Group constraint check interface for constraints that can be computed on individual class pairs.
    `static class` | `GroupConstraint.ParametrizedConstraintType<P>` Distribution constraint with parameters.
    `static class` | `GroupConstraint.SimpleCheck` Simplified group constraint check interface for constraints that can be computed on individual class pairs.
    `static class` | `GroupConstraint.SimpleTimeCheck` Simplified group constraint check interface for time-only constraints that can be computed on individual class pairs.

  - ### Field Summary

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

      `iConstraintListeners, iId`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `GroupConstraint()`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `computeConflicts(Assignment<TeachingRequest.Variable,TeachingAssignment> assignment, TeachingAssignment value, Set<TeachingAssignment> conflicts)` The only method which has to be implemented by any constraint.
    `protected static List<GroupConstraint.Block>` | `getBlocks(Assignment<TeachingRequest.Variable,TeachingAssignment> assignment, Instructor instructor, int dayCode, Set<TeachingAssignment> conflicts, TeachingRequest.Variable variable, TeachingAssignment value, BitSet week, int maxBreakBetweenBTB)` Return blocks for an instructor, meeting the provided parameters.
    `static GroupConstraint.ConstraintTypeInterface` | `getConstraintType(String reference, String name)` Create a constraint type from the provided reference.
    `String` | `getName()` Constraint's name -- for printing purposes
    `protected static Set<org.cpsolver.instructor.constraints.GroupConstraint.TeachingAssignmentSection>` | `getRelevantPlacements(Assignment<TeachingRequest.Variable,TeachingAssignment> assignment, Instructor instructor, int dayCode, Set<TeachingAssignment> conflicts, TeachingRequest.Variable variable, TeachingAssignment value, BitSet week)` Return teaching assignment + section combinations for the given instructor, considering the selected value and the provided conflicts.
    `protected static boolean` | `isCorectDayAndWeek(TeachingAssignment value, int dayCode, BitSet week)` Check if the given assignment has a section on the given days of the week and weeks.
    `protected static boolean` | `isCorectDayOfWeek(TeachingAssignment value, int dayCode)` Check if the given assignment has a section on the given days of the week.
    `protected static List<GroupConstraint.Block>` | `mergeToBlocks(Collection<org.cpsolver.instructor.constraints.GroupConstraint.TeachingAssignmentSection> sorted, int maxBreakBetweenBTB)` Merge sorted teaching assignment + section combinations into block.
    `protected static boolean` | `shareWeeksAndDay(TimeLocation t, BitSet week, int dayCode)` Returns true if the time overlaps with the provided week date pattern and days of the week.
    `String` | `toString()`

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

      `addVariable, assigned, assignedVariables, countAssignedVariables, removeVariable, unassigned, variables`

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

      `addConstraintListener, compareTo, computeConflictsNoForwardCheck, constraintListeners, countVariables, equals, getDescription, getId, getModel, hashCode, inConflict, isConsistent, isHard, removeConstraintListener, setModel`

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

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

- - ### Constructor Detail

    - #### GroupConstraint

          public GroupConstraint()

  - ### Method Detail

    - #### computeConflicts

          public void computeConflicts(Assignment<TeachingRequest.Variable,TeachingAssignment> assignment,
                                       TeachingAssignment value,
                                       Set<TeachingAssignment> 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<TeachingRequest.Variable,TeachingAssignment>`
      Parameters:
        `assignment` - current assignment
        `value` - value to be assigned to its variable
        `conflicts` - resultant set of conflicting values

    - #### getName

          public String getName()

      Description copied from class: `Constraint`
      Constraint's name -- for printing purposes
      Overrides:
        `getName` in class `GlobalConstraint<TeachingRequest.Variable,TeachingAssignment>`
      Returns:
        constraint name

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `GlobalConstraint<TeachingRequest.Variable,TeachingAssignment>`

    - #### getConstraintType

          public static GroupConstraint.ConstraintTypeInterface getConstraintType(String reference,
                                                                                  String name)

      Create a constraint type from the provided reference. Returns null when there is no match.

    - #### shareWeeksAndDay

          protected static boolean shareWeeksAndDay(TimeLocation t,
                                                    BitSet week,
                                                    int dayCode)

      Returns true if the time overlaps with the provided week date pattern and days of the week.

    - #### getRelevantPlacements

          protected static Set<org.cpsolver.instructor.constraints.GroupConstraint.TeachingAssignmentSection> getRelevantPlacements(Assignment<TeachingRequest.Variable,TeachingAssignment> assignment,
                                                                                                                                    Instructor instructor,
                                                                                                                                    int dayCode,
                                                                                                                                    Set<TeachingAssignment> conflicts,
                                                                                                                                    TeachingRequest.Variable variable,
                                                                                                                                    TeachingAssignment value,
                                                                                                                                    BitSet week)

      Return teaching assignment + section combinations for the given instructor, considering the selected value and the provided conflicts. The sections are sorted by time, and must meet during the given week and days of the week.

    - #### mergeToBlocks

          protected static List<GroupConstraint.Block> mergeToBlocks(Collection<org.cpsolver.instructor.constraints.GroupConstraint.TeachingAssignmentSection> sorted,
                                                                     int maxBreakBetweenBTB)

      Merge sorted teaching assignment + section combinations into block.

    - #### getBlocks

          protected static List<GroupConstraint.Block> getBlocks(Assignment<TeachingRequest.Variable,TeachingAssignment> assignment,
                                                                 Instructor instructor,
                                                                 int dayCode,
                                                                 Set<TeachingAssignment> conflicts,
                                                                 TeachingRequest.Variable variable,
                                                                 TeachingAssignment value,
                                                                 BitSet week,
                                                                 int maxBreakBetweenBTB)

      Return blocks for an instructor, meeting the provided parameters. Combining `GroupConstraint#getRelevantPlacements(Assignment, Instructor, int, Set, Variable, TeachingAssignment, BitSet)` and `mergeToBlocks(Collection, int)`.

    - #### isCorectDayOfWeek

          protected static boolean isCorectDayOfWeek(TeachingAssignment value,
                                                     int dayCode)

      Check if the given assignment has a section on the given days of the week.

    - #### isCorectDayAndWeek

          protected static boolean isCorectDayAndWeek(TeachingAssignment value,
                                                      int dayCode,
                                                      BitSet week)

      Check if the given assignment has a section on the given days of the week and weeks.