-
Notifications
You must be signed in to change notification settings - Fork 1
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
refactor(BaseGraph): improve performance of get_components #23
base: feat/tmp-remove-nodes
Are you sure you want to change the base?
Changes from all commits
a732914
269182b
9f3bd5b
68adcd2
a40bedd
f7e0085
0351b12
89d6341
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,11 +84,8 @@ def _get_shortest_path(self, source: int, target: int) -> tuple[list[int], int]: | |
def _get_all_paths(self, source: int, target: int) -> list[list[int]]: | ||
return list(rx.all_simple_paths(self._graph, source, target)) | ||
|
||
def _get_components(self, substation_nodes: list[int]) -> list[list[int]]: | ||
no_os_graph = self._graph.copy() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As @jaapschoutenalliander already pointed out: Surprisingly, there seems to be no performance increase. Verified it on my own laptop. Seems even slightly slower: 0.36 (this PR) vs. 0.33 (main) at 5000 nodes I still think we can consider merging this because in my opinion it makes the implementation more readable and more consistent with the other methods. Also, our performance test might not be representative enough (only 2 Substation nodes). I could also try a more representative performance comparison with my internal project at Alliander |
||
for os_node in substation_nodes: | ||
no_os_graph.remove_node(os_node) | ||
components = rx.connected_components(no_os_graph) | ||
def _get_components(self) -> list[list[int]]: | ||
components = rx.connected_components(self._graph) | ||
return [list(component) for component in components] | ||
|
||
def _get_connected(self, node_id: int, nodes_to_ignore: list[int], inclusive: bool = False) -> list[int]: | ||
|
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.
perhaps we can add the deprecation message for substation_nodes?
something like
warning should say intended use is as follows: