Skip to content

Conversation

@clementleclercRTE
Copy link
Contributor

@clementleclercRTE clementleclercRTE commented Feb 3, 2026

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • A PR or issue has been opened in all impacted repositories (if any)

Does this PR already have an issue describing the problem?

What kind of change does this PR introduce?

Refactoring

What is the current behavior?

Currently, BusBreakerTopologyModel, NodeBreakerTopologyModel, and DcTopologyModel all contain duplicated logic to traverse the graph and identify connected components (bus construction).

What is the new behavior (if this is a feature change)?

Introduced getConnectedComponents method and ConnectedComponentCollector interface in UndirectedGraph

Does this PR introduce a breaking change or deprecate an API?

  • Yes
  • No

If yes, please check if the following requirements are fulfilled

  • The Breaking Change or Deprecated label has been added
  • The migration steps are described in the following section

What changes might users need to make in their application due to this PR? (migration steps)

Other information:

… graph-connected-components

# Conflicts:
#	iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/NodeBreakerTopologyModel.java

void addVertex(C component, int vertexIndex, V vertexObject);

default boolean isComponentValid(C component) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method does not make much sense in the graph world. So keep it to iidm side, that is,

  • always add the connected component in the graph world,
  • and in iidm world get all the connected components and then dismiss the ones which are not valid for iidm.


traverse(v, TraversalType.BREADTH_FIRST, (v1, e, v2) -> {
E edgeObject = edges.get(e).getObject();
if (edgeObject == null || isTraversable.test(edgeObject)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we might want to stop even if edgeObject == null. So we should reconsider the traverse signature. We probably need to replace the Predicate<E> isTraversable with a Traverser

Comment on lines 601 to 602
Vertex<V> destVertex = vertices.get(v2);
if (destVertex != null) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just call directly the collector with the integer, no need to fetch the vertex object

@rolnico rolnico changed the title Refactor graph traversal methods to use new getConnectedComponents Refactor graph traversal methods to use new getConnectedComponents API Feb 3, 2026

collector.addVertex(component, v, vertex.getObject());

traverse(v, TraversalType.BREADTH_FIRST, (v1, e, v2) -> {
Copy link
Collaborator

@flo-dup flo-dup Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • this traverse method of the UndirectedGraph interface should be deprecated
  • this traverse method in UndirectedGraphImpl should be private and a new parameter boolean[] encounteredEdges added

… traversal components.

Signed-off-by: Leclerc Clement <[email protected]>
…` API, and enhance vertex object handling in graph traversal implementations.

Signed-off-by: Leclerc Clement <[email protected]>
@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 4, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants