Class AcceptanceTracker

  • All Implemented Interfaces:
    Splittable<AnnealingSchedule>, AnnealingSchedule

    public final class AcceptanceTracker
    extends Object
    implements AnnealingSchedule
    An AcceptanceTracker can be used to extract fine-grained information about the behavior of an annealing schedule across several runs of simulated annealing. Specifically, it can be used to compute the rate of neighbor acceptance, across a set of runs of SA, as it changes from the beginning of the run to the end of the run.
    • 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.
      double getAcceptanceRate​(int iterationIndex)
      Computes the acceptance rate for a specific iteration number computed across all runs since either the last call to reset(int) or since the last run of simulated annealing with a different run length.
      void init​(int maxEvals)
      Perform any initialization necessary for the annealing schedule at to the start of a run of simulated annealing.
      void reset​(int maxEvals)
      Resets the AcceptanceTracker.
      AcceptanceTracker split()
      Generates a functionally identical copy of this object, for use in multithreaded implementations of search algorithms.
    • Constructor Detail

      • AcceptanceTracker

        public AcceptanceTracker​(AnnealingSchedule schedule)
        Constructs the AcceptanceTracker.
        Parameters:
        schedule - The AnnealingSchedule object.
    • Method Detail

      • getAcceptanceRate

        public double getAcceptanceRate​(int iterationIndex)
        Computes the acceptance rate for a specific iteration number computed across all runs since either the last call to reset(int) or since the last run of simulated annealing with a different run length.
        Parameters:
        iterationIndex - The iteration number of interest, which must be in the interval: 0 ≤ iterationIndex < maxEvals, where maxEvals is the run length of simulation annealing.
        Returns:
        The acceptance rate across all runs since the last call to reset or since the last change in run length, computed at iteration iterationIndex.
        Throws:
        ArrayIndexOutOfBoundsException - if iterationIndex is negative or too high.
        NullPointerException - if reset has not been called and no runs of simulated annealing have been performed.
      • reset

        public void reset​(int maxEvals)
        Resets the AcceptanceTracker.
        Parameters:
        maxEvals - The length of the simulated annealing run.
        Throws:
        IllegalArgumentException - if maxEvals ≤ 0.
      • 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 AcceptanceTracker 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.