-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtsp.py
39 lines (31 loc) · 856 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
35
36
37
38
39
import city
import random
class TSP():
def __init__(self,n): #n is the number of cities to be generated
self.initial_cities = []
self.countries = []
i = 0
while i < n:
newCity = city.City(i)
self.initial_cities.append(newCity)
i+=1
def makeCountries(self, n):
i = 0
cities = self.initial_cities[:]
while i < n:
newCountry = city.Country(self.initial_cities)
newCountry.shuffleCities()
self.countries.append(newCountry)
i += 1
return(self.countries)
def bestSolution(self): #determines best solution and returns the country(agent) with the best solution
min = 0
min_agent = city.Country(self.initial_cities)
for country in self.countries:
current = country.costOfRoute()
if current < min:
min = current
min_agent = country
return (min_agent)
if __name__=="__main__":
main()