-
Notifications
You must be signed in to change notification settings - Fork 157
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
Implement simple_cycles() Johnson Algorithm #622
Comments
@mtreinish Maybe just a wrong condition |
It's still a work in progress (hence the |
Hi @mtreinish, |
This commit adds a new function, simple_cycles(), which is an implementation of Johnson's algorithm [1] for finding all the simple cycles in a directed graph. The implementation is based on the non-recursive implementation from NetworkX. [2] [1] https://doi.org/10.1137/0204007 [2] https://github.com/networkx/networkx/blob/networkx-2.8.4/networkx/algorithms/cycles.py#L98-L222 Closes: Qiskit#622
I think I've got it working now, see #633, let me know if you still have issues with it. I still need to do more testing and add more tests to the PR |
Working as expected! |
* Add Johnson's algorithm for cycles in directed graph This commit adds a new function, simple_cycles(), which is an implementation of Johnson's algorithm [1] for finding all the simple cycles in a directed graph. The implementation is based on the non-recursive implementation from NetworkX. [2] [1] https://doi.org/10.1137/0204007 [2] https://github.com/networkx/networkx/blob/networkx-2.8.4/networkx/algorithms/cycles.py#L98-L222 Closes: #622 * Remove test debugging * Fix lint * Add more tests * Apply suggestions from code review Co-authored-by: georgios-ts <45130028+georgios-ts@users.noreply.github.com> * Fix rustfmt * Make return from simple_cycles a iterator This commit converts the simple_cycles function to a Python class that implements the iterator protocol. Each step of the the iterator will compute the next cycle using Johnson's algorithm and return a NodeIndices object representing the cycle. * Use IndexSet::pop() instead of set_pop() * Fix iterator behavior * Fix MSRV support * Use mem::take() instead of .drain(..).collect() Co-authored-by: georgios-ts <45130028+georgios-ts@users.noreply.github.com> Co-authored-by: Ivan Carvalho <8753214+IvanIsCoding@users.noreply.github.com>
What is the expected enhancement?
Networkx has an algorithm for finding all cycles in a directed graph:
simple_cycles
it's based on the Research of D. B. Johnson in 1975
Would love to see a rust implementation of that!
The text was updated successfully, but these errors were encountered: