Python implements simulated annealing algorithm to solve TSP problem (Implementing TSP with Simulated

Author: Zen and the Art of Computer Programming

1 Introduction

Introduction and Features of Simulated Annealing Algorithm

Simulated annealing algorithm (Simulated annealing) is a method of controlling the search for the optimal solution through temperature changes. Its characteristic is that at the current temperature, the system accepts a poorer solution with a certain probability and transfers to a better solution within a certain period of time. process. To put it simply, it means that all the solutions are bad at the beginning, and then gradually worse solutions are accepted. In each iteration, the algorithm will calculate the fitness value (objective function) of the solution at a certain moment, and judge whether to accept the solution according to its size, if accepted, the solution will be used as the current solution; otherwise, a new one will be randomly generated solution, and continue to iterate until a termination condition is reached or a certain maximum number of iterations is reached.

Specifically, the basic flow of the simulated annealing algorithm is as follows:

  1. Initialize an initial solution X, and calculate its fitness value f(X).

  2. Set the initial temperature T=1, and set the termination temperature threshold ε, generally set to ε=10^(-5), that is, stop the iteration when T is less than ε.

  3. In each iteration process, a new solution Xn is accepted according to a certain probability, and its fitness value fn(Xn) is also calculated.

  4. The temperature T is updated according to the following formula:

    T = alpha * T

    alpha is an attenuation coefficient, which is used to control the temperature drop rate. A larger alpha means that the temperature drops faster and the convergence is slower; while a smaller alpha means that the temperature drops slower and the convergence is faster. Generally take α=0.95.

  5. If fn(Xn)<fn(X), let X=Xn; otherwise, accept Xn with a certain probability

Guess you like

Origin blog.csdn.net/universsky2015/article/details/132438504