net.sf.cpsolver.ifs.criteria

## Class AbstractCriterion<V extends Variable<V,T>,T extends Value<V,T>>

- java.lang.Object
- - net.sf.cpsolver.ifs.criteria.AbstractCriterion<V,T>

- All Implemented Interfaces:
    Criterion<V,T>, InfoProvider<V>, ModelListener<V,T>
  Direct Known Subclasses:
    AssignedValue, ExamCriterion, InstructorLunchBreak, TimetablingCriterion

      public abstract class AbstractCriterion<V extends Variable<V,T>,T extends Value<V,T>>
      extends Object
      implements Criterion<V,T>

  Abstract Criterion.
  An optimization objective can be split into several (optimization) criteria and modeled as a weighted sum of these. This makes the implementation of a particular problem more versatile as it allows for an easier modification of the optimization objective.
  This class implements most of the `Criterion` except of the `Criterion.getValue(Value, Set)`.
  Version:
    IFS 1.2 (Iterative Forward Search)
    Copyright (C) 2006 - 2011 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
    --- | ---
    `protected static class` | `AbstractCriterion.ValueUpdateType` Defines how the overall value of the criterion should be automatically updated (using `Criterion.getValue(Value, Set)`).

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected double` | `iBest`
    `protected boolean` | `iDebug`
    `protected double` | `iValue`
    `protected AbstractCriterion.ValueUpdateType` | `iValueUpdateType`
    `protected double` | `iWeight`
    `protected static DecimalFormat` | `sDoubleFormat`
    `protected static DecimalFormat` | `sPercentFormat`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractCriterion()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `afterAssigned(long iteration, T value)` Called after a value is assigned to its variable ( `Value.variable()`).
    `void` | `afterUnassigned(long iteration, T value)` Called after a value is unassigned from its variable ( `Value.variable()`).
    `void` | `beforeAssigned(long iteration, T value)` Called before a value is assigned to its variable ( `Value.variable()`).
    `void` | `beforeUnassigned(long iteration, T value)` Called before a value is unassigned from its variable ( `Value.variable()`).
    `void` | `bestRestored()` Notification that the current solution has been restored from the best.
    `void` | `bestSaved()` Notification that the current solution has been saved to the best.
    `protected void` | `clearCache()` Clear bounds cache
    `protected double[]` | `computeBounds()` Compute bounds (bounds are being cached by default).
    `void` | `constraintAdded(Constraint<V,T> constraint)` Constraint is added to the model
    `void` | `constraintRemoved(Constraint<V,T> constraint)` Constraint is removed from the model
    `double` | `getBest()` Best value (value of the criterion in the best solution)
    `double[]` | `getBounds()` Bounds (minimum and maximum) estimate for the value
    `double[]` | `getBounds(Collection<V> variables)` Value bounds (minimum and maximum) of the criterion on a part of the problem
    `void` | `getInfo(Map<String,String> info)` Adds some information into the table with information about the solution
    `void` | `getInfo(Map<String,String> info, Collection<V> variables)` Adds some information into the table with information about the solution, only consider variables from the given set
    `Model<V,T>` | `getModel()` Returns current model
    `String` | `getName()` Criterion name
    `protected String` | `getPerc(double value, double min, double max)`
    `protected String` | `getPercRev(double value, double min, double max)`
    `double` | `getValue()` Current value of the criterion (optimization objective)
    `double` | `getValue(Collection<V> variables)` Value of a part of the problem (given by the collection of variables)
    `double` | `getWeight()` Weight of the criterion
    `double` | `getWeightDefault(DataProperties config)` Defines default weight (when `getWeightName()` parameter is not present in the criterion).
    `double` | `getWeightedBest()` Weighted best value of the objective (value in the best solution).
    `double` | `getWeightedValue()` Weighted value of the objectives
    `double` | `getWeightedValue(Collection<V> variables)` Weighted value of a part of the problem (given by the collection of variables)
    `double` | `getWeightedValue(T value, Set<T> conflicts)` Weighted value of a proposed assignment (including hard conflicts)
    `String` | `getWeightName()` Defines weight name (to be used to get the criterion weight from the configuration).
    `void` | `inc(double value)` Outside update of the criterion (usefull when the criterion is driven by a set of constraints).
    `boolean` | `init(Solver<V,T> solver)` Notification that the model was initialized by the solver.
    `void` | `variableAdded(V variable)` Variable is added to the model
    `void` | `variableRemoved(V variable)` Variable is removed from the model

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

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface net.sf.cpsolver.ifs.criteria.Criterion

      `getValue`

- - ### Field Detail

    - #### iBest

          protected double iBest

    - #### iValue

          protected double iValue

    - #### iWeight

          protected double iWeight

    - #### sDoubleFormat

          protected static DecimalFormat sDoubleFormat

    - #### sPercentFormat

          protected static DecimalFormat sPercentFormat

    - #### iDebug

          protected boolean iDebug

    - #### iValueUpdateType

          protected AbstractCriterion.ValueUpdateType iValueUpdateType

  - ### Constructor Detail

    - #### AbstractCriterion

          public AbstractCriterion()

  - ### Method Detail

    - #### getWeightName

          public String getWeightName()

      Defines weight name (to be used to get the criterion weight from the configuration).

    - #### getWeightDefault

          public double getWeightDefault(DataProperties config)

      Defines default weight (when `getWeightName()` parameter is not present in the criterion).

    - #### init

          public boolean init(Solver<V,T> solver)

      Description copied from interface: `ModelListener`
      Notification that the model was initialized by the solver.
      Specified by:
        `init` in interface `ModelListener<V extends Variable<V,T>,T extends Value<V,T>>`
      Parameters:
        `solver` - IFS solver

    - #### getModel

          public Model<V,T> getModel()

      Returns current model

    - #### getValue

          public double getValue()

      Description copied from interface: `Criterion`
      Current value of the criterion (optimization objective)
      Specified by:
        `getValue` in interface `Criterion<V extends Variable<V,T>,T extends Value<V,T>>`

    - #### getBest

          public double getBest()

      Description copied from interface: `Criterion`
      Best value (value of the criterion in the best solution)
      Specified by:
        `getBest` in interface `Criterion<V extends Variable<V,T>,T extends Value<V,T>>`

    - #### getValue

          public double getValue(Collection<V> variables)

      Description copied from interface: `Criterion`
      Value of a part of the problem (given by the collection of variables)
      Specified by:
        `getValue` in interface `Criterion<V extends Variable<V,T>,T extends Value<V,T>>`

    - #### getWeight

          public double getWeight()

      Description copied from interface: `Criterion`
      Weight of the criterion
      Specified by:
        `getWeight` in interface `Criterion<V extends Variable<V,T>,T extends Value<V,T>>`

    - #### getWeightedBest

          public double getWeightedBest()

      Description copied from interface: `Criterion`
      Weighted best value of the objective (value in the best solution).
      Specified by:
        `getWeightedBest` in interface `Criterion<V extends Variable<V,T>,T extends Value<V,T>>`

    - #### getWeightedValue

          public double getWeightedValue()

      Description copied from interface: `Criterion`
      Weighted value of the objectives
      Specified by:
        `getWeightedValue` in interface `Criterion<V extends Variable<V,T>,T extends Value<V,T>>`

    - #### getWeightedValue

          public double getWeightedValue(T value,
                                         Set<T> conflicts)

      Description copied from interface: `Criterion`
      Weighted value of a proposed assignment (including hard conflicts)
      Specified by:
        `getWeightedValue` in interface `Criterion<V extends Variable<V,T>,T extends Value<V,T>>`

    - #### getWeightedValue

          public double getWeightedValue(Collection<V> variables)

      Description copied from interface: `Criterion`
      Weighted value of a part of the problem (given by the collection of variables)
      Specified by:
        `getWeightedValue` in interface `Criterion<V extends Variable<V,T>,T extends Value<V,T>>`

    - #### computeBounds

          protected double[] computeBounds()

      Compute bounds (bounds are being cached by default).

    - #### getBounds

          public double[] getBounds()

      Description copied from interface: `Criterion`
      Bounds (minimum and maximum) estimate for the value
      Specified by:
        `getBounds` in interface `Criterion<V extends Variable<V,T>,T extends Value<V,T>>`

    - #### getBounds

          public double[] getBounds(Collection<V> variables)

      Description copied from interface: `Criterion`
      Value bounds (minimum and maximum) of the criterion on a part of the problem
      Specified by:
        `getBounds` in interface `Criterion<V extends Variable<V,T>,T extends Value<V,T>>`

    - #### beforeAssigned

          public void beforeAssigned(long iteration,
                                     T value)

      Description copied from interface: `ModelListener`
      Called before a value is assigned to its variable ( `Value.variable()`).
      Specified by:
        `beforeAssigned` in interface `ModelListener<V extends Variable<V,T>,T extends Value<V,T>>`
      Parameters:
        `iteration` - current iteration
        `value` - value to be assigned

    - #### afterAssigned

          public void afterAssigned(long iteration,
                                    T value)

      Description copied from interface: `ModelListener`
      Called after a value is assigned to its variable ( `Value.variable()`).
      Specified by:
        `afterAssigned` in interface `ModelListener<V extends Variable<V,T>,T extends Value<V,T>>`
      Parameters:
        `iteration` - current iteration
        `value` - value to be assigned

    - #### beforeUnassigned

          public void beforeUnassigned(long iteration,
                                       T value)

      Description copied from interface: `ModelListener`
      Called before a value is unassigned from its variable ( `Value.variable()`).
      Specified by:
        `beforeUnassigned` in interface `ModelListener<V extends Variable<V,T>,T extends Value<V,T>>`
      Parameters:
        `iteration` - current iteration
        `value` - value to be unassigned

    - #### afterUnassigned

          public void afterUnassigned(long iteration,
                                      T value)

      Description copied from interface: `ModelListener`
      Called after a value is unassigned from its variable ( `Value.variable()`).
      Specified by:
        `afterUnassigned` in interface `ModelListener<V extends Variable<V,T>,T extends Value<V,T>>`
      Parameters:
        `iteration` - current iteration
        `value` - value to be unassigned

    - #### bestSaved

          public void bestSaved()

      Description copied from interface: `Criterion`
      Notification that the current solution has been saved to the best.
      Specified by:
        `bestSaved` in interface `Criterion<V extends Variable<V,T>,T extends Value<V,T>>`

    - #### bestRestored

          public void bestRestored()

      Description copied from interface: `Criterion`
      Notification that the current solution has been restored from the best.
      Specified by:
        `bestRestored` in interface `Criterion<V extends Variable<V,T>,T extends Value<V,T>>`

    - #### inc

          public void inc(double value)

      Description copied from interface: `Criterion`
      Outside update of the criterion (usefull when the criterion is driven by a set of constraints).
      Specified by:
        `inc` in interface `Criterion<V extends Variable<V,T>,T extends Value<V,T>>`

    - #### getName

          public String getName()

      Description copied from interface: `Criterion`
      Criterion name
      Specified by:
        `getName` in interface `Criterion<V extends Variable<V,T>,T extends Value<V,T>>`

    - #### clearCache

          protected void clearCache()

      Clear bounds cache

    - #### variableAdded

          public void variableAdded(V variable)

      Description copied from interface: `ModelListener`
      Variable is added to the model
      Specified by:
        `variableAdded` in interface `ModelListener<V extends Variable<V,T>,T extends Value<V,T>>`
      Parameters:
        `variable` - added variable

    - #### variableRemoved

          public void variableRemoved(V variable)

      Description copied from interface: `ModelListener`
      Variable is removed from the model
      Specified by:
        `variableRemoved` in interface `ModelListener<V extends Variable<V,T>,T extends Value<V,T>>`
      Parameters:
        `variable` - removed variable

    - #### constraintAdded

          public void constraintAdded(Constraint<V,T> constraint)

      Description copied from interface: `ModelListener`
      Constraint is added to the model
      Specified by:
        `constraintAdded` in interface `ModelListener<V extends Variable<V,T>,T extends Value<V,T>>`
      Parameters:
        `constraint` - added constraint

    - #### constraintRemoved

          public void constraintRemoved(Constraint<V,T> constraint)

      Description copied from interface: `ModelListener`
      Constraint is removed from the model
      Specified by:
        `constraintRemoved` in interface `ModelListener<V extends Variable<V,T>,T extends Value<V,T>>`
      Parameters:
        `constraint` - removed constraint

    - #### getPerc

          protected String getPerc(double value,
                                   double min,
                                   double max)

    - #### getPercRev

          protected String getPercRev(double value,
                                      double min,
                                      double max)

    - #### getInfo

          public void getInfo(Map<String,String> info)

      Description copied from interface: `InfoProvider`
      Adds some information into the table with information about the solution
      Specified by:
        `getInfo` in interface `InfoProvider<V extends Variable<V,T>>`

    - #### getInfo

          public void getInfo(Map<String,String> info,
                              Collection<V> variables)

      Description copied from interface: `InfoProvider`
      Adds some information into the table with information about the solution, only consider variables from the given set
      Specified by:
        `getInfo` in interface `InfoProvider<V extends Variable<V,T>>`