-
Notifications
You must be signed in to change notification settings - Fork 81
pathcounts and allparents in DijkstraStates #155
Conversation
As it turns out, I needed the explicit parents lists as well, so I made further modifications. An optional Here's an example:
This should not be time-impactful, but might be memory-impactful (as it would store potentially Once folks are ok with this, I'll also push an update to the docs. |
@yeesian - we might also consider the (positive) impact this would have on something like |
Some times on a reasonably-sized random graph:
|
Sorry @sbromberger, but I'm not sure I'm on the same page.. Have you tried it on graphs with a million nodes/edges? I think those are instances that people care about, and that the README promises performance for. I'm of the understanding that
Although the keyword arguments are optional, the bloat in I can imagine this to be useful on occasion, but not for the 99% of applications that might use |
It's actually vital for efficient
What's the concern with optionally tracking parents? It's off by default but can be used in all sorts of path analysis with very little overhead. Having to compute all_paths parents after the fact is an expensive operation; it's much better to do it during the path discovery itself. Also: this does not modify the Dijkstra algorithm one bit. It just keeps track of extra information as |
cc @lindahua |
I think it'll help for you to provide the performance between dijkstra_shortest_paths(g,1) # before the PR and dijkstra_shortest_paths(g,1; all_paths=false) # after the PR for comparison |
tests bugfix added allparents, made accumulation optional and default to false added comments and fixed upstream pathcounts removed println for debug
I used the exact same randomly-generated {1m, 10m} graph for all tests:
Pre-PR code:
Post-PR code,
Post-PR code,
The PR code saves 15 seconds (about 50%) for |
|
||
dists::Vector{D} = state.dists | ||
parents::Vector{V} = state.parents | ||
hasparent::Vector{Bool} = state.hasparent | ||
colormap::Vector{Int} = state.colormap | ||
pathcounts::Vector{Int} = state.pathcounts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you wrap these two lines in an if-block? AIUI they will currently cause unnecessary allocation and GC in the all_paths=false
case, but I haven't tested this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an if all_paths
wrapping 124 and 125 actually worsened the time for both:
julia> @time z = dijkstra_shortest_paths(g,2, all_paths=true);
elapsed time: 3.926816859 seconds (653550664 bytes allocated, 20.23% gc time)
julia> @time z = dijkstra_shortest_paths(g,2, all_paths=true);
elapsed time: 3.349007774 seconds (636758152 bytes allocated, 15.47% gc time)
julia> @time z = dijkstra_shortest_paths(g,2, all_paths=true);
elapsed time: 3.31105659 seconds (636758152 bytes allocated, 15.53% gc time)
julia> @time z = dijkstra_shortest_paths(g,2);
elapsed time: 2.567676538 seconds (324112744 bytes allocated, 48.72% gc time)
julia> @time z = dijkstra_shortest_paths(g,2);
elapsed time: 2.169036004 seconds (324088144 bytes allocated, 37.58% gc time)
julia> @time z = dijkstra_shortest_paths(g,2);
elapsed time: 1.998513853 seconds (324088144 bytes allocated, 34.89% gc time)
julia> @time z = dijkstra_shortest_paths(g,2);
elapsed time: 2.081961072 seconds (324088144 bytes allocated, 34.56% gc time)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, I am surprised. I'd have thought the JIT and/or branch predictor would have eliminated most of the overhead with a million-node graph. Evidently not - thanks for checking!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries - I was hoping it would improve performance also.
Wow, those are some pretty compelling numbers for your use-case. But IMHO a 9% slowdown is not trivial, and I'd prefer to reduce that before merging this. Hopefully that'll be as simple as adding the if-statement I suggested :-) |
That
|
Closing this out. I'll move this into Centrality.jl as
I'm happy to revisit rolling it back into Graphs.jl - just let me know. |
SEE COMMENT BELOW FOR FURTHER EDITS.
Hi,
I needed the number of
(u,v)
shortest paths indijkstra
. I added a new vector calledpathcounts
that stores this information. It's an accumulator so shouldn't add any time complexity (will increase memory by sizeof(Int) * num_vertices).Here's an example: