-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTSP-Text.py
More file actions
33 lines (29 loc) 路 1.11 KB
/
Copy pathTSP-Text.py
File metadata and controls
33 lines (29 loc) 路 1.11 KB
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
from TSP import *
from libs.GeneticAlgorithm import GeneticAlgorithm
def main():
poland = Country()
poland.add([
City('Gorlice', (49.655299, 21.159769)),
City('Sosnowiec', (50.286263, 19.104078)),
City('艁贸d藕', (51.760229, 19.457209)),
City('Wroc艂aw', (51.108314, 17.037802)),
City('Pozna艅', (52.406376, 16.925167)),
City('Toru艅', (53.013790, 18.598444)),
City('Zielona G贸ra', (51.935619, 15.506186)),
City('Szczecin', (53.428543, 14.552812)),
City('Rzesz贸w', (50.041187, 21.999121)),
City('Krak贸w', (50.049683, 19.944544)),
City('Olsztyn', (53.770226, 20.490189)),
City('Lublin', (51.245376, 22.568278))
])
print('Cities:', end=' ')
print(*(city for city in poland.cities), sep=', ')
ga = GeneticAlgorithm(100, mutation_rate=0.5, ptype=Route, args=(poland.cities,))
ga.run(seconds=10)
fittest = ga.alltime_best
best_fitness = fittest.fitness
print('Best route:', fittest)
print('Best fitness:', best_fitness)
print('Generations:', ga.generation)
if __name__ == '__main__':
main()