Repository navigation
Conversation
|
Yes -- this is a nice suggestion. The helper function checks if And I think it is really cool that |
dschult
left a comment
There was a problem hiding this comment.
Thanks for the fix!!
But it looks like the fix changes the order of the iterated dict entries which makes a doctest fail. I've made a suggestion below which shouldn't slow things much but keeps the node order the same as in G. Thoughts?
We already know which nodes are reachable. No need to iterate the whole graph. Signed-off-by: Celelibi <[email protected]>
dschult
left a comment
There was a problem hiding this comment.
Yup! Sorry for the wrong line number.
Thanks for the suggestion and help and getting it all ready!
Current Behavior
Currently, the function
single_source_all_shortest_pathscontains this line:Which might be a significant waste of time if most nodes aren't reachable from the given source.
Expected Behavior
Merely looping on the keys of
predcould lead to a significant improvement for large very sparse graphs.And I guess the
try-exceptin the loop is then no longer necessary.Steps to Reproduce
Here's an example that shows the performance issue. The more nodes in the graph, the slower, even if they are unreachable. Even though it might not be an issue for a single call to that function, when calling it on several sources, it quickly adds up. (See Additional context below.)
Environment
Python version: 3.12.8
NetworkX version: 3.2.1
Additional context
Day 10 part 2 of Advent of Code has a graph with many small connected components and asks to find the number of paths from all the nodes marked
0to all the nodes marked9.https://adventofcode.com/2024/day/10
As it turns out, calling
single_source_all_shortest_pathsfor all source nodes is pretty slow and takes 1.5 seconds for me. With the proposed change, it only takes 50ms.