Обновить route.py
This commit is contained in:
11
route.py
11
route.py
@@ -4,13 +4,13 @@ import requests
|
||||
from typing import List, Tuple, Dict, Optional, Set
|
||||
import random
|
||||
class Point:
|
||||
def __init__(self, coord: List[float], tag: str, visit_time: int):
|
||||
def __init__(self, coord: List[float], tag: str, visit_time: int, list_id=0):
|
||||
self.coord = coord
|
||||
self.tag = tag
|
||||
self.visit_time = visit_time
|
||||
self.matrix_index = None # Индекс точки в матрице расстояний
|
||||
self.estimated_time = None # Оценочное время (перемещение + посещение)
|
||||
|
||||
self.list_id = list_id
|
||||
def haversine(coord1: List[float], coord2: List[float]) -> float:
|
||||
"""Calculate the great-circle distance between two points in kilometers."""
|
||||
lat1, lon1 = coord1
|
||||
@@ -248,8 +248,8 @@ def generate_routes_with_repeats(grouped_points: Dict[int, List[Point]],
|
||||
|
||||
def form_point_list(data):
|
||||
point_list =[]
|
||||
for entry in data:
|
||||
point = Point(list(map(float,entry['coordinate'].split(', '))),entry['type'],entry['time_to_visit'])
|
||||
for list_id,entry in enumerate(data):
|
||||
point = Point(list(map(float,entry['coordinate'].split(', '))),entry['type'],entry['time_to_visit'],list_id)
|
||||
point_list.append(point)
|
||||
return point_list
|
||||
|
||||
@@ -456,6 +456,7 @@ def build_route(data, mapping,start_coord,total_time,n_nodes,strategy='best'):
|
||||
print("All coordinates in the route are unique!")
|
||||
else:
|
||||
print("ERROR: Duplicate coordinates found in the route!")
|
||||
return route_coords
|
||||
places = [data[point.list_id] for point in optimal_route]
|
||||
return route_coords,places
|
||||
#if __name__ == "__main__":
|
||||
# build_route()
|
||||
Reference in New Issue
Block a user