-
Notifications
You must be signed in to change notification settings - Fork 51
Refactor graph traversal methods to use new getConnectedComponents API
#3753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…API. Signed-off-by: Leclerc Clement <[email protected]>
…API. Signed-off-by: Leclerc Clement <[email protected]>
… 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) { |
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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
| Vertex<V> destVertex = vertices.get(v2); | ||
| if (destVertex != null) { |
There was a problem hiding this comment.
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
getConnectedComponents …getConnectedComponents API
|
|
||
| collector.addVertex(component, v, vertex.getObject()); | ||
|
|
||
| traverse(v, TraversalType.BREADTH_FIRST, (v1, e, v2) -> { |
There was a problem hiding this comment.
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]>
…Predicate` Signed-off-by: Leclerc Clement <[email protected]>
…` API, and enhance vertex object handling in graph traversal implementations. Signed-off-by: Leclerc Clement <[email protected]>
|



Please check if the PR fulfills these requirements
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?
If yes, please check if the following requirements are fulfilled
What changes might users need to make in their application due to this PR? (migration steps)
Other information: