91 lines
3.7 KiB
Python
91 lines
3.7 KiB
Python
from optimizer import solve_optimization
|
|
from refiner import refine_optimization
|
|
from landmarks_manager import generate_landmarks
|
|
from structs.landmarks import Landmark
|
|
from structs.landmarktype import LandmarkType
|
|
from structs.preferences import Preferences, Preference
|
|
from fastapi import FastAPI, Query, Body
|
|
from typing import List
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
# TODO: needs a global variable to store the landmarks accross function calls
|
|
# linked_tour = []
|
|
|
|
|
|
# Assuming frontend is calling like this :
|
|
#"http://127.0.0.1:8000/process?param1={param1}¶m2={param2}"
|
|
@app.post("/optimizer_coords/{start_lat}/{start_lon}/{finish_lat}/{finish_lon}")
|
|
def main1(start_lat: float, start_lon: float, preferences: Preferences = Body(...), finish_lat: float = None, finish_lon: float = None) -> List[Landmark]:
|
|
|
|
if preferences is None :
|
|
raise ValueError("Please provide preferences in the form of a 'Preference' BaseModel class.")
|
|
if bool(start_lat) ^ bool(start_lon) :
|
|
raise ValueError("Please provide both latitude and longitude for the starting point")
|
|
if bool(finish_lat) ^ bool(finish_lon) :
|
|
raise ValueError("Please provide both latitude and longitude for the finish point")
|
|
|
|
start = Landmark(name='start', type=LandmarkType(landmark_type='start'), location=(start_lat, start_lon), osm_type='start', osm_id=0, attractiveness=0, must_do=True, n_tags = 0)
|
|
|
|
if bool(finish_lat) and bool(finish_lon) :
|
|
finish = Landmark(name='finish', type=LandmarkType(landmark_type='finish'), location=(finish_lat, finish_lon), osm_type='finish', osm_id=0, attractiveness=0, must_do=True, n_tags = 0)
|
|
else :
|
|
finish = Landmark(name='finish', type=LandmarkType(landmark_type='finish'), location=(start_lat, start_lon), osm_type='finish', osm_id=0, attractiveness=0, must_do=True, n_tags = 0)
|
|
|
|
|
|
start = Landmark(name='start', type=LandmarkType(landmark_type='start'), location=(48.8375946, 2.2949904), osm_type='start', osm_id=0, attractiveness=0, must_do=True, n_tags = 0)
|
|
finish = Landmark(name='finish', type=LandmarkType(landmark_type='finish'), location=(48.8375946, 2.2949904), osm_type='finish', osm_id=0, attractiveness=0, must_do=True, n_tags = 0)
|
|
|
|
# Generate the landmarks from the start location
|
|
landmarks, landmarks_short = generate_landmarks(preferences=preferences, coordinates=start.location)
|
|
|
|
# insert start and finish to the landmarks list
|
|
landmarks_short.insert(0, start)
|
|
landmarks_short.append(finish)
|
|
|
|
|
|
# TODO use these parameters in another way
|
|
max_walking_time = 4 # hours
|
|
detour = 30 # minutes
|
|
|
|
# First stage optimization
|
|
base_tour = solve_optimization(landmarks_short, max_walking_time*60, True)
|
|
|
|
# Second stage optimization
|
|
refined_tour = refine_optimization(landmarks, base_tour, max_walking_time*60+detour, True)
|
|
|
|
|
|
# TODO: should look something like this
|
|
# # set time to reach and transform into fully functional linked list
|
|
# linked_tour += link(refined_tour)
|
|
# return {
|
|
# 'city_name': 'Paris',
|
|
# 'n_stops': len(linked_tour),
|
|
# 'first_landmark_uuid': linked_tour[0].uuid,
|
|
# }
|
|
|
|
return refined_tour
|
|
|
|
|
|
|
|
|
|
# input city, country in the form of 'Paris, France'
|
|
@app.post("/test2/{city_country}")
|
|
def test2(city_country: str, preferences: Preferences = Body(...)) -> List[Landmark]:
|
|
|
|
landmarks = generate_landmarks(city_country, preferences)
|
|
|
|
max_steps = 9000000
|
|
|
|
visiting_order = solve_optimization(landmarks, max_steps, True)
|
|
|
|
|
|
|
|
@app.get("/landmark/{landmark_uuid}")
|
|
def get_landmark(landmark_uuid: str) -> Landmark:
|
|
#cherche dans linked_tour et retourne le landmark correspondant
|
|
pass
|
|
|
|
|