org.cpsolver.coursett.constraint

## Class SpreadConstraint

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

- All Implemented Interfaces:
    Comparable<Constraint<Lecture,Placement>>, CanHoldContext, HasAssignmentContext<Lecture,Placement,SpreadConstraint.SpreadConstraintContext>, WeakeningConstraint<Lecture,Placement>
  Direct Known Subclasses:
    DepartmentSpreadConstraint

      public class SpreadConstraint
      extends ConstraintWithContext<Lecture,Placement,SpreadConstraint.SpreadConstraintContext>
      implements WeakeningConstraint<Lecture,Placement>

  Spread given set of classes in time as much as possible. See `DepartmentSpreadConstraint` for more details.
  Version:
    CourseTT 1.3 (University Course Timetabling)
    Copyright (C) 2006 - 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` | `SpreadConstraint.SpreadConstraintContext`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static boolean` | `USE_MOST_IMPROVEMENT_ADEPTS`

    - ### 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
    `SpreadConstraint(DataProperties config, String name)`
    `SpreadConstraint(String name, double spreadFactor, int unassignmentsToWeaken, boolean interactiveMode, int firstDaySlot, int lastDaySlot, int firstWorkDay, int lastWorkDay)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addVariable(Lecture lecture)` Add a variable to this constraint
    `void` | `computeConflicts(Assignment<Lecture,Placement> assignment, Placement placement, Set<Placement> conflicts)` The only method which has to be implemented by any constraint.
    `SpreadConstraint.SpreadConstraintContext` | `createAssignmentContext(Assignment<Lecture,Placement> assignment)` Create a new assignment context for the given assignment.
    `Placement` | `getAdept(Assignment<Lecture,Placement> assignment, Placement placement, int[][] nrCourses, Set<Placement> conflicts)`
    `protected Criterion<Lecture,Placement>` | `getCriterion()`
    `int` | `getMaxPenalty(Assignment<Lecture,Placement> assignment, Placement placement)`
    `String` | `getName()` Constraint's name -- for printing purposes
    `int` | `getPenalty(Assignment<Lecture,Placement> assignment)` Department balancing penalty for this department
    `int` | `getPenalty(Assignment<Lecture,Placement> assignment, Placement placement)` Department balancing penalty of the given placement
    `int` | `getPenaltyEstimate(Assignment<Lecture,Placement> assignment)`
    `boolean` | `inConflict(Assignment<Lecture,Placement> assignment, Placement placement)` Returns true if the given assignment is inconsistent with the existing assignments respecting this constraint.
    `String` | `toString()`
    `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.ifs.assignment.context.ConstraintWithContext

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

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

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

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

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

- - ### Field Detail

    - #### USE_MOST_IMPROVEMENT_ADEPTS

          public static boolean USE_MOST_IMPROVEMENT_ADEPTS

  - ### Constructor Detail

    - #### SpreadConstraint

          public SpreadConstraint(String name,
                                  double spreadFactor,
                                  int unassignmentsToWeaken,
                                  boolean interactiveMode,
                                  int firstDaySlot,
                                  int lastDaySlot,
                                  int firstWorkDay,
                                  int lastWorkDay)

    - #### SpreadConstraint

          public SpreadConstraint(DataProperties config,
                                  String name)

  - ### Method Detail

    - #### getCriterion

          protected Criterion<Lecture,Placement> getCriterion()

    - #### getAdept

          public Placement getAdept(Assignment<Lecture,Placement> assignment,
                                    Placement placement,
                                    int[][] nrCourses,
                                    Set<Placement> conflicts)

    - #### computeConflicts

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

    - #### inConflict

          public boolean inConflict(Assignment<Lecture,Placement> assignment,
                                    Placement placement)

      Description copied from class: `Constraint`
      Returns true if the given assignment is inconsistent with the existing assignments respecting this constraint. This method is used by MAC (see `MacPropagation`).
      Overrides:
        `inConflict` in class `Constraint<Lecture,Placement>`
      Parameters:
        `assignment` - current assignment
        `placement` - given value
      Returns:
        true if there is a conflict with other assigned variables of the constraint

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

    - #### getName

          public String getName()

      Description copied from class: `Constraint`
      Constraint's name -- for printing purposes
      Overrides:
        `getName` in class `Constraint<Lecture,Placement>`
      Returns:
        constraint name

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### getPenalty

          public int getPenalty(Assignment<Lecture,Placement> assignment)

      Department balancing penalty for this department
      Parameters:
        `assignment` - current assignment
      Returns:
        current penalty

    - #### getPenaltyEstimate

          public int getPenaltyEstimate(Assignment<Lecture,Placement> assignment)

    - #### getMaxPenalty

          public int getMaxPenalty(Assignment<Lecture,Placement> assignment,
                                   Placement placement)

    - #### getPenalty

          public int getPenalty(Assignment<Lecture,Placement> assignment,
                                Placement placement)

      Department balancing penalty of the given placement
      Parameters:
        `assignment` - current assignment
        `placement` - a placement that is being considered
      Returns:
        change in the penalty if assigned

    - #### addVariable

          public void addVariable(Lecture lecture)

      Description copied from class: `Constraint`
      Add a variable to this constraint
      Overrides:
        `addVariable` in class `Constraint<Lecture,Placement>`
      Parameters:
        `lecture` - a variable

    - #### 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 SpreadConstraint.SpreadConstraintContext 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,SpreadConstraint.SpreadConstraintContext>`
      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