better time management for optimizer
This commit is contained in:
parent
a1fcc8d23b
commit
003b8d0f9c
@ -7,5 +7,5 @@ tag_exponent: 1.15
|
|||||||
image_bonus: 10
|
image_bonus: 10
|
||||||
viewpoint_bonus: 15
|
viewpoint_bonus: 15
|
||||||
wikipedia_bonus: 6
|
wikipedia_bonus: 6
|
||||||
N_important: 50
|
N_important: 40
|
||||||
pay_bonus: -1
|
pay_bonus: -1
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
detour_factor: 1.4
|
detour_factor: 1.4
|
||||||
detour_corridor_width: 200
|
detour_corridor_width: 300
|
||||||
average_walking_speed: 4.8
|
average_walking_speed: 4.8
|
||||||
max_landmarks: 10
|
max_landmarks: 10
|
||||||
max_landmarks_refiner: 20
|
max_landmarks_refiner: 20
|
||||||
|
overshoot: 1.3
|
||||||
|
@ -33,6 +33,7 @@ class Landmark(BaseModel) :
|
|||||||
return self.uuid.int
|
return self.uuid.int
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
time_to_next_str = f", time_to_next={self.time_to_reach_next}" if self.time_to_reach_next else ""
|
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'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}'
|
||||||
|
|
||||||
|
@ -24,8 +24,8 @@ def test(start_coords: tuple[float, float], finish_coords: tuple[float, float] =
|
|||||||
nature=Preference(type='nature', score = 5),
|
nature=Preference(type='nature', score = 5),
|
||||||
shopping=Preference(type='shopping', score = 5),
|
shopping=Preference(type='shopping', score = 5),
|
||||||
|
|
||||||
max_time_minute=1000,
|
max_time_minute=300,
|
||||||
detour_tolerance_minute=0
|
detour_tolerance_minute=15
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create start and finish
|
# 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)
|
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)
|
linked_tour = LinkedLandmarks(refined_tour)
|
||||||
|
total_time = 0
|
||||||
logger.info("Optimized route : ")
|
logger.info("Optimized route : ")
|
||||||
for l in linked_tour :
|
for l in linked_tour :
|
||||||
logger.info(f"{l}")
|
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:
|
# with open('linked_tour.yaml', 'w') as f:
|
||||||
# yaml.dump(linked_tour.asdict(), 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
|
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((48.8375946, 2.2949904))) # Point random
|
||||||
# test(tuple((47.377859, 8.540585))) # Zurich HB
|
# 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.5848435, 7.7332974))) # Strasbourg Gare
|
||||||
# test(tuple((48.2067858, 16.3692340))) # Vienne
|
# test(tuple((48.2067858, 16.3692340))) # Vienne
|
||||||
|
@ -343,9 +343,15 @@ class LandmarkManager:
|
|||||||
score = int(score*self.church_coeff)
|
score = int(score*self.church_coeff)
|
||||||
duration = 60
|
duration = 60
|
||||||
|
|
||||||
else :
|
elif "fountain" in elem.tags().values() :
|
||||||
|
duration = 5
|
||||||
|
|
||||||
|
elif "park" in elem.tags().values() :
|
||||||
duration = 30
|
duration = 30
|
||||||
|
|
||||||
|
else :
|
||||||
|
duration = 15
|
||||||
|
|
||||||
# Generate the landmark and append it to the list
|
# Generate the landmark and append it to the list
|
||||||
landmark = Landmark(
|
landmark = Landmark(
|
||||||
name=name,
|
name=name,
|
||||||
|
@ -21,6 +21,7 @@ class Optimizer:
|
|||||||
detour_factor: float # detour factor of straight line vs real distance in cities
|
detour_factor: float # detour factor of straight line vs real distance in cities
|
||||||
average_walking_speed: float # average walking speed of adult
|
average_walking_speed: float # average walking speed of adult
|
||||||
max_landmarks: int # max number of landmarks to visit
|
max_landmarks: int # max number of landmarks to visit
|
||||||
|
overshoot: float # experimentally determined overshoot possibility to return long enough tours
|
||||||
|
|
||||||
|
|
||||||
def __init__(self) :
|
def __init__(self) :
|
||||||
@ -31,6 +32,7 @@ class Optimizer:
|
|||||||
self.detour_factor = parameters['detour_factor']
|
self.detour_factor = parameters['detour_factor']
|
||||||
self.average_walking_speed = parameters['average_walking_speed']
|
self.average_walking_speed = parameters['average_walking_speed']
|
||||||
self.max_landmarks = parameters['max_landmarks']
|
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.
|
Initialize the objective function coefficients and inequality constraints for the optimization problem.
|
||||||
|
|
||||||
@ -176,7 +178,7 @@ class Optimizer:
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
landmarks (list[Landmark]): List of landmarks.
|
landmarks (list[Landmark]): List of landmarks.
|
||||||
max_steps (int): Maximum number of steps allowed.
|
max_time (int): Maximum time allowed for tour.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Tuple[list[float], list[float], list[int]]: Objective function coefficients, inequality constraint coefficients, and the right-hand side of the inequality constraint.
|
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
|
A_ub += dist_table
|
||||||
c = c*len(landmarks)
|
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):
|
def respect_number(self, L, max_landmarks: int):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user