From 13b097cee3a1f899b88406c2c2eab3fd5914d308 Mon Sep 17 00:00:00 2001 From: prokopparuzek Date: Thu, 5 Sep 2024 19:41:15 +0200 Subject: [PATCH] Can use distance as metric --- findAllRoutes.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/findAllRoutes.py b/findAllRoutes.py index 169618b..3ca36bf 100755 --- a/findAllRoutes.py +++ b/findAllRoutes.py @@ -1,15 +1,15 @@ #!/usr/bin/python3 # find all routes between all pointes in positions.csv # max 100 points -# uses time as metrice +# default by type, param -l use length -import json import requests import pickle from os.path import isfile import fast_tsp import gpxpy import gpxpy.gpx +import sys class Person: name: str @@ -27,6 +27,13 @@ index: int = 0 persons: list[Person] = [] key: str matrix: list[list[int]] = [] +byWhat: str + +if len(sys.argv) == 2 and sys.argv[1] == "-l": + byWhat = 'length' +else: + byWhat = 'duration' + with open("key.api", "r") as f: key = f.readline() @@ -54,7 +61,7 @@ if not isfile('data.pkl'): mat = r.json() matrix.append([]) for res in mat['matrix'][0]: - matrix[p.index].append(res['duration']) + matrix[p.index].append(res[byWhat]) # Serialize the object to a binary format with open('data.pkl', 'wb') as file: pickle.dump(matrix, file)