Package es.urjc.etsii.grafo.improve.sa
Class SimulatedAnnealing<M extends Move<S,I>,S extends Solution<S,I>,I extends Instance>
java.lang.Object
es.urjc.etsii.grafo.improve.Improver<S,I>
es.urjc.etsii.grafo.improve.sa.SimulatedAnnealing<M,S,I>
- Type Parameters:
M
- Move typeS
- Solution typeI
- Instance type
public class SimulatedAnnealing<M extends Move<S,I>,S extends Solution<S,I>,I extends Instance>
extends Improver<S,I>
Simulated annealing (SA) is a metaheuristic whose name comes from annealing in metallurgy.
This metaheuristic considers some neighboring state s* of the current state s,
and probabilistically decides between moving the system to state s* or staying in-state s.
The transition is always performed if it improves the current solution, while it depends on the current temperature if not.
The decision to transition is controlled by the
AcceptanceCriteria
.
These probabilities ultimately lead the system to move to lower energy states. After each possible transition,
the current temperature is lowered, using the CoolDownControl
.
The process is repeated until the TerminationCriteria
is met.
The initial temperature is configured using InitialTemperatureCalculator
,
which usually defaults to something like the Max diff between the moves in the neighborhood,
as implemented in MaxDifferenceInitialTemperature
.- See Also:
-
Nested Class Summary
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final AcceptanceCriteria
<M, S, I> protected final CoolDownControl
<M, S, I> protected final int
protected final InitialTemperatureCalculator
<M, S, I> protected final RandomizableNeighborhood
<M, S, I> protected final TerminationCriteria
<M, S, I> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
SimulatedAnnealing
(Objective<M, S, I> objective, AcceptanceCriteria<M, S, I> acceptanceCriteria, RandomizableNeighborhood<M, S, I> ps, InitialTemperatureCalculator<M, S, I> initialTemperatureCalculator, TerminationCriteria<M, S, I> terminationCriteria, CoolDownControl<M, S, I> coolDownControl, int cycleLength) Internal constructor, useSimulatedAnnealingBuilder
. -
Method Summary
Modifier and TypeMethodDescriptionprotected es.urjc.etsii.grafo.improve.sa.SimulatedAnnealing.CycleResult
<S> doCycle
(RandomizableNeighborhood<M, S, I> neighborhood, S solution, S best, double currentTemperature, int currentIteration) Does a cycle with the same temperature.Improves a model.Solution Iterates until we run out of time, or we cannot improve the current es.urjc.etsii.grafo.solution any furtherprotected boolean
Methods inherited from class es.urjc.etsii.grafo.improve.Improver
getObjective, nul, serial, serial
-
Field Details
-
objective
-
acceptanceCriteria
-
neighborhood
-
terminationCriteria
-
coolDownControl
-
initialTemperatureCalculator
-
cycleLength
protected final int cycleLength
-
-
Constructor Details
-
SimulatedAnnealing
protected SimulatedAnnealing(Objective<M, S, I> objective, AcceptanceCriteria<M, S, I> acceptanceCriteria, RandomizableNeighborhood<M, S, I> ps, InitialTemperatureCalculator<M, S, I> initialTemperatureCalculator, TerminationCriteria<M, S, I> terminationCriteria, CoolDownControl<M, S, I> coolDownControl, int cycleLength) Internal constructor, useSimulatedAnnealingBuilder
.- Parameters:
acceptanceCriteria
-ps
-initialTemperatureCalculator
-terminationCriteria
-coolDownControl
-cycleLength
-
-
-
Method Details
-
shouldEnd
-
improve
Description copied from class:Improver
Improves a model.Solution Iterates until we run out of time, or we cannot improve the current es.urjc.etsii.grafo.solution any further -
doCycle
protected es.urjc.etsii.grafo.improve.sa.SimulatedAnnealing.CycleResult<S> doCycle(RandomizableNeighborhood<M, S, I> neighborhood, S solution, S best, double currentTemperature, int currentIteration) Does a cycle with the same temperature. Always works on the same solution. Fast implementation that can only be used if theNeighborhood
implementsRandomizableNeighborhood
.- Parameters:
solution
- current working solutionbest
- best solution found until nowcurrentTemperature
- current temperaturecurrentIteration
- current iteration- Returns:
- best solution found, remember that you should NOT use the returned solution
-