can reverse

add argparse
add makeSymetric, but commented
This commit is contained in:
2025-09-01 22:44:54 +02:00
parent d6b54d55ab
commit c367a216ce

View File

@@ -10,6 +10,14 @@ import fast_tsp
import gpxpy
import gpxpy.gpx
import sys
import argparse
# copy down left triangle to up right
def makeSymmetric(matrix :list[list[int]]) -> list[list[int]]:
for i in range(0, len(matrix)):
for j in range(0, i):
matrix[j][i] = matrix[i][j]
return matrix
class Person:
name: str
@@ -29,7 +37,12 @@ key: str
matrix: list[list[dict[str, int]]] = []
byWhat: str
if len(sys.argv) == 2 and sys.argv[1] == "-l":
parser = argparse.ArgumentParser()
parser.add_argument("-l", "--length", action="store_true", help="Shortest length, otherwise time.")
parser.add_argument("-r", "--reverse", action="store_true", help="Other direction.")
args = parser.parse_args()
if args.length:
byWhat = 'length'
else:
byWhat = 'duration'
@@ -74,6 +87,9 @@ computeMatrix = {}
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['length'] = makeSymmetric(computeMatrix['length'])
#computeMatrix['duration'] = makeSymmetric(computeMatrix['duration'])
tour = fast_tsp.solve_tsp_exact(computeMatrix[byWhat])
print('Parametry cesty:')
print('Délka:', fast_tsp.compute_cost(tour, computeMatrix['length'])/1000, 'km')
@@ -84,6 +100,9 @@ print('Doba:', duration//3600, 'h', (duration%3600)//60, 'm', duration%60, 's')
gpx = gpxpy.gpx.GPX()
points: list[gpxpy.gpx.GPXTrackPoint] = []
if args.reverse:
tour.reverse()
start = tour.index(0)
for i in range(0, len(tour)):