Skip to content
Snippets Groups Projects
Commit 24cc1eee authored by markn92's avatar markn92
Browse files

premature optimization

parent 6ca9aa6c
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
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