fixed optimizer. works fine now
This commit is contained in:
@@ -1,13 +1,25 @@
|
||||
import pandas as pd
|
||||
from optimizer import solve_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
|
||||
from fastapi import FastAPI, Query, Body
|
||||
from fastapi.encoders import jsonable_encoder
|
||||
from typing import List
|
||||
|
||||
|
||||
# Helper function to create a .txt file with results
|
||||
def write_data(L: List[Landmark]):
|
||||
|
||||
data = pd.DataFrame()
|
||||
i = 0
|
||||
|
||||
for landmark in L :
|
||||
data[i] = jsonable_encoder(landmark)
|
||||
i += 1
|
||||
|
||||
data.to_json('landmarks.txt', indent = 2, force_ascii=False)
|
||||
|
||||
def test3(city_country: str) -> List[Landmark]:
|
||||
|
||||
|
||||
@@ -25,7 +37,9 @@ def test3(city_country: str) -> List[Landmark]:
|
||||
type=LandmarkType(landmark_type='shopping'),
|
||||
score = 5))
|
||||
|
||||
landmarks = generate_landmarks(city_country, preferences)
|
||||
coords = None
|
||||
|
||||
landmarks = generate_landmarks(preferences=preferences, city_country=city_country, coordinates=coords)
|
||||
|
||||
max_steps = 9
|
||||
|
||||
@@ -47,21 +61,33 @@ def test4(coordinates: tuple[float, float]) -> List[Landmark]:
|
||||
nature=Preference(
|
||||
name='nature',
|
||||
type=LandmarkType(landmark_type='nature'),
|
||||
score = 0),
|
||||
score = 5),
|
||||
shopping=Preference(
|
||||
name='shopping',
|
||||
type=LandmarkType(landmark_type='shopping'),
|
||||
score = 5))
|
||||
|
||||
landmarks = generate_landmarks(coordinates, preferences)
|
||||
city_country = None
|
||||
|
||||
max_steps = 90
|
||||
landmarks, landmarks_short = generate_landmarks(preferences=preferences, city_country=city_country, coordinates=coordinates)
|
||||
|
||||
visiting_order = solve_optimization(landmarks, max_steps, True)
|
||||
#write_data(landmarks)
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
test = landmarks_short
|
||||
test.append(finish)
|
||||
test.insert(0, start)
|
||||
|
||||
max_walking_time = 4 # hours
|
||||
|
||||
visiting_order = solve_optimization(test, max_walking_time*60, True)
|
||||
|
||||
print(len(visiting_order))
|
||||
|
||||
return len(visiting_order)
|
||||
|
||||
|
||||
test3(tuple((48.834378, 2.322113)))
|
||||
test4(tuple((48.834378, 2.322113)))
|
Reference in New Issue
Block a user