From 3ef6d519d715efb2aec863f9c09ee2ec605c711b Mon Sep 17 00:00:00 2001 From: Bobby Xiong <36541459+bobbyxng@users.noreply.github.com> Date: Wed, 14 Aug 2024 10:24:38 +0200 Subject: [PATCH] Fix simplify_network.py to handle more complex topologies (#1211) * Fixed simplify_network.py to handle more complex topologies, i.e. if two links are connected to nearby AC buses separated by an AC line. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- scripts/simplify_network.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/scripts/simplify_network.py b/scripts/simplify_network.py index 558e4cf2..2b759a73 100644 --- a/scripts/simplify_network.py +++ b/scripts/simplify_network.py @@ -298,13 +298,24 @@ def simplify_links( _, labels = connected_components(adjacency_matrix, directed=False) labels = pd.Series(labels, n.buses.index) - G = n.graph() + # Only span graph over the DC link components + G = n.graph(branch_components=["Link"]) def split_links(nodes): nodes = frozenset(nodes) seen = set() - supernodes = {m for m in nodes if len(G.adj[m]) > 2 or (set(G.adj[m]) - nodes)} + + # Supernodes are endpoints of links, identified by having lass then two neighbours or being an AC Bus + # An example for the latter is if two different links are connected to the same AC bus. + supernodes = { + m + for m in nodes + if ( + (len(G.adj[m]) < 2 or (set(G.adj[m]) - nodes)) + or (n.buses.loc[m, "carrier"] == "AC") + ) + } for u in supernodes: for m, ls in G.adj[u].items():