From 24cc1eee557991755358362dcb89a5bdd9f74d54 Mon Sep 17 00:00:00 2001 From: "niehues.mark@gmail.com" <niehues.mark@gmail.com> Date: Tue, 31 Mar 2020 20:24:29 +0200 Subject: [PATCH] premature optimization --- evrouting/gasstation/routing.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/evrouting/gasstation/routing.py b/evrouting/gasstation/routing.py index c207050..7171caa 100644 --- a/evrouting/gasstation/routing.py +++ b/evrouting/gasstation/routing.py @@ -101,10 +101,12 @@ def contract_graph(G: nx.Graph, charging_stations: Set[Node], capacity: SoC, """ H: nx.Graph = nx.Graph() - for cs in list(charging_stations): + all_cs = list(charging_stations) + for i in range(len(all_cs) - 1): + cs = all_cs[i] H.add_node(cs, **G.nodes[cs]) # Iterate unvisited charging stations - for n_cs in [n for n in charging_stations if (n, cs) not in H.edges and n != cs]: + for n_cs in all_cs[i + 1:]: min_path: List[Node] = dist(G, cs, n_cs) w_cs_n: SoC = fold_path(G, min_path, weight=CONSUMPTION_KEY) if w_cs_n <= capacity: @@ -115,6 +117,8 @@ def contract_graph(G: nx.Graph, charging_stations: Set[Node], capacity: SoC, DISTANCE_KEY: fold_path(G, min_path, weight=DISTANCE_KEY) } ) + H.add_node(all_cs[-1], **G.nodes[all_cs[-1]]) + return H -- GitLab