-
Notifications
You must be signed in to change notification settings - Fork 56
Refactor graph traversal methods to use new computeTraversalPartitions 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
Open
clementleclercRTE
wants to merge
28
commits into
main
Choose a base branch
from
graph-connected-components
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 13 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
988efdd
Refactor graph traversal methods to use new `getConnectedComponents` …
clementleclercRTE 30cc260
Refactor graph traversal methods to use new `getConnectedComponents` …
clementleclercRTE 10555c9
Merge remote-tracking branch 'origin/graph-connected-components' into…
clementleclercRTE e522228
Merge branch 'main' into graph-connected-components
clementleclercRTE caa146e
Remove `isComponentValid` method and inline validation logic in graph…
clementleclercRTE b54a1c6
Refactor `getConnectedComponents` API to use `Traverser` instead of `…
clementleclercRTE 8eb3d6c
Deprecate old traversal method, simplify `ConnectedComponentCollector…
clementleclercRTE c562c12
Refactor `getConnectedComponents` usage
clementleclercRTE c9cf18d
Merge branch 'main' into graph-connected-components
clementleclercRTE df1cf80
Refactor traversal methods and update internal connection tests.
clementleclercRTE 1b58640
Merge branch 'main' into graph-connected-components
clementleclercRTE c5a2ef6
Add unit tests for getConnectedComponents and update traversal logic
clementleclercRTE 7cd03d4
Merge remote-tracking branch 'origin/graph-connected-components' into…
clementleclercRTE 16a1dd0
Refactor topology models to replace `Set` with `List` and fix review …
clementleclercRTE e3e8b9e
Refactor topology models to replace `Set` with `List` and fix review …
clementleclercRTE 037e516
Merge remote-tracking branch 'origin/graph-connected-components' into…
clementleclercRTE b173fb9
Merge branch 'main' into graph-connected-components
clementleclercRTE 201fb81
Fix indentation
clementleclercRTE f73819e
Merge branch 'main' into graph-connected-components
clementleclercRTE 583b71a
Merge branch 'main' into graph-connected-components
clementleclercRTE f85d061
Merge branch 'main' into graph-connected-components
clementleclercRTE dd565cb
Merge remote-tracking branch 'origin/graph-connected-components' into…
clementleclercRTE 9557084
Refactor `getConnectedComponents` to `computeTraversalPartitions` and…
clementleclercRTE 8f96dea
Merge remote-tracking branch 'origin/main' into graph-connected-compo…
clementleclercRTE b6b5556
Merge branch 'main' into graph-connected-components
flo-dup 6c094d8
Merge remote-tracking branch 'origin/graph-connected-components' into…
clementleclercRTE e7cbba1
Merge remote-tracking branch 'origin/main' into graph-connected-compo…
clementleclercRTE 8f84c9a
review fix
clementleclercRTE File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -259,41 +259,6 @@ protected BusChecker getBusChecker() { | |
| return CALCULATED_BUS_CHECKER; | ||
| } | ||
|
|
||
| private void traverse(int n, boolean[] encountered, Predicate<SwitchImpl> terminate, Map<String, CalculatedBus> id2bus, CalculatedBus[] node2bus) { | ||
| if (!encountered[n]) { | ||
| final TIntArrayList nodes = new TIntArrayList(1); | ||
| nodes.add(n); | ||
| Traverser traverser = (n1, e, n2) -> { | ||
| SwitchImpl aSwitch = graph.getEdgeObject(e); | ||
| if (aSwitch != null && terminate.test(aSwitch)) { | ||
| return TraverseResult.TERMINATE_PATH; | ||
| } | ||
|
|
||
| if (!encountered[n2]) { | ||
| // We need to check this as the traverser might be called twice with the same n2 but with different edges. | ||
| // Note that the "encountered" array is used and maintained inside graph::traverse method, hence we should not update it. | ||
| nodes.add(n2); | ||
| } | ||
| return TraverseResult.CONTINUE; | ||
| }; | ||
| graph.traverse(n, TraversalType.DEPTH_FIRST, traverser, encountered); | ||
|
|
||
| // check that the component is a bus | ||
| String busId = Identifiables.getUniqueId(NAMING_STRATEGY.getId(voltageLevel, nodes), getNetwork().getIndex()::contains); | ||
| CopyOnWriteArrayList<NodeTerminal> terminals = new CopyOnWriteArrayList<>(); | ||
| for (int i = 0; i < nodes.size(); i++) { | ||
| int n2 = nodes.getQuick(i); | ||
| NodeTerminal terminal2 = graph.getVertexObject(n2); | ||
| if (terminal2 != null) { | ||
| terminals.add(terminal2); | ||
| } | ||
| } | ||
| if (getBusChecker().isValid(graph, nodes, terminals)) { | ||
| addBus(nodes, id2bus, node2bus, busId, terminals); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void addBus(TIntArrayList nodes, Map<String, CalculatedBus> id2bus, CalculatedBus[] node2bus, | ||
| String busId, CopyOnWriteArrayList<NodeTerminal> terminals) { | ||
| String busName = NAMING_STRATEGY.getName(voltageLevel, nodes); | ||
|
|
@@ -312,10 +277,30 @@ protected void updateCache(final Predicate<SwitchImpl> terminate) { | |
| LOGGER.trace("Update bus topology of voltage level {}", voltageLevel.getId()); | ||
| Map<String, CalculatedBus> id2bus = new LinkedHashMap<>(); | ||
| CalculatedBus[] node2bus = new CalculatedBus[graph.getVertexCapacity()]; | ||
| boolean[] encountered = new boolean[graph.getVertexCapacity()]; | ||
| for (int v : graph.getVertices()) { | ||
| traverse(v, encountered, terminate, id2bus, node2bus); | ||
| } | ||
|
|
||
| graph.getConnectedComponents((v1, e, v2) -> { | ||
| SwitchImpl sw = graph.getEdgeObject(e); | ||
| if (sw != null && terminate.test(sw)) { | ||
| return TraverseResult.TERMINATE_PATH; | ||
| } | ||
| return TraverseResult.CONTINUE; | ||
| }).forEach(nodes -> { | ||
| CopyOnWriteArrayList<NodeTerminal> terminals = new CopyOnWriteArrayList<>(); | ||
|
||
| for (int i = 0; i < nodes.size(); i++) { | ||
| NodeTerminal terminal = graph.getVertexObject(nodes.getQuick(i)); | ||
| if (terminal != null) { | ||
| terminals.add(terminal); | ||
| } | ||
| } | ||
| if (getBusChecker().isValid(graph, nodes, terminals)) { | ||
flo-dup marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| String busId = Identifiables.getUniqueId( | ||
| NAMING_STRATEGY.getId(voltageLevel, nodes), | ||
| getNetwork().getIndex()::contains | ||
| ); | ||
| addBus(nodes, id2bus, node2bus, busId, terminals); | ||
| } | ||
| }); | ||
|
|
||
| busCache = new BusCache(node2bus, id2bus); | ||
| LOGGER.trace("Found buses {}", id2bus.values()); | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.