better time management for optimizer

This commit is contained in:
Kilian PC 2024-08-12 18:52:01 +02:00
parent a1fcc8d23b
commit 003b8d0f9c
6 changed files with 31 additions and 16 deletions

View File

@ -7,5 +7,5 @@ tag_exponent: 1.15
image_bonus: 10
viewpoint_bonus: 15
wikipedia_bonus: 6
N_important: 50
N_important: 40
pay_bonus: -1

View File

@ -1,5 +1,6 @@
detour_factor: 1.4
detour_corridor_width: 200
detour_corridor_width: 300
average_walking_speed: 4.8
max_landmarks: 10
max_landmarks_refiner: 20
overshoot: 1.3

View File

@ -33,6 +33,7 @@ class Landmark(BaseModel) :
return self.uuid.int
def __str__(self) -> str:
time_to_next_str = f", time_to_next={self.time_to_reach_next}" if self.time_to_reach_next else ""
return f'Landmark({self.type}): [{self.name} @{self.location}, score={self.attractiveness}{time_to_next_str}]'
time_to_next_str = f"time_to_next={self.time_to_reach_next}" if self.time_to_reach_next else ""
# return f'Landmark({self.type}): [{self.name} @{self.location}, score={self.attractiveness}{time_to_next_str}]'
return f'({self.type[:4]}), score={self.attractiveness}\tmain:{not self.is_secondary}\tduration={self.duration}\t{time_to_next_str}\t{self.name}'

View File

@ -24,8 +24,8 @@ def test(start_coords: tuple[float, float], finish_coords: tuple[float, float] =
nature=Preference(type='nature', score = 5),
shopping=Preference(type='shopping', score = 5),
max_time_minute=1000,
detour_tolerance_minute=0
max_time_minute=300,
detour_tolerance_minute=15
)
# Create start and finish
@ -60,9 +60,14 @@ def test(start_coords: tuple[float, float], finish_coords: tuple[float, float] =
refined_tour = refiner.refine_optimization(all_landmarks=landmarks, base_tour=base_tour, max_time = preferences.max_time_minute, detour = preferences.detour_tolerance_minute)
linked_tour = LinkedLandmarks(refined_tour)
total_time = 0
logger.info("Optimized route : ")
for l in linked_tour :
logger.info(f"{l}")
total_time += l.duration
total_time += l.time_to_reach_next
logger.info(f"Total time: {total_time}")
# with open('linked_tour.yaml', 'w') as f:
# yaml.dump(linked_tour.asdict(), f)
@ -70,9 +75,9 @@ def test(start_coords: tuple[float, float], finish_coords: tuple[float, float] =
return linked_tour
test(tuple((48.8344400, 2.3220540))) # Café Chez César
# test(tuple((48.8344400, 2.3220540))) # Café Chez César
# test(tuple((48.8375946, 2.2949904))) # Point random
# test(tuple((47.377859, 8.540585))) # Zurich HB
# test(tuple((45.7576485, 4.8330241))) # Lyon Bellecour
test(tuple((45.7576485, 4.8330241))) # Lyon Bellecour
# test(tuple((48.5848435, 7.7332974))) # Strasbourg Gare
# test(tuple((48.2067858, 16.3692340))) # Vienne

View File

@ -343,8 +343,14 @@ class LandmarkManager:
score = int(score*self.church_coeff)
duration = 60
else :
elif "fountain" in elem.tags().values() :
duration = 5
elif "park" in elem.tags().values() :
duration = 30
else :
duration = 15
# Generate the landmark and append it to the list
landmark = Landmark(

View File

@ -17,10 +17,11 @@ class Optimizer:
logger = logging.getLogger(__name__)
detour: int = None # accepted max detour time (in minutes)
detour_factor: float # detour factor of straight line vs real distance in cities
average_walking_speed: float # average walking speed of adult
max_landmarks: int # max number of landmarks to visit
detour: int = None # accepted max detour time (in minutes)
detour_factor: float # detour factor of straight line vs real distance in cities
average_walking_speed: float # average walking speed of adult
max_landmarks: int # max number of landmarks to visit
overshoot: float # experimentally determined overshoot possibility to return long enough tours
def __init__(self) :
@ -31,6 +32,7 @@ class Optimizer:
self.detour_factor = parameters['detour_factor']
self.average_walking_speed = parameters['average_walking_speed']
self.max_landmarks = parameters['max_landmarks']
self.overshoot = parameters['overshoot']
@ -167,7 +169,7 @@ class Optimizer:
def init_ub_dist(self, landmarks: list[Landmark], max_steps: int):
def init_ub_dist(self, landmarks: list[Landmark], max_time: int):
"""
Initialize the objective function coefficients and inequality constraints for the optimization problem.
@ -176,7 +178,7 @@ class Optimizer:
Args:
landmarks (list[Landmark]): List of landmarks.
max_steps (int): Maximum number of steps allowed.
max_time (int): Maximum time allowed for tour.
Returns:
Tuple[list[float], list[float], list[int]]: Objective function coefficients, inequality constraint coefficients, and the right-hand side of the inequality constraint.
@ -200,7 +202,7 @@ class Optimizer:
A_ub += dist_table
c = c*len(landmarks)
return c, A_ub, [max_steps]
return c, A_ub, [max_time*self.overshoot]
def respect_number(self, L, max_landmarks: int):