Refactor graph traversal methods to use new getConnectedComponents API#3753
Refactor graph traversal methods to use new getConnectedComponents API#3753clementleclercRTE wants to merge 19 commits intomainfrom
getConnectedComponents API#3753Conversation
…API. Signed-off-by: Leclerc Clement <clement.leclerc@rte-france.com>
…API. Signed-off-by: Leclerc Clement <clement.leclerc@rte-france.com>
… graph-connected-components # Conflicts: # iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/NodeBreakerTopologyModel.java
math/src/main/java/com/powsybl/math/graph/UndirectedGraphImpl.java
Outdated
Show resolved
Hide resolved
math/src/main/java/com/powsybl/math/graph/UndirectedGraphImpl.java
Outdated
Show resolved
Hide resolved
getConnectedComponents …getConnectedComponents API
… traversal components. Signed-off-by: Leclerc Clement <clement.leclerc@rte-france.com>
…Predicate` Signed-off-by: Leclerc Clement <clement.leclerc@rte-france.com>
…` API, and enhance vertex object handling in graph traversal implementations. Signed-off-by: Leclerc Clement <clement.leclerc@rte-france.com>
Signed-off-by: Leclerc Clement <clement.leclerc@rte-france.com>
Signed-off-by: Leclerc Clement <clement.leclerc@rte-france.com>
|
Signed-off-by: Leclerc Clement <clement.leclerc@rte-france.com>
… graph-connected-components
| } else { | ||
| busSet.add(graph.getVertexObject(v2)); | ||
| return TraverseResult.CONTINUE; | ||
| graph.getConnectedComponents( |
There was a problem hiding this comment.
introduce a variable which is the result to improve readability
There was a problem hiding this comment.
Done. I used a simple for loop instead of streams
| @Override | ||
| public Iterable<V> getVerticesObj() { | ||
| return FluentIterable.from(vertices) | ||
| .filter(Predicates.notNull()) |
There was a problem hiding this comment.
Could you remove the formatting changes?
| List<C> components = new ArrayList<>(vertices.size()); | ||
|
|
||
| for (int v = 0; v < vertices.size(); v++) { | ||
| Vertex<V> vertex = vertices.get(v); |
There was a problem hiding this comment.
why do you check that vertex != null?
There was a problem hiding this comment.
Indeed, I've removed that
| @Override | ||
| public void addVertex(Set<ConfiguredBus> component, int vertexIndex) { | ||
| ConfiguredBus bus = graph.getVertexObject(vertexIndex); | ||
| if (bus != null) { |
There was a problem hiding this comment.
getVertexObject() cannot return null in bus/breaker topology
There was a problem hiding this comment.
Indeed, I've removed that check
| } | ||
| return TraverseResult.CONTINUE; | ||
| }, | ||
| new UndirectedGraph.ConnectedComponentCollector<Set<ConfiguredBus>>() { |
There was a problem hiding this comment.
There's no need to have a set anymore, a list would be enough
There was a problem hiding this comment.
Switched to a List and updated relevant private function signatures accordingly.
|
|
||
| final CalculatedBusTopology calculatedBusTopology | ||
| = new CalculatedBusTopology(); | ||
| = new CalculatedBusTopology(); |
| } | ||
| return TraverseResult.CONTINUE; | ||
| }).forEach(nodes -> { | ||
| CopyOnWriteArrayList<NodeTerminal> terminals = new CopyOnWriteArrayList<>(); |
There was a problem hiding this comment.
I'm wondering if we really need the CopyOnWriteArrayList for buses
| terminals.add(terminal); | ||
| } | ||
| } | ||
| if (getBusChecker().isValid(graph, nodes, terminals)) { |
There was a problem hiding this comment.
the terminals argument is never used. Should it be removed or rather used?
There was a problem hiding this comment.
Removed it and moved the logic directly into the addBus method
math/src/main/java/com/powsybl/math/graph/UndirectedGraphImpl.java
Outdated
Show resolved
Hide resolved
…comments Signed-off-by: Leclerc Clement <clement.leclerc@rte-france.com>
…comments Signed-off-by: Leclerc Clement <clement.leclerc@rte-france.com>
… graph-connected-components
Signed-off-by: Leclerc Clement <clement.leclerc@rte-france.com>
|



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: