Repository navigation
Added example for SpanningTreeIterator to find min spanning trees - #8556
Merged
Merged
Conversation
roboGOD
force-pushed
the
enhancement/7985-mst-iteration
branch
from
March 7, 2026 08:03
57f16d8 to
b08c9a0
Compare
rossbar
reviewed
Mar 9, 2026
rossbar
left a comment
Contributor
There was a problem hiding this comment.
I'm -1 on expanding the API surface in this way - my vote would be to expand the SpanningTreeIterator docstring examples
This reverts commit b364c93. Revert "Created find_all_optimal_spanning_trees" This reverts commit 1a116dd. Revert "Rename to `optimal_spanning_trees`" This reverts commit 983ff11. Revert "doc string" This reverts commit c0dceb0. Revert "Added tests" This reverts commit 57f16d8. Revert "Update mst.py" This reverts commit b08c9a0.
Contributor
Author
|
As per the suggestion, removed the helper function and added doc string example. |
optimal_spanning_trees using SpanningTreeIteratorSpanningTreeIterator to find min spanning trees
dschult
reviewed
Mar 11, 2026
dschult
reviewed
Mar 11, 2026
rossbar
reviewed
Mar 13, 2026
rossbar
left a comment
Contributor
There was a problem hiding this comment.
I think this is headed in the right direction! Just a couple minor suggestions
Co-authored-by: Ross Barnowski <[email protected]>
Co-authored-by: Ross Barnowski <[email protected]>
amcandio
approved these changes
Mar 21, 2026
amcandio
left a comment
Contributor
There was a problem hiding this comment.
Looks good do me. You could use itertools to have a more compact version:
min_spanning_trees = list(next(
group for _, group in itertools.groupby(
nx.SpanningTreeIterator(G),
key=lambda t: t.size(weight="weight")
)
))
Co-authored-by: Alejandro Candioti <[email protected]>
mcbosch
pushed a commit
to mcbosch/networkx
that referenced
this pull request
Apr 7, 2026
…etworkx#8556) * Created find_all_optimal_spanning_trees * Rename to `optimal_spanning_trees` * doc string * Added example * Added tests * Update mst.py * Revert "Added example" This reverts commit b364c93. Revert "Created find_all_optimal_spanning_trees" This reverts commit 1a116dd. Revert "Rename to `optimal_spanning_trees`" This reverts commit 983ff11. Revert "doc string" This reverts commit c0dceb0. Revert "Added tests" This reverts commit 57f16d8. Revert "Update mst.py" This reverts commit b08c9a0. * Added example for SpanningTreeIterator * dummy commit * Fix doc string * Update mst.py * Update mst.py * Update networkx/algorithms/tree/mst.py Co-authored-by: Ross Barnowski <[email protected]> * Update networkx/algorithms/tree/mst.py Co-authored-by: Ross Barnowski <[email protected]> * Update mst.py * Single max spanning tree * Update mst.py * Use itertools.groupby for example. Co-authored-by: Alejandro Candioti <[email protected]> --------- Co-authored-by: Ross Barnowski <[email protected]> Co-authored-by: Alejandro Candioti <[email protected]>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
As mentioned in #7985,
SpanningTreeIteratorcan be used to find all minimum or maximum spanning trees as the output of the iterator is sorted based on size.Added example on how to use
SpanningTreeIteratorto find all minimum spanning trees.