net.sf.cpsolver.coursett.constraint

## Class SpreadConstraint

- java.lang.Object
- - net.sf.cpsolver.ifs.model.Constraint<Lecture,Placement>
  - - net.sf.cpsolver.coursett.constraint.SpreadConstraint

- All Implemented Interfaces:
    Comparable<Constraint<Lecture,Placement>>, WeakeningConstraint<Lecture,Placement>
  Direct Known Subclasses:
    DepartmentSpreadConstraint

      public class SpreadConstraint
      extends Constraint<Lecture,Placement>
      implements WeakeningConstraint<Lecture,Placement>

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

- - ### Field Summary

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

    - ### Fields inherited from class net.sf.cpsolver.ifs.model.Constraint

      `iAssignedVariables, iConstraintListeners, iId`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SpreadConstraint(DataProperties config, String name)`
    `SpreadConstraint(String name, double spreadFactor, int unassignmentsToWeaken, boolean interactiveMode)`

  - ### 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` | `assigned(long iteration, Placement placement)` Given value is to be assigned to its varable.
    `void` | `computeConflicts(Placement placement, Set<Placement> conflicts)` The only method which has to be implemented by any constraint.
    `Placement` | `getAdept(Placement placement, int[][] nrCourses, Set<Placement> conflicts)`
    `List<Placement>[][]` | `getCourses()`
    `protected Criterion<Lecture,Placement>` | `getCriterion()`
    `int[][]` | `getMaxCourses()`
    `int` | `getMaxPenalty(Placement placement)`
    `String` | `getName()` Constraint's name -- for printing purposes
    `int[][]` | `getNrCourses()`
    `int` | `getPenalty()` Department balancing penalty for this department
    `int` | `getPenalty(Placement placement)` Department balancing penalty of the given placement
    `int` | `getPenaltyEstimate()`
    `boolean` | `inConflict(Placement placement)` Returns true if the given assignment is inconsistent with the existing assignments respecting this constraint.
    `void` | `init()` Initialize constraint (to be called after all variables are added to this constraint)
    `boolean` | `isConsistent(Placement p1, Placement p2)` Returns true if the given assignments are consistent respecting this constraint.
    `String` | `toString()`
    `void` | `unassigned(long iteration, Placement placement)` Given value is unassigned from its variable.
    `void` | `weaken()` Weaken the constraint.
    `void` | `weaken(Placement value)` Weaken the constraint enough so that it can assign the given value.

    - ### Methods inherited from class net.sf.cpsolver.ifs.model.Constraint

      `addConstraintListener, assignedVariables, compareTo, constraintListeners, countAssignedVariables, countVariables, equals, getDescription, getId, getModel, hashCode, isHard, removeConstraintListener, removeVariable, setModel, 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)

    - #### SpreadConstraint

          public SpreadConstraint(DataProperties config,
                                  String name)

  - ### Method Detail

    - #### getCriterion

          protected Criterion<Lecture,Placement> getCriterion()

    - #### init

          public void init()

      Initialize constraint (to be called after all variables are added to this constraint)

    - #### getAdept

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

    - #### computeConflicts

          public void computeConflicts(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:
        `placement` - value to be assigned to its varaible
        `conflicts` - resultant set of conflicting values

    - #### inConflict

          public boolean inConflict(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>`

    - #### isConsistent

          public boolean isConsistent(Placement p1,
                                      Placement p2)

      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 `Constraint<Lecture,Placement>`

    - #### weaken

          public void weaken()

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

    - #### assigned

          public void assigned(long iteration,
                               Placement placement)

      Description copied from class: `Constraint`
      Given value is to be assigned to its varable. In this method, the constraint should unassigns all varaibles which are in conflict with the given assignment because of this constraint.
      Overrides:
        `assigned` in class `Constraint<Lecture,Placement>`

    - #### unassigned

          public void unassigned(long iteration,
                                 Placement placement)

      Description copied from class: `Constraint`
      Given value is unassigned from its variable.
      Overrides:
        `unassigned` in class `Constraint<Lecture,Placement>`

    - #### getName

          public String getName()

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

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### getPenalty

          public int getPenalty()

      Department balancing penalty for this department

    - #### getPenaltyEstimate

          public int getPenaltyEstimate()

    - #### getMaxPenalty

          public int getMaxPenalty(Placement placement)

    - #### getPenalty

          public int getPenalty(Placement placement)

      Department balancing penalty of the given placement

    - #### getMaxCourses

          public int[][] getMaxCourses()

    - #### getNrCourses

          public int[][] getNrCourses()

    - #### getCourses

          public List<Placement>[][] getCourses()

    - #### addVariable

          public void addVariable(Lecture lecture)

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

    - #### weaken

          public void weaken(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>`