style corrections, documentation, duplicate removal, flow improvement
This commit is contained in:
@@ -1,16 +1,20 @@
|
||||
from backend.src.example_optimizer import solve_optimization
|
||||
# from refiner import refine_optimization
|
||||
from landmarks_manager import LandmarkManager
|
||||
from structs.landmarks import Landmark
|
||||
from structs.landmarktype import LandmarkType
|
||||
from structs.preferences import Preferences
|
||||
import logging
|
||||
from fastapi import FastAPI, Query, Body
|
||||
|
||||
from structs.landmark import Landmark
|
||||
from structs.preferences import Preferences
|
||||
from structs.linked_landmarks import LinkedLandmarks
|
||||
from utils.landmarks_manager import LandmarkManager
|
||||
from utils.optimizer import Optimizer
|
||||
from utils.refiner import Refiner
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
app = FastAPI()
|
||||
manager = LandmarkManager()
|
||||
|
||||
# TODO: needs a global variable to store the landmarks accross function calls
|
||||
# linked_tour = []
|
||||
optimizer = Optimizer()
|
||||
refiner = Refiner(optimizer=optimizer)
|
||||
|
||||
|
||||
@app.post("/route/new")
|
||||
@@ -22,19 +26,23 @@ def main1(preferences: Preferences, start: tuple[float, float], end: tuple[float
|
||||
:param end: the coordinates of the finishing point as a tuple of floats (as url query parameters)
|
||||
:return: the uuid of the first landmark in the optimized route
|
||||
'''
|
||||
if preferences is None :
|
||||
if preferences is None:
|
||||
raise ValueError("Please provide preferences in the form of a 'Preference' BaseModel class.")
|
||||
if start is None:
|
||||
raise ValueError("Please provide the starting coordinates as a tuple of floats.")
|
||||
if end is None:
|
||||
end = start
|
||||
logger.info("No end coordinates provided. Using start=end.")
|
||||
|
||||
start_landmark = Landmark(name='start', type='start', location=(start[0], start[1]), osm_type='start', osm_id=0, attractiveness=0, must_do=True, n_tags = 0)
|
||||
end_landmark = Landmark(name='end', type='end', location=(end[0], end[1]), osm_type='end', osm_id=0, attractiveness=0, must_do=True, n_tags = 0)
|
||||
|
||||
start_landmark = Landmark(name='start', type=LandmarkType(landmark_type='start'), location=(start[0], start[1]), osm_type='start', osm_id=0, attractiveness=0, must_do=True, n_tags = 0)
|
||||
end_landmark = Landmark(name='end', type=LandmarkType(landmark_type='end'), location=(end[0], end[1]), osm_type='end', osm_id=0, attractiveness=0, must_do=True, n_tags = 0)
|
||||
|
||||
# Generate the landmarks from the start location
|
||||
landmarks, landmarks_short = LandmarkManager.get_landmark_lists(preferences=preferences, coordinates=start.location)
|
||||
print([l.name for l in landmarks_short])
|
||||
landmarks, landmarks_short = manager.generate_landmarks_list(
|
||||
center_coordinates = start,
|
||||
preferences = preferences
|
||||
)
|
||||
|
||||
# insert start and finish to the landmarks list
|
||||
landmarks_short.insert(0, start_landmark)
|
||||
landmarks_short.append(end_landmark)
|
||||
@@ -44,14 +52,13 @@ def main1(preferences: Preferences, start: tuple[float, float], end: tuple[float
|
||||
detour = 30 # minutes
|
||||
|
||||
# First stage optimization
|
||||
base_tour = solve_optimization(landmarks_short, max_walking_time*60, True)
|
||||
base_tour = optimizer.solve_optimization(max_walking_time*60, landmarks_short)
|
||||
|
||||
# Second stage optimization
|
||||
# refined_tour = refine_optimization(landmarks, base_tour, max_walking_time*60+detour, True)
|
||||
refined_tour = refiner.refine_optimization(landmarks, base_tour, max_walking_time*60, detour)
|
||||
|
||||
# linked_tour = ...
|
||||
# return linked_tour[0].uuid
|
||||
return base_tour[0].uuid
|
||||
linked_tour = LinkedLandmarks(refined_tour)
|
||||
return linked_tour[0].uuid
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user