-
Notifications
You must be signed in to change notification settings - Fork 29
/
tsp.py
34 lines (24 loc) · 821 Bytes
/
tsp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from nodes_generator import NodeGenerator
from simulated_annealing import SimulatedAnnealing
def main():
'''set the simulated annealing algorithm params'''
temp = 1000
stopping_temp = 0.00000001
alpha = 0.9995
stopping_iter = 10000000
'''set the dimensions of the grid'''
size_width = 200
size_height = 200
'''set the number of nodes'''
population_size = 70
'''generate random list of nodes'''
nodes = NodeGenerator(size_width, size_height, population_size).generate()
'''run simulated annealing algorithm with 2-opt'''
sa = SimulatedAnnealing(nodes, temp, alpha, stopping_temp, stopping_iter)
sa.anneal()
'''animate'''
sa.animateSolutions()
'''show the improvement over time'''
sa.plotLearning()
if __name__ == "__main__":
main()