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

Add method to compute Minimum cost spanning arborescence to WeightedGraph #86

Open
NickTheFreak97 opened this issue Jun 14, 2024 · 2 comments

Comments

@NickTheFreak97
Copy link

NickTheFreak97 commented Jun 14, 2024

There are various use cases of graphs where it's relevant to extract a minimum cost spanning arborescence (equivalent of minimum spanning tree for undirected weighted graphs).

For example in my case it was relevant to create a variant of the observer pattern (then turned into mediator), to avoid redundant updates: you create a dependency graph and for each component, extract a minimum cost spanning arborescence (weights are used if some routes for updates are preferred to others), then send updates down the MSA rooted in the component.

I can share some code if needed.

@davecom
Copy link
Owner

davecom commented Jun 14, 2024

Sure, if you want to share a pull request I'll take a look. Please put it in an extension to Graph or UnweightedGraph in a separate file and tests would be ideal too. Thanks!

@NickTheFreak97
Copy link
Author

NickTheFreak97 commented Jun 14, 2024

I'm not that great at using Github and I'm not sure how to properly do that. Though I have the extension pushed in this repo on a convenience account that I use to park libraries for my main project without polluting my main.

It is already structured as an extension and in separate files. Currently it only contains the method for computing the MSA on top of SwiftGraph (and an Union-Find by rank with path compression leftover file that I plan to remove in the future because I don't need it anymore).

A possible improvement is to move part of the code from func msa(_:) to a private helper function that works under the assumption that every vertex of the graph is reachable from the specified root. This way, when only a subset of the vertices was reachable from root, the check won't be performed twice, leading to performance improvements.

EDIT: I did what I described in this last paragraph in the latest commit.

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

No branches or pull requests

2 participants