Repository navigation
Add single_source_all_shortest_paths and all_pairs_all_shortest_paths - #5959
Conversation
add single_source_all_shortest_paths and all_pairs_all_shortest_paths
|
Thanks for this @dzy49 ! I think there's general consensus that this is a good idea and the right way to go. It'd be good to add some tests for the new functions, though we likely don't need a ton of testing since these new functions are thin wrappers on top of existing (hopefully well-tested) functionality. |
|
@rossbar Hi, as you suggested, I added some simple tests, however automatic testing is saying "Your tests failed on CircleCI", and the output isn't making much sense, is there something I forgot to do? |
No these failures are unrelated. The underlying issue should be fixed on main so you should be able to fix this by simply merging with main and pushing! |
Okay. I merged with main but it seems like the issue is still there |
Oops - sorry about that. I thought we had fixed all of these but it turns out we missed one. Everything should now be fixed as of #5994 - one final merge with main should do the job. |
|
Thanks for useful work, and i want to know when we can use this function? |
|
Well -- you can use it now via the branch of the PR, but I think you mean: when will it be merged with the NetworkX repo? We like these functions and the implementation, but are looking for time to review it. |
|
@dschult Hi, thanks for your help, and i want to know how can i use the branch of the PR, i see the branch is "feature-for-issue-5949" and i use the command "git clone -b feature-for-issue-5949 [email protected]:networkx/networkx.git", but it said "fatal: Remote branch feature-for-issue-5949 not found in upstream origin". How can i use it now via the branch of the PR? |
|
@wsh2836741 the quickest way here would be to pip install this branch in your python environment. |
|
That is a reasonable result. If nodes in the graph are not connected then you can't compute all shortest paths between all pairs of nodes. There is no path between the nodes. So the function raises an exception. |
|
@dschult That is not a reasonable result. These is no exception when i use the function "all_pairs_shortest_path". If nodes in the graph are not connected then the function "all_pairs_all_shortest_paths" will not compute all shortest paths and the nodes will not appear in the return result of the function, but not raises an exception. |
|
Point taken -- it is certainly not an optimal result if you want the partial results given by the pairs that are connected. As you point out, the current |
I have thought about this, but in my personal use case all my graphs were connected, so I didn't pay much attention to the behaviors when graphs are not connected. |
|
@dzy49 Yes,i think output partial results is more useful. Can you modify the code? Thanks a lot. |
I made the change and now it outputs partial results, simialr to |
|
No need to open a new PR. Its a busy time of year, but we'll get to it. |
dschult
left a comment
There was a problem hiding this comment.
Thanks for this and thanks for waiting for us to review it.
-
please go ahead and add a note to the
all_pairs_shortest_pathdoc_string that If there are ties (more than one shortest path) only one of them is reported. And (maybe instead?) you could/should add these new functions to the "See Also" section in those doc_strings. -
can you wrap the text in the doc_strings to be shorter than the (88) max text width for code? It's Ok to make that smaller if that is easier (like wrap to 80). That doesn't work well sometimes for examples where the output has to match what is actually created exactly. In that case (i.e. line 635 which prints all the possible shortest_paths), can you change the example so that it prints a shorter output -- like make the dict and then print some interesting parts of it. e.g.
all_paths[0][3]andall_paths[0][2]. Otherwise the documentation gets hard to read. You can put the full output test into the tests. -
Are the resulting orders of the paths consistent? I mean do we need the
sortedfunction on the tests? Generally, if the algorithm uses dicts (which are now ordered) and lists, the order will be the same over different hardware and memory. If we use sets, then the order is arbitrary and can vary. -
Other possible methods could be Floyd-W and Johnson. No reason to implement them as far as I'm concerned, but can you comment about whether there is a reason not to do that?
More comments below.
add note to all_pairs_shortest_path line width for example fixed raise
|
Hi, I made changes according to your suggestions!
For the For other possible methods, for now, I am just leveraging the existing method since this is the easiest. |
|
The current Johnson method doesn't handle ties. I'm not sure whether it is worth adding it here. If you want to, go for it. But if you'd rather get this merged, we can put that in later.
Looking good! |
|
Thanks! I fixed the line width and |
dschult
left a comment
There was a problem hiding this comment.
I shortened the doc_string in unweighted.py.
This looks good to me -- ready for merge after another set of eyes.
Thanks!!
|
@rossbar I am wondering if you can take a look at this? thanks! |
…networkx#5959) * Update generic.py add single_source_all_shortest_paths and all_pairs_all_shortest_paths * test and code format * black format * add simple tests * changed behavior when the graph is not connected * address issues add note to all_pairs_shortest_path line width for example fixed raise * fix missing blank line * format * line width and print * wrap doc_string from weighted.py --------- Co-authored-by: Dan Schult <[email protected]>
…networkx#5959) * Update generic.py add single_source_all_shortest_paths and all_pairs_all_shortest_paths * test and code format * black format * add simple tests * changed behavior when the graph is not connected * address issues add note to all_pairs_shortest_path line width for example fixed raise * fix missing blank line * format * line width and print * wrap doc_string from weighted.py --------- Co-authored-by: Dan Schult <[email protected]>
|
Hello, I've noticed that the documentation for the newly merged functions is not appearing on the NetworkX documentation site. Are there any specific steps or updates required to ensure these functions are included in the documentation? |
|
Rats! I didn't look at the PR closely enough. For each of the new functions you should include an entry in the appropriate Those changes should be made in a new PR. The tests in the new PR include a test that builds the docs, and another test that loads the html pages to a temporary url (the test appears as "document artifact"). Look on the "Details" link for that test to go to the documentation webpage with that PRs changes included. |
…networkx#5959) * Update generic.py add single_source_all_shortest_paths and all_pairs_all_shortest_paths * test and code format * black format * add simple tests * changed behavior when the graph is not connected * address issues add note to all_pairs_shortest_path line width for example fixed raise * fix missing blank line * format * line width and print * wrap doc_string from weighted.py --------- Co-authored-by: Dan Schult <[email protected]>

as discussed in issue #5949, add
single_source_all_shortest_pathsandall_pairs_all_shortest_paths