Simulated annealing optimizer designed to solve Travelling Salesman Problem (TSP). Working of this optimizer consists of three stages:
- Stage 1: Greedy algorithm provides an initial solution,
- Stage 2: Simulated Annealing searches solutions space,
- Stage 3: 2-Opt algorithm improves the solution obtained in stage 2. (optional)
- Input should be in the form of a list [ [x_1, y_1], [x_2, y_2], ... , [x_n, y_n] ]
from random import randint
towns = []
for town in range(60):
towns.append([randint(0, 100), randint(0, 100)])
- How to initialize
from SimulatedAnnealing import SimulatedAnnealing
SA_optimizer = SimulatedAnnealing()
SA_optimizer.fit(towns, iterations=60000, cooling='polynomial', improve=True)
- Plotting results
SA_optimizer.plot()
- Visualization
SA_optimizer.show_graph(fitted=True)