Skip to content
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

Added code to handle multi-graph in mst #7454

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Aditya-Shandilya1182
Copy link

No description provided.

@Aditya-Shandilya1182
Copy link
Author

This code is written to address issue #7451.

@Aditya-Shandilya1182
Copy link
Author

Code used to test the feature:

for g in nx.SpanningTreeIterator(nx.cycle_graph(3,create_using=nx.MultiGraph)):
    print(g.edges())

Result before changes:
fli

Result after changes:
mst

@mjschwenne
Copy link
Contributor

The code itself looks pretty good, but you should definitely add some test cases using multi-graphs to the iterator. Things that are worth testing would be that the number of generated trees is correct, and then that the trees themself are presented in a non-decreasing (and non-increasing for the reverse mode). For a small tests, enumerating the trees explicitly can be a good sanity check. The current tests for the iterator should provide a good roadmap.

@Aditya-Shandilya1182
Copy link
Author

I will try to add the test cases.

Comment on lines +1150 to +1153
edges = (
G.edges(keys=True, data=True) if G.is_multigraph() else G.edges(data=True)
)
for *e, d in edges:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this pattern! What do you think about using it above when setting d[partition_key]? This way, we wouldn't need separate for loops for if G.is_multigraph() and else.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looked neat this way.
Will it affect the performance of the code? I would love to hear your suggestions. I will make sure to change the code accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

3 participants