SimulatedAnnealing

class SimulatedAnnealing @JvmOverloads constructor(problemDefinition: ProblemDefinition, evaluator: EvaluatorIfc, val temperatureConfiguration: TemperatureConfiguration = TemperatureConfiguration.Fixed(defaultInitialTemperature), var coolingSchedule: CoolingScheduleIfc = ExponentialCoolingSchedule(defaultInitialTemperature), stoppingTemperature: Double = defaultStoppingTemperature, maxIterations: Int = defaultMaxNumberIterations, replicationsPerEvaluation: ReplicationPerEvaluationIfc, streamNum: Int = 0, streamProvider: RNStreamProviderIfc = KSLRandom.DefaultRNStreamProvider, name: String? = null) : StochasticSolver(source)

A class that implements the simulated annealing optimization algorithm for solving stochastic or deterministic problems. Simulated annealing is an iterative optimization method inspired by the physical process of annealing in metallurgy. It uses a probabilistic approach to escape local optima by accepting worse solutions with a certain probability, which decreases over time according to a cooling schedule.

Parameters

problemDefinition

the problem being solved

evaluator

The evaluator responsible for calculating the objective function value of a solution. It must implement the EvaluatorIfc interface.

initialTemperature

The starting temperature for the simulated annealing algorithm. Must be greater than 0.0.

coolingSchedule

the cooling schedule for the annealing process

stoppingTemperature

the temperature used to stop the annealing process. If the current temperature goes below this temperature, the search process stops.

maxIterations

the maximum number of iterations permitted for the search process

replicationsPerEvaluation

An instance of ReplicationPerEvaluationIfc defining the strategy for determining the number of replications per evaluation.

rnStream

An optional random number stream used for stochastic behavior. Defaults to KSLRandom.defaultRNStream().

name

An optional name for this solver instance.

Constructors

Link copied to clipboard
constructor(problemDefinition: ProblemDefinition, evaluator: EvaluatorIfc, temperatureConfiguration: TemperatureConfiguration = TemperatureConfiguration.Fixed(defaultInitialTemperature), coolingSchedule: CoolingScheduleIfc = ExponentialCoolingSchedule(defaultInitialTemperature), stoppingTemperature: Double = defaultStoppingTemperature, maxIterations: Int = defaultMaxNumberIterations, replicationsPerEvaluation: ReplicationPerEvaluationIfc, streamNum: Int = 0, streamProvider: RNStreamProviderIfc = KSLRandom.DefaultRNStreamProvider, name: String? = null)

Constructs a SimulatedAnnealing solver with the specified parameters.

constructor(problemDefinition: ProblemDefinition, evaluator: EvaluatorIfc, temperatureConfiguration: TemperatureConfiguration = TemperatureConfiguration.Fixed(defaultInitialTemperature), coolingSchedule: CoolingScheduleIfc = ExponentialCoolingSchedule(defaultInitialTemperature), stoppingTemperature: Double = defaultStoppingTemperature, maxIterations: Int = defaultMaxNumberIterations, replicationsPerEvaluation: Int = defaultReplicationsPerEvaluation, streamNum: Int = 0, streamProvider: RNStreamProviderIfc = KSLRandom.DefaultRNStreamProvider, name: String? = null)

Secondary constructor for the SimulatedAnnealing class. This constructor provides a simplified way to initialize the Simulated Annealing algorithm with configurable parameters, while delegating certain default parameters to their respective values or functional objects.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
Link copied to clipboard

Represents the difference in cost between the current solution and a potential new solution in the simulated annealing process. This value directly influences the acceptance probability of new solutions as the algorithm progresses.

Link copied to clipboard

Represents the current temperature in the simulated annealing process. It is initialized to the value of initialTemperature and dynamically updated during each iteration of the algorithm based on the cooling schedule.

Link copied to clipboard

Changing the initial temperature will also change it for the associated cooling schedule.

Link copied to clipboard

Tracks the last computed acceptance probability in the simulated annealing process.

Link copied to clipboard

Used to check if the last set of solutions that were captured are the same.

Link copied to clipboard

Represents the temperature threshold at which the simulated annealing algorithm will stop iterating. The stopping temperature serves as a termination criterion, ensuring the optimization process concludes when the system has sufficiently cooled. The target temperature below which the optimization process should stop. Must be greater than 0.0.

Functions

Link copied to clipboard
fun acceptanceProbability(costDifference: Double, temperature: Double): Double

Calculates the probability of accepting a new solution in the simulated annealing algorithm. The probability is determined based on the difference in cost between the current and new solutions, as well as the current temperature of the system.

Link copied to clipboard
protected open override fun initializeIterations()

Subclasses may implement this function to prepare the solver before running the first iteration. Generally, it is sufficient to just implement the startingPoint() function.

Link copied to clipboard
protected open override fun isStoppingCriteriaSatisfied(): Boolean

Subclasses should implement this function to determine if the solver should continue running iterations. This will likely include some implementation of stopping criteria. This function should implement stopping criteria based on the quality of the solution. The number of iterations, compared to the maximum number of iterations, is automatically checked after each step in the iterative process. Unless overridden, this function returns false by default, which indicates that the solution quality criteria have not been satisfied. This will cause the solver to iterate through all iterations of the solution process up to the maximum number of iterations. Alternatively, the user can specify an instance of the SolutionQualityEvaluatorIfc interface to determine if the solution quality has been reached.

Link copied to clipboard
protected open override fun mainIteration()

This function should contain the logic that iteratively executes until the maximum number of iterations is reached or until the stopping criteria is met. The base implementation calls nextPoint() to determine the next point to evaluate, requests an evaluation of the point, and then updates the current solution if the resulting solution is better than the current solution. Generally, implementing startingPoint() and nextPoint() should be adequate. The property iterationCounter represents the current iteration within the mainIteration() function. That is, the value of iterationCounter is incremented prior to the execution of the mainIteration() function.

Link copied to clipboard
open override fun toString(): String