Skip to content
Snippets Groups Projects
Commit 962a1fa2 authored by markn92's avatar markn92
Browse files

insert complete path

parent f2015074
No related branches found
No related tags found
No related merge requests found
...@@ -160,7 +160,7 @@ def state_graph(G: nx.Graph, capacity: SoC, f: AccessFunctions = AccessFunctions ...@@ -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, 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 trip_time: Time = 0
charge_path = [] charge_path = []
u: Node u: Node
...@@ -172,13 +172,15 @@ def compose_result(graph_core: nx.Graph, extended_graph: nx.DiGraph, ...@@ -172,13 +172,15 @@ def compose_result(graph_core: nx.Graph, extended_graph: nx.DiGraph,
v, g_v = path[i + 1] v, g_v = path[i + 1]
t: Time = extended_graph.edges[(u, g_u), (v, g_v)]['weight'] t: Time = extended_graph.edges[(u, g_u), (v, g_v)]['weight']
trip_time += t trip_time += t
charge_time_u: Time = t - nx.shortest_path_length( path_in_between = nx.shortest_path(
graph_core, graph_core,
u, u,
v, v,
weight=DISTANCE_KEY 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.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 charge_path.append((path[-1][0], 0)) # Final Node
...@@ -253,5 +255,6 @@ def shortest_path(G: nx.Graph, ...@@ -253,5 +255,6 @@ def shortest_path(G: nx.Graph,
return compose_result( return compose_result(
graph_core=G, graph_core=G,
extended_graph=extended_graph, extended_graph=extended_graph,
path=path path=path,
f=f
) )
...@@ -77,3 +77,7 @@ def test_charge_shortest_route_stop(map_graph): ...@@ -77,3 +77,7 @@ def test_charge_shortest_route_stop(map_graph):
path_cost = s_to_c + c_to_t path_cost = s_to_c + c_to_t
assert int(path_cost) == int(used_energy) 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:]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment