Class LinearCooling

  • All Implemented Interfaces:
    Splittable<AnnealingSchedule>, AnnealingSchedule

    public final class LinearCooling
    extends Object
    implements AnnealingSchedule

    This class implements the linear cooling schedule for simulated annealing. In this cooling schedule, the k-th temperature, tk, is determined as follows: tk = t0 - k * Δt, where t0 is the initial temperature and Δt is the difference between two consecutive temperature values. The new temperature is usually computed incrementally from the previous with: tk = tk-1 - Δt. In some applications, the temperature update occurs with each simulated annealing evaluation, while in others it is updated periodically, such as every s steps (i.e., iterations) of simulated annealing. This class supports this periodic update approach, with a default of every step. See the parameters of the constructors for more information.

    Additionally, if the temperature is ever less than 0.001, this class sets it to 0.001 for the remainder of the run. For any foreseeable cost scale that a problem may have, a temperature value of 0.001 is sufficiently low such that all moves that are worse than the current state will be rejected, so further cooling would be superfluous.

    The accept methods of this class use the classic, and most common, Boltzmann distribution for determining whether to accept a neighbor.

    • Constructor Summary

      Constructors 
      Constructor Description
      LinearCooling​(double t0, double deltaT)
      Constructs a linear cooling schedule for simulated annealing.
      LinearCooling​(double t0, double deltaT, int steps)
      Constructs a linear cooling schedule for simulated annealing.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean accept​(double neighborCost, double currentCost)
      Determine whether or not to accept a neighboring solution based on its cost and the current cost, both passed as parameters.
      void init​(int maxEvals)
      Perform any initialization necessary for the annealing schedule at to the start of a run of simulated annealing.
      LinearCooling split()
      Generates a functionally identical copy of this object, for use in multithreaded implementations of search algorithms.
    • Constructor Detail

      • LinearCooling

        public LinearCooling​(double t0,
                             double deltaT,
                             int steps)
        Constructs a linear cooling schedule for simulated annealing.
        Parameters:
        t0 - The initial temperature for the start of an annealing run. The value of t0 must be positive.
        deltaT - The difference between the current temperature and the next temperature. The value of deltaT must be positive.
        steps - The number of iterations of simulated annealing between cooling events. Steps must be positive. If 0 or a negative is passed for steps, steps is set to 1.
        Throws:
        IllegalArgumentException - if t0 ≤ 0 or deltaT ≤ 0.
      • LinearCooling

        public LinearCooling​(double t0,
                             double deltaT)
        Constructs a linear cooling schedule for simulated annealing.
        Parameters:
        t0 - The initial temperature for the start of an annealing run. The value of t0 must be positive.
        deltaT - The difference between the current temperature and the next temperature. The value of deltaT must be positive.
        Throws:
        IllegalArgumentException - if t0 ≤ 0 or deltaT ≤ 0.
    • Method Detail

      • init

        public void init​(int maxEvals)
        Description copied from interface: AnnealingSchedule
        Perform any initialization necessary for the annealing schedule at to the start of a run of simulated annealing. This includes initializing the temperature parameter. This method is called once by implementations of simulated annealing at the start of the run. Implementations of simulated annealing that perform reannealing will also call this once at the start of each reanneal.
        Specified by:
        init in interface AnnealingSchedule
        Parameters:
        maxEvals - The maximum length of the run of simulated annealing about to start. Some annealing schedules depend upon prior knowledge of run length. For those annealing schedules that don't depend upon run length, this parameter is ignored.
      • accept

        public boolean accept​(double neighborCost,
                              double currentCost)
        Description copied from interface: AnnealingSchedule
        Determine whether or not to accept a neighboring solution based on its cost and the current cost, both passed as parameters. Lower cost indicates better solution. This method must also update the temperature and any other state data related to the annealing schedule.
        Specified by:
        accept in interface AnnealingSchedule
        Parameters:
        neighborCost - The cost of the neighboring solution under consideration.
        currentCost - The cost of the current solution.
        Returns:
        true if simulated annealing should accept the neighbor, and false otherwise.
      • split

        public LinearCooling split()
        Description copied from interface: Splittable
        Generates a functionally identical copy of this object, for use in multithreaded implementations of search algorithms. The state of the object that is returned may or may not be identical to that of the original. Thus, this is a distinct concept from the functionality of the Copyable interface. Classes that implement this interface must ensure that the object returned performs the same functionality, and that it does not share any state data that would be either unsafe or inefficient for concurrent access by multiple threads. The split method is allowed to simply return the this reference, provided that it is both safe and efficient for multiple threads to share a single copy of the Splittable object. The intention is to provide a multithreaded search with the capability to provide spawned threads with their own distinct search operators. Such multithreaded algorithms can call the split method for each thread it spawns to generate a functionally identical copy of the operator, but with independent state.
        Specified by:
        split in interface Splittable<AnnealingSchedule>
        Returns:
        A functionally identical copy of the object, or a reference to this if it is both safe and efficient for multiple threads to share a single instance of this Splittable object.