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

Enhance traversal docs #1375

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

Conversation

barakatzir
Copy link

This PR fixes #1361.
It add some elaboration to the traversal BFS and DFS functions, mainly with a more concrete pseudo-code.
I also fixed small doc errors in betweenness function's docstrings.
In the issue I also suggested doing a face-lift to the dijkstra_search. I can add this in to this PR in the style of the other docstrings changes I'm proposing If you'd like.

  • [v] I ran the nox -e docs and cargo doc to see that the result is good.
  • [v] I have read the CONTRIBUTING document.

@CLAassistant
Copy link

CLAassistant commented Jan 29, 2025

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@IvanIsCoding
Copy link
Collaborator

Thanks for submitting this! I will try to review it when I can, but again this is a welcome contribution.

@coveralls
Copy link

Pull Request Test Coverage Report for Build 13047597904

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 95.819%

Totals Coverage Status
Change from base Build 13020512734: 0.0%
Covered Lines: 18381
Relevant Lines: 19183

💛 - Coveralls

Copy link
Collaborator

@IvanIsCoding IvanIsCoding left a comment

Choose a reason for hiding this comment

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

This looks good to me with the caveat that I think for Python docstrings we should focus on the methods that highlight BFS/DFS only. I'd drop the iterator details

end while

If an exception is raised inside the callback function, the graph traversal
def BFSIterator(G, I, F):
Copy link
Collaborator

Choose a reason for hiding this comment

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

For Python I think it makes more sense to talk about BFS than BFSIterator. I'd rewrite it to keep the old signature BFS(G, s)

@@ -1565,38 +1633,68 @@ def tree_edge(self, edge):

@_rustworkx_dispatch
def dfs_search(graph, source, visitor):
"""Depth-first traversal of a directed/undirected graph.
"""Iterative depth-first traversal of a directed/undirected graph.
Copy link
Collaborator

Choose a reason for hiding this comment

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

We could have a recursive DFS with something like https://crates.io/crates/recursive these days, so I am not opposed to saying this.

With that in mind, DFS order is implementation dependent and even the order we iterate edges is not promised to be stable so it is what it is.

Copy link
Author

Choose a reason for hiding this comment

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

I copied the Iterative prefix from the rustworkx-core since it made sense to me to differentiate this method from the DFS algorithm which has a single source vertex.
I didn't know about DFS (the CLRS ref you sent me was helpful!) but my friends who do know (both the algo and of CLRS) were confused a bit by how several source vertices are incorporated.
If the implementation detail of how several source vertices are incorporated into DFS is not guaranteed, the docs should probably mention that as well.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I will double check Georgios’ implementation in the source code and check.

I myself forgot the specifics, either the user passes it as an input or we pick an arbitrary node I think

color[u] := BLACK finish vertex u

If an exception is raised inside the callback function, the graph traversal
def DFSIterator(G, I, F):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same comment from BFS

color[s] = GRAY
time += 1
F.Discover(s, time)
Q = [s] # LIFO vertex queue
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can call it a stack

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

Successfully merging this pull request may close these issues.

python BFS and DFS search documentation improvements
4 participants