org.cpsolver.ifs.algorithms

## Class SimulatedAnnealing.SimulatedAnnealingContext

- java.lang.Object
- - org.cpsolver.ifs.algorithms.NeighbourSearch.NeighbourSearchContext
  - - org.cpsolver.ifs.algorithms.SimulatedAnnealing.SimulatedAnnealingContext

- All Implemented Interfaces:
    AssignmentContext, SolutionListener<V,T>
  Enclosing class:
    SimulatedAnnealing<V extends Variable<V,T>,T extends Value<V,T>>

      public class SimulatedAnnealing.SimulatedAnnealingContext
      extends NeighbourSearch.NeighbourSearchContext

- - ### Field Summary

    - ### Fields inherited from class org.cpsolver.ifs.algorithms.NeighbourSearch.NeighbourSearchContext

      `iIter, iT0`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SimulatedAnnealingContext()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected boolean` | `accept(Assignment<V,T> assignment, Model<V,T> model, Neighbour<V,T> neighbour, double value, boolean lazy)` True if the given neighbour is to be be accepted
    `protected void` | `activate(Solution<V,T> solution)` Setup the temperature
    `void` | `bestSaved(Solution<V,T> solution)` Memorize the iteration when the last best solution was found.
    `protected void` | `cool(Solution<V,T> solution)` Cool temperature
    `protected double` | `getCoolingRate(int idx)`
    `protected void` | `incIteration(Solution<V,T> solution)` Increment iteration counter, cool/reheat/restoreBest if necessary
    `protected double` | `prob(double value)` Neighbour acceptance probability
    `protected void` | `reheat(Solution<V,T> solution)` Reheat temperature
    `protected void` | `restoreBest(Solution<V,T> solution)` restore best ever found solution
    `protected void` | `train(Solution<V,T> solution)` Set initial temperature based on the training period

    - ### Methods inherited from class org.cpsolver.ifs.algorithms.NeighbourSearch.NeighbourSearchContext

      `bestCleared, bestRestored, canContinue, deactivate, getInfo, getInfo, getTimeMillis, solutionUpdated`

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

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

- - ### Constructor Detail

    - #### SimulatedAnnealingContext

          public SimulatedAnnealingContext()

  - ### Method Detail

    - #### activate

          protected void activate(Solution<V,T> solution)

      Setup the temperature
      Overrides:
        `activate` in class `NeighbourSearch.NeighbourSearchContext`
      Parameters:
        `solution` - current solution

    - #### getCoolingRate

          protected double getCoolingRate(int idx)

    - #### train

          protected void train(Solution<V,T> solution)

      Set initial temperature based on the training period
      Parameters:
        `solution` - current solution

    - #### cool

          protected void cool(Solution<V,T> solution)

      Cool temperature
      Parameters:
        `solution` - current solution

    - #### reheat

          protected void reheat(Solution<V,T> solution)

      Reheat temperature
      Parameters:
        `solution` - current solution

    - #### restoreBest

          protected void restoreBest(Solution<V,T> solution)

      restore best ever found solution
      Parameters:
        `solution` - current solution

    - #### prob

          protected double prob(double value)

      Neighbour acceptance probability
      Parameters:
        `value` - absolute or relative value of the proposed change (neighbour)
      Returns:
        probability of acceptance of a change (neighbour)

    - #### accept

          protected boolean accept(Assignment<V,T> assignment,
                                   Model<V,T> model,
                                   Neighbour<V,T> neighbour,
                                   double value,
                                   boolean lazy)

      True if the given neighbour is to be be accepted
      Specified by:
        `accept` in class `NeighbourSearch.NeighbourSearchContext`
      Parameters:
        `assignment` - current assignment
        `neighbour` - proposed move
        `model` - problem model
        `value` - value of the generated move (i.e., its impact on the solution value)
        `lazy` - true if lazy move
      Returns:
        true if generated random number is below the generated probability

    - #### incIteration

          protected void incIteration(Solution<V,T> solution)

      Increment iteration counter, cool/reheat/restoreBest if necessary
      Overrides:
        `incIteration` in class `NeighbourSearch.NeighbourSearchContext`
      Parameters:
        `solution` - current solution

    - #### bestSaved

          public void bestSaved(Solution<V,T> solution)

      Memorize the iteration when the last best solution was found.
      Specified by:
        `bestSaved` in interface `SolutionListener<V extends Variable<V,T>,T extends Value<V,T>>`
      Overrides:
        `bestSaved` in class `NeighbourSearch.NeighbourSearchContext`
      Parameters:
        `solution` - source solution