org.cpsolver.coursett.constraint

## Class MaxBlockFlexibleConstraint

- 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.MaxBlockFlexibleConstraint

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

      public class MaxBlockFlexibleConstraint
      extends FlexibleConstraint

  The MaxBlock constraint checks for too big blocks of back-to-back classes of an instructor.
  It has two parameters: a maximal length of a back-to-back block that is allowed and a minimal length of a break between two classes not to be considered in the same block.
  Reference _MaxBlock:120:30_ translates to a maximal block of at most 2 hours (120 minutes) with classes not more than 30 minutes a part.
  Version:
    CourseTT 1.3 (University Course Timetabling)
    Copyright (C) 2013 Matej Lukac
    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:
    Matej Lukac

- - ### Nested Class Summary

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

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

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected int` | `iMaxBlockSlotsBTB`

    - ### 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
    `MaxBlockFlexibleConstraint(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.
    `List<FlexibleConstraint.Block>` | `getBlocks(Assignment<Lecture,Placement> assignment, int dayCode, Set<Placement> conflicts, Placement value, HashMap<Lecture,Placement> assignments, BitSet week)`
    `double` | `getNrViolations(Assignment<Lecture,Placement> assignment, Set<Placement> conflicts, HashMap<Lecture,Placement> assignments)` Return current number of violations.

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

      `createAssignmentContext, getCurrentPreference, getDayOfWeekOffset, getName, getOwner, getPrologPreference, getReference, getRelevantPlacements, getType, getWeeks, isConsistent, 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`

- - ### Field Detail

    - #### iMaxBlockSlotsBTB

          protected int iMaxBlockSlotsBTB

  - ### Constructor Detail

    - #### MaxBlockFlexibleConstraint

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

      Parameters:
        `id` - constraint unique id
        `owner` - identifier of distribution preference the constraint was created for
        `preference` - time preference ("R" for required, "P" for prohibited, "-2", "-1", "1", "2" for soft preference)
        `reference` - parameters of the constraint in String form

  - ### Method Detail

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

    - #### getBlocks

          public List<FlexibleConstraint.Block> getBlocks(Assignment<Lecture,Placement> assignment,
                                                          int dayCode,
                                                          Set<Placement> conflicts,
                                                          Placement value,
                                                          HashMap<Lecture,Placement> assignments,
                                                          BitSet week)

    - #### getNrViolations

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

      Description copied from class: `FlexibleConstraint`
      Return current number of violations.
      Specified by:
        `getNrViolations` in class `FlexibleConstraint`
      Parameters:
        `assignment` - current assignment
        `conflicts` - conflicting placements to be unassigned
        `assignments` - assigned placements
      Returns:
        the number of violations of the constraint during days and all weeks of the semester