From 962a1fa271962b2ef18a787112631e648e1b4c31 Mon Sep 17 00:00:00 2001 From: "niehues.mark@gmail.com" <niehues.mark@gmail.com> Date: Wed, 29 Apr 2020 17:09:00 +0200 Subject: [PATCH] insert complete path --- evrouting/gasstation/routing.py | 9 ++++++--- tests/osm/test_gasstation_osm.py | 4 ++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/evrouting/gasstation/routing.py b/evrouting/gasstation/routing.py index ff5d458..fbea26d 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 3235d7f..2973e78 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:] -- GitLab