Skip to content

Commit

Permalink
Add attributes to node/breaker graph (#911)
Browse files Browse the repository at this point in the history
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@rte-france.com>
  • Loading branch information
geofjamg authored Dec 11, 2024
1 parent 9f5c0be commit 2ac515b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pypowsybl/network/impl/node_breaker_topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ def create_graph(self) -> _nx.Graph:
Representation of the topology as a networkx graph.
"""
graph = _nx.Graph()
graph.add_nodes_from(self._nodes.index.tolist())
graph.add_edges_from(self._switchs[['node1', 'node2']].values.tolist())
for (index, row) in self.nodes.iterrows():
graph.add_node(index, connectable_id=row['connectable_id'], connectable_type=row['connectable_type'])
for (index, row) in self._switchs.iterrows():
graph.add_edge(row['node1'], row['node2'], id=index, name=row['name'], kind=row['kind'],
open=row['open'], retained=row['retained'])
graph.add_edges_from(self._internal_connections[['node1', 'node2']].values.tolist())
return graph
7 changes: 7 additions & 0 deletions tests/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,14 @@ def test_graph():
network_topology = n.get_node_breaker_topology('S4VL1')
graph = network_topology.create_graph()
assert 7 == len(graph.nodes)
assert [0, 1, 2, 3, 4, 5, 6] == list(graph.nodes)
assert {'connectable_id': 'S4VL1_BBS', 'connectable_type': 'BUSBAR_SECTION'} == graph.nodes[0]
assert [(0, 5), (0, 1), (0, 3), (1, 2), (3, 4), (5, 6)] == list(graph.edges)
assert {'id': 'S4VL1_BBS_LINES3S4_DISCONNECTOR',
'kind': 'DISCONNECTOR',
'name': 'S4VL1_BBS_LINES3S4_DISCONNECTOR',
'open': False,
'retained': False} == graph.edges[0, 5]


@unittest.skip("plot graph skipping")
Expand Down

0 comments on commit 2ac515b

Please sign in to comment.