licit-lab / MnMS

Agent-based Multimodal Urban Moblity Simulator resulting from the ERC MAGnUM project
GNU Lesser General Public License v3.0
9 stars 4 forks source link

When at least 2 paths are requested, the n shortest paths algorithm returns no path even if there is one #81

Closed becarie closed 2 years ago

becarie commented 2 years ago

In this case, the algorithm should return the single path To reproduce:

from mnms.graph.io import load_graph

lyon_file_name = "network_lyon6.json"
mmgraph = load_graph(lyon_file_name)
from mnms.graph.shortest_path import compute_shortest_path
from mnms.demand.user import User
from mnms.tools.time import Time

user = User('U0', 'E_762997770_T_549690255_toRef', 'S_762997770_T_549690255_FRef', Time('07:00:00'), available_mobility_services=['PersonalCar'])
path = compute_shortest_path(mmgraph, user)
print(f"Path cost: {path.path_cost}, path:{path.nodes}")
from mnms.graph.shortest_path import compute_n_best_shortest_path

paths = compute_n_best_shortest_path(mmgraph, user, 2, algorithm='dijkstra')
print(f"Paths: {paths}")

Data: https://www.dropbox.com/s/n05a7hyt3mzxx9u/network_lyon6.json?dl=0

floriangc commented 2 years ago

Fix in https://github.com/licit-lab/MnMS/commit/3a5b3f926934d2d8738e3f544a4465ba01344d20

becarie commented 2 years ago

In the above example, the list returned by the compute_n_best_shortest_path function contains 2 elements if there is a unique path: the first is the path but there is another element which only contains the cost of the shorter path

floriangc commented 2 years ago

The second item is the penalized cost of the path, not the actual cost