org.cpsolver.coursett.constraint

## Class MaxHolesFlexibleConstraint

- java.lang.Object
- - org.cpsolver.ifs.model.Constraint<V,T>
  - - org.cpsolver.ifs.assignment.context.ConstraintWithContext<Lecture,Placement,FlexibleConstraint.FlexibleConstraintContext>
    - - org.cpsolver.coursett.constraint.FlexibleConstraint
      - - org.cpsolver.coursett.constraint.MaxHolesFlexibleConstraint

- All Implemented Interfaces:
    Comparable<Constraint<Lecture,Placement>>, CanHoldContext, HasAssignmentContext<Lecture,Placement,FlexibleConstraint.FlexibleConstraintContext>, WeakeningConstraint<Lecture,Placement>

      public class MaxHolesFlexibleConstraint
      extends FlexibleConstraint
      implements WeakeningConstraint<Lecture,Placement>

  The MaxHoles constraint limits the number of free time (holes) for an instructor on a day.
  It has one parameter: a maximal amount of free time (holes) that an instructor have on a day in minutes.
  Reference _MaxHoles:120_ translates to a maximum number of two hours on a day (between the first and the last class on a day).
  Version:
    CourseTT 1.3 (University Course Timetabling)
    Copyright (C) 2013 - 2017 Tomáš Müller
    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
    --- | ---
    `class` | `MaxHolesFlexibleConstraint.MaxHolesFlexibleConstraintContext`

    - ### Nested classes/interfaces inherited from class org.cpsolver.coursett.constraint.FlexibleConstraint

      `FlexibleConstraint.Block, FlexibleConstraint.FlexibleConstraintContext, FlexibleConstraint.FlexibleConstraintType, FlexibleConstraint.PlacementTimeComparator`

  - ### Field Summary

    - ### Fields inherited from class org.cpsolver.coursett.constraint.FlexibleConstraint

      `iConstraintType, iDayOfWeekOffset, iPreciseDateComputation, iPreference, iReference, iWeeks`

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

      `iConstraintListeners, iId`

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

      `sMaxSize`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `MaxHolesFlexibleConstraint(Long id, String owner, String preference, String reference)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `computeConflicts(Assignment<Lecture,Placement> assignment, Placement value, Set<Placement> conflicts)` The only method which has to be implemented by any constraint.
    `int` | `countHoles(Assignment<Lecture,Placement> assignment, int dayCode, Set<Placement> conflicts, Placement value, HashMap<Lecture,Placement> assignments, BitSet week)` Count number of holes (free slots) between the given classes on given day and week.
    `FlexibleConstraint.FlexibleConstraintContext` | `createAssignmentContext(Assignment<Lecture,Placement> assignment)` Create a new assignment context for the given assignment.
    `double` | `getNrViolations(Assignment<Lecture,Placement> assignment, Set<Placement> conflicts, HashMap<Lecture,Placement> assignments)` Count violations, that is weekly average free time that is over the limit in hours.
    `boolean` | `isConsistent(Placement value1, Placement value2)` Returns true if the given assignments are consistent respecting this constraint.
    `void` | `weaken(Assignment<Lecture,Placement> assignment)` Weaken the constraint.
    `void` | `weaken(Assignment<Lecture,Placement> assignment, Placement value)` Weaken the constraint enough so that it can assign the given value.

    - ### Methods inherited from class org.cpsolver.coursett.constraint.FlexibleConstraint

      `getCurrentPreference, getDayOfWeekOffset, getName, getOwner, getPrologPreference, getReference, getRelevantPlacements, getType, getWeeks, isHard, isPreciseDateComputation, mergeToBlocks, shareWeeksAndDay, toString`

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

      `assigned, getAssignmentContextReference, getContext, getContext, setAssignmentContextReference, setModel, unassigned`

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

      `addConstraintListener, addVariable, assignedVariables, compareTo, computeConflictsNoForwardCheck, constraintListeners, countAssignedVariables, countVariables, equals, getDescription, getId, getModel, hashCode, inConflict, removeConstraintListener, removeVariable, variables`

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

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

- - ### Constructor Detail

    - #### MaxHolesFlexibleConstraint

          public MaxHolesFlexibleConstraint(Long id,
                                            String owner,
                                            String preference,
                                            String reference)

  - ### Method Detail

    - #### countHoles

          public int countHoles(Assignment<Lecture,Placement> assignment,
                                int dayCode,
                                Set<Placement> conflicts,
                                Placement value,
                                HashMap<Lecture,Placement> assignments,
                                BitSet week)

      Count number of holes (free slots) between the given classes on given day and week.
      Parameters:
        `assignment` - current assignment
        `dayCode` - representation of days in week combination
        `conflicts` - placements to be unassigned
        `value` - placement to be assigned
        `assignments` - placements of variables
        `week` - bitset representing a date pattern
      Returns:
        number of holes (free slots) that are over the limit

    - #### getNrViolations

          public double getNrViolations(Assignment<Lecture,Placement> assignment,
                                        Set<Placement> conflicts,
                                        HashMap<Lecture,Placement> assignments)

      Count violations, that is weekly average free time that is over the limit in hours.
      Specified by:
        `getNrViolations` in class `FlexibleConstraint`
      Parameters:
        `assignment` - current assignment
        `conflicts` - placements to be unassigned
        `assignments` - placements of variables
      Returns:
        weekly average free time that is over the limit in hours

    - #### computeConflicts

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

    - #### weaken

          public void weaken(Assignment<Lecture,Placement> assignment)

      Description copied from interface: `WeakeningConstraint`
      Weaken the constraint. This method is called if the constraint participates in an unassigned of a variable.
      Specified by:
        `weaken` in interface `WeakeningConstraint<Lecture,Placement>`
      Parameters:
        `assignment` - current assignment

    - #### isConsistent

          public boolean isConsistent(Placement value1,
                                      Placement value2)

      Description copied from class: `Constraint`
      Returns true if the given assignments are consistent respecting this constraint. This method is used by MAC (see `MacPropagation`).
      Overrides:
        `isConsistent` in class `FlexibleConstraint`
      Parameters:
        `value1` - a value
        `value2` - a value
      Returns:
        true if the constraint is ok with the assignment

    - #### weaken

          public void weaken(Assignment<Lecture,Placement> assignment,
                             Placement value)

      Description copied from interface: `WeakeningConstraint`
      Weaken the constraint enough so that it can assign the given value.
      Specified by:
        `weaken` in interface `WeakeningConstraint<Lecture,Placement>`
      Parameters:
        `assignment` - current assignment
        `value` - a conflicting value to be assigned

    - #### createAssignmentContext

          public FlexibleConstraint.FlexibleConstraintContext createAssignmentContext(Assignment<Lecture,Placement> 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<Lecture,Placement,FlexibleConstraint.FlexibleConstraintContext>`
      Overrides:
        `createAssignmentContext` in class `FlexibleConstraint`
      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