Upgraded refiner
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from optimizer import solve_optimization
|
||||
from refiner import refine_optimization
|
||||
from landmarks_manager import generate_landmarks
|
||||
from structs.landmarks import LandmarkTest
|
||||
from structs.landmarks import Landmark
|
||||
from structs.landmarktype import LandmarkType
|
||||
from structs.preferences import Preferences, Preference
|
||||
@@ -12,35 +12,45 @@ app = FastAPI()
|
||||
|
||||
# Assuming frontend is calling like this :
|
||||
#"http://127.0.0.1:8000/process?param1={param1}¶m2={param2}"
|
||||
@app.post("/optimizer_coords/{latitude}/{longitude}/{city_country}")
|
||||
def main1(preferences: Preferences = Body(...), latitude: float = None, longitude: float = None, city_country: str = None) -> List[Landmark]:
|
||||
@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.")
|
||||
elif latitude is None and longitude is None and city_country is None :
|
||||
raise ValueError("Please provide GPS coordinates or a 'city_country' string.")
|
||||
elif latitude is not None and longitude is not None and city_country is not None :
|
||||
raise ValueError("Please provide EITHER GPS coordinates or a 'city_country' string.")
|
||||
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")
|
||||
|
||||
|
||||
# From frontend get longitude, latitude and prefence list
|
||||
if city_country is None :
|
||||
coordinates = tuple((latitude, longitude))
|
||||
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)
|
||||
|
||||
|
||||
[], landmarks_short = generate_landmarks(preferences=preferences, city_country=city_country, coordinates=coordinates)
|
||||
|
||||
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)
|
||||
|
||||
max_walking_time = 4 # hours
|
||||
# TODO use these parameters in another way
|
||||
max_walking_time = 4 # hours
|
||||
detour = 30 # minutes
|
||||
|
||||
visiting_list = solve_optimization(landmarks_short, max_walking_time*60, True)
|
||||
|
||||
return visiting_list
|
||||
# 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)
|
||||
|
||||
return refined_tour
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user