exact solution and fixed start

This commit is contained in:
2025-08-18 09:06:49 +02:00
parent d0ec4db293
commit 2e85f0b9cc

View File

@@ -74,7 +74,7 @@ computeMatrix = {}
computeMatrix['length'] = [[c['length'] for c in r] for r in matrix] computeMatrix['length'] = [[c['length'] for c in r] for r in matrix]
computeMatrix['duration'] = [[c['duration'] for c in r] for r in matrix] computeMatrix['duration'] = [[c['duration'] for c in r] for r in matrix]
tour = fast_tsp.find_tour(computeMatrix[byWhat], 60) tour = fast_tsp.solve_tsp_exact(computeMatrix[byWhat])
print('Parametry cesty:') print('Parametry cesty:')
print('Délka:', fast_tsp.compute_cost(tour, computeMatrix['length'])/1000, 'km') print('Délka:', fast_tsp.compute_cost(tour, computeMatrix['length'])/1000, 'km')
duration = fast_tsp.compute_cost(tour, computeMatrix['duration']) duration = fast_tsp.compute_cost(tour, computeMatrix['duration'])
@@ -83,9 +83,12 @@ print('Doba:', duration//3600, 'h', (duration%3600)//60, 'm', duration%60, 's')
# compute path # compute path
gpx = gpxpy.gpx.GPX() gpx = gpxpy.gpx.GPX()
points: list[gpxpy.gpx.GPXTrackPoint] = [] points: list[gpxpy.gpx.GPXTrackPoint] = []
start = tour.index(0)
for i in range(0, len(tour)): for i in range(0, len(tour)):
s = tour[i] s = tour[(start+i)%len(tour)]
e = tour[(i+1)%len(tour)] e = tour[(start+i+1)%len(tour)]
url = 'https://api.mapy.cz/v1/routing/route' url = 'https://api.mapy.cz/v1/routing/route'
headers = {'accept': 'application/json'} headers = {'accept': 'application/json'}
payload = {} payload = {}