SimulatedAnnealing

class SimulatedAnnealing(evaluator: EvaluatorIfc, initialTemperature: Double = defaultInitialTemperature, var coolingSchedule: CoolingScheduleIfc = ExponentialCoolingSchedule(initialTemperature), stoppingTemperature: Double = defaultStoppingTemperature, maxIterations: Int = defaultMaxNumberIterations, var replicationsPerEvaluation: ReplicationPerEvaluationIfc, streamNum: Int = 0, val streamProvider: RNStreamProviderIfc = KSLRandom.DefaultRNStreamProvider, name: String? = null) : StochasticSolver

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

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(evaluator: EvaluatorIfc, initialTemperature: Double = defaultInitialTemperature, coolingSchedule: CoolingScheduleIfc = ExponentialCoolingSchedule(initialTemperature), 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.

constructor(evaluator: EvaluatorIfc, initialTemperature: Double = defaultInitialTemperature, coolingSchedule: CoolingScheduleIfc = ExponentialCoolingSchedule(initialTemperature), 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.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

If true, the stream will automatically participate in having its stream advanced to the next sub-stream via stream managers

Link copied to clipboard
open override var antithetic: Boolean

Tells the stream to start producing antithetic variates

Link copied to clipboard

The best solution found so far in the search. Some algorithms may allow the current solution to vary from the best solution due to randomness or other search needs (e.g., explore bad areas with the hope of getting better). The algorithm should ensure the updating of the best solution found across any iteration.

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 point (input settings) of the solver during its iterative process.

Link copied to clipboard

The current (or last) solution that was accepted as a possible solution to recommend for the solver. It is the responsibility of the subclass to determine the current solution.

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
open override val emitter: Emitter<Solution>
Link copied to clipboard

Indicates whether the solver allows infeasible requests to be sent to the evaluator. The default is false. That is, the solver is allowed to send infeasible problem requests for evaluation by the evaluator.

Link copied to clipboard
open override val id: Int
Link copied to clipboard

The initial point associated with the initial solution.

Link copied to clipboard

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

Link copied to clipboard

Returns the number of times the main iteration function was called.

Link copied to clipboard

Allow the status of the iterative process to be accessible

Link copied to clipboard
open override var label: String?
Link copied to clipboard

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

Link copied to clipboard

The maximum number of iterations when sampling for an input feasible point

Link copied to clipboard

The maximum number of iterations permitted for the main loop. This must be greater than 0.

Link copied to clipboard
open override val name: String
Link copied to clipboard

The user can supply a function that will generate a neighbor for the evaluation process. If supplied, this function will be used instead of the pre-defined generateNeighbor() function. The user may also override the generateNeighbor() function when developing subclasses.

Link copied to clipboard

Counts the number of times that a new current solution replaced the current best solution. This can be used to measure how often an iteration results in a better solution being found.

Link copied to clipboard

The difference between the previous solution's penalized objective function value and the current solution's penalized objective function value.

Link copied to clipboard

The previous point in the solution process. It is associated with the previous solution.

Link copied to clipboard

The previous solution in the sequence of solutions.

Link copied to clipboard

A convenience property to access the problem being solved

Link copied to clipboard
open override var resetStartStreamOption: Boolean

If true, the stream will automatically participate in having its stream reset to its start stream via stream managers

Link copied to clipboard

rnStream provides a reference to the underlying stream of random numbers

Link copied to clipboard

If true, updates to the current solution will be captured automatically to memory. The default is false.

Link copied to clipboard

The user can supply a comparator for comparing whether one solution is smaller, equal to, or larger than another solution. If supplied, this function will be used instead of the implemented compare() function. The user can supply a function or override the compare function to specialize how solutions are compared.

Link copied to clipboard

A variable representing an instance of the SolutionQualityEvaluatorIfc interface. It is used to assess and evaluate the quality of a given solution. The variable can hold a nullable implementation of the interface.

Link copied to clipboard

A read-only view of the solutions evaluated by the solver. Not all solvers retain past solutions. Also, in general, the evaluator will have access to a cache of solutions.

Link copied to clipboard

An initial starting point for the solver. If supplied, this point will be used instead of the returned value of the startingPoint() function. The default is null, which indicates that the function should be called to obtain the initial starting point.

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.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

The difference between the previous solution's unpenalized objective function value and the current solution's unpenalized objective function value.

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
open override fun advanceToNextSubStream()

Positions the RNG at the beginning of its next substream

Link copied to clipboard
open override fun compare(first: Solution, second: Solution): Int

Recognizing the need to be able to compare solutions that may have sampling error, the user can override this function to provide more extensive comparison or supply an instance of the CompareSolutionsIfc interface via the solutionComparer property Returns -1 if first is less than the second solution, 0 if the solutions are to be considered equivalent, and 1 if the first is larger than the second solution.

Link copied to clipboard
fun endIterations(msg: String? = null)

Note that the iterations can only be ended before running all iterations or before running the next iteration. Use stopIterations() to cause a graceful completion of inner and outer iterations.

Link copied to clipboard

Generates a random neighbor of the current point that satisfies input feasibility constraints. The method attempts to generate a feasible point by randomizing the input variables of the current point. If a feasible point cannot be generated within a maximum number of iterations, an exception is thrown.

Link copied to clipboard

Checks if the iterative process has additional iterations to execute. This does not check other stopping criteria related to solution quality or convergence. This is about how many iterations have been executed from the maximum specified.

Link copied to clipboard

Causes the solver to be initialized. It will then be in a state that allows for the running of the iterations.

Link copied to clipboard
open override fun resetStartStream()

The resetStartStream method will position the RNG at the beginning of its stream. This is the same location in the stream as assigned when the RNG was created and initialized.

Link copied to clipboard
open override fun resetStartSubStream()

Resets the position of the RNG at the start of the current substream

Link copied to clipboard

Causes the solver to run all iterations until its stopping criteria is met or the maximum number of iterations has been reached.

Link copied to clipboard

Runs the next iteration. Only valid if the solver has been initialized and there are additional iterations to run.

Link copied to clipboard
fun stopIterations(msg: String? = null)

Causes a graceful stopping of the iterative processes for the solver. The inner process will complete its current iteration, and then no more outer iterations will start.

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