diff --git a/evrouting/gasstation/routing.py b/evrouting/gasstation/routing.py index ff5d4588fa552dc504fb7777e0804204ff6eb88a..fbea26dd06ae80eaa0e0bde8a2a5739759a1ddf1 100644 --- a/evrouting/gasstation/routing.py +++ b/evrouting/gasstation/routing.py @@ -160,7 +160,7 @@ def state_graph(G: nx.Graph, capacity: SoC, f: AccessFunctions = AccessFunctions def compose_result(graph_core: nx.Graph, extended_graph: nx.DiGraph, - path: List[State]) -> Result: + path: List[State], f: AccessFunctions = AccessFunctions()) -> Result: trip_time: Time = 0 charge_path = [] u: Node @@ -172,13 +172,15 @@ def compose_result(graph_core: nx.Graph, extended_graph: nx.DiGraph, v, g_v = path[i + 1] t: Time = extended_graph.edges[(u, g_u), (v, g_v)]['weight'] trip_time += t - charge_time_u: Time = t - nx.shortest_path_length( + path_in_between = nx.shortest_path( graph_core, u, v, weight=DISTANCE_KEY ) + charge_time_u: Time = t - f.path_distance(graph_core, path_in_between) charge_path.append((u, charge_time_u)) + charge_path += [(n, 0) for n in path_in_between[1:-1]] charge_path.append((path[-1][0], 0)) # Final Node @@ -253,5 +255,6 @@ def shortest_path(G: nx.Graph, return compose_result( graph_core=G, extended_graph=extended_graph, - path=path + path=path, + f=f ) diff --git a/tests/osm/test_gasstation_osm.py b/tests/osm/test_gasstation_osm.py index 3235d7fc9ecd3a57761e7d0392ee732d1854d218..2973e78c1ba0e53e67a01ba717ee8d1f499694f2 100644 --- a/tests/osm/test_gasstation_osm.py +++ b/tests/osm/test_gasstation_osm.py @@ -77,3 +77,7 @@ def test_charge_shortest_route_stop(map_graph): path_cost = s_to_c + c_to_t assert int(path_cost) == int(used_energy) + + path_s_to_c = nx.shortest_path(map_graph, _s, charge_node, weight=DISTANCE_KEY) + path_c_to_t = nx.shortest_path(map_graph, charge_node, _t, weight=DISTANCE_KEY) + assert [n for n, t in result.charge_path] == path_s_to_c + path_c_to_t[1:]