acceptanceProbability

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.

Return

The acceptance probability, which is a value between 0.0 and 1.0. A higher probability indicates a greater likelihood of accepting the new solution. If costDifference is less than or equal to 0, the probability is 1.0. Otherwise, it is calculated as exp(-costDifference / temperature).

Parameters

costDifference

The difference in cost between the current solution and the new solution. A positive value indicates the new solution is worse, and a negative value indicates it is better.

temperature

The current temperature in the simulated annealing process. Must be greater than zero.

Throws

If the temperature is not positive.