-
Notifications
You must be signed in to change notification settings - Fork 81
Conversation
function show_dijkstra_shortest_paths{V}(g::AbstractGraph{V},all...) | ||
state = dijkstra_shortest_paths(g,all...) | ||
allvertices = g.vertices | ||
patharr = Array(Array{V},0) |
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.
This should be Array(Vector{V},0)
, I believe.
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.
Yes - sorry. Let me change that.
Seems reasonable to me, though travis is failing. I would name it something like |
Travis appears to be failing because the change that allowed |
|
||
g3 = simple_graph(4) | ||
add_edge!(g3,1,2); add_edge!(g3,1,3); add_edge!(g3,2,3); add_edge!(g3,3,4) | ||
sps = show_dijkstra_shortest_paths(g3,"2") |
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.
These are integer vertices, so should be 2
not "2"
here.
I got it - thanks for catching my stupid mistakes. For some reason I'm unable to rebase/squash these commits. |
(I'll update the docs separately if that's ok.) |
Okay, would be nicer if this were squashed with a separate commit for the whitespace changes. Leaving open (for a short time) for others' comments. |
I tried squashing but it's giving me errors. I'll keep at it for a bit. Also, just a question: the docs imply that |
I keep getting rebase errors on squash. I think this is the best I can do unless you'd prefer I start clean. Your call. |
Are you using |
HEAD~6 shows
I think the problem is that I've got
Let me see if the friendly folks on freenode#github can help :) |
Would probably be less effort just to open a new PR. |
We've all done it before :) |
It's an academic challenge at this point. Give me a few before I throw in the towel. :) |
Et voilà. |
Was the issue with multiple sources resolved? If not, could you update the method signature to only allow a single source? E.g.,
|
It was not, but I couldn't figure out how/whether it even worked in |
change Array to Vector silly test fix rename per suggestion updated docs explicit: source cannot be Vector/Array
dijkstra_shortest_paths_explicit()
Thanks! |
Thank you for all the guidance. I'm going to be working on more centrality measures (see #129). Could you let me know whether the proposed licensing text will work? |
Just saw this commit; it is great work, thanks! Some remarks:
|
Hi @yeesian (btw, your name is doing something really weird to my email client.)
Also: I think yours will fail with |
Hey @sbromberger (I've corrected my name to be more decorous, sorry about messing up your email client!),
# construct a graph and the edge distance vector
g = simple_inclist(5)
inputs = [ # each element is (u, v, dist)
(1, 2, 10.),
(1, 3, 5.),
(2, 3, 2.),
(3, 2, 3.),
(2, 4, 1.),
(3, 5, 2.),
(4, 5, 4.),
(5, 4, 6.),
(5, 1, 7.),
(3, 4, 9.) ]
ne = length(inputs)
dists = zeros(ne)
for i = 1 : ne
a = inputs[i]
add_edge!(g, a[1], a[2]) # add edge
dists[i] = a[3] # set distance
end
# Single source: Vertex 1
r = dijkstra_shortest_paths(g, dists, 1)
@assert r.parents == [1, 3, 1, 2, 3]
@assert r.dists == [0., 8., 5., 9., 7.]
# Multiple sources: Vertices 1 and 4
r = dijkstra_shortest_paths(g, dists, [1, 4]) #
@assert r.parents == [1, 3, 1, 4, 4]
@assert r.dists == [0., 8., 5., 0., 4.]
You're right about it failing (in the general case) with the implementation with OSM. There we had the luxury of assuming that our weights are *The vertices in OSM are also integers (since they're node ids), so we're not in conflict there. But I'll leave that discussion to #143? |
Hi @yeesian
Also: the failing is not with weights. With vertices that are Ints, the |
Ah sorry I'm out for the moment; I'll have a look when I'm back? I think you're on to the right direction for (5) too. Have a good new years eve! (: |
@yeesian Happy New Year to you as well! BTW, this is how your name was coming across in Mac Mail and in iOS: |
Oh haha that was actually intentional, and inspired by a thread on stackoverflow |
Brilliant. And here I was getting ready to blame Apple for breaking i18n. |
Ah, if I understand correctly, a That complicates things a bit, I would imagine. Let me think on this. |
Sorry for the delay, It seems you're onto the issues at hand (really thanks!), do let me/us know what you eventually decide, and where I might be able to help?
Yeah sure, although if we leave out vertex information, perhaps we should avoid having to work with DijkstraState altogether, and use some notion of paths = enumerate_paths(parents::Vector{V}) # assumed to be all destinations
paths = enumerate_paths(parents::Vector{V}, dest::V) # to a single destination
paths = enumerate_paths(parents::Vector{V}, dest::Vector{V}) # to a subset of the nodes The user can then map the vertex ids to the respective distances (in paths, distances = enumerate_paths(dijkstra::DijkstraState) # assumed to be all destinations
paths, distances = enumerate_paths(dijkstra::DijkstraState, dest::V) # to a single destination
paths, distances = enumerate_paths(dijkstra::DijkstraState, dest::Vector{V}) # to a subset of the nodes
I haven't noticed the discussion over at #142, and am perfectly happy with the decision to provide an "array indexed by vertex-index" instead of a Dict. |
Also, if I understand it correctly, paths = dijkstra_shortest_paths_explicit(g,source) is equivalent to result = dijkstra_shortest_paths(g,source) # L252
paths = enumerate_paths(result.parents) #L253-283 (And I think the latter is a little clearer in intent) |
@yeesian
But I thought the use case you needed was one in which you didn't know in advance whether explicit path determination would be necessary, but you had In any case, what might be best is for you to submit a PR or gist that we could discuss so that we make sure we're talking about the same thing. (This thread is taxing my ability to keep the issues/proposals straight.) I'm totally open to whatever method works best, as long as I can get explicit path information out of it :) I'm also nervous about using ETA:
Yes, essentially. The difference is pretty much the fact that we're referencing the vertices explicitly via |
Yeah sure! Sorry about extending this thread beyond its due. And happy new year to you too! (: |
Let me rewrite to use DijkstraState, if that's ok with you, and I'll post a gist for discussion. |
No worries, I'll submit a PR, and we can discuss there? |
OK, sounds good. I'll wait for your PR :) Just a caution: the reason we need the vertices is because you need to test "connectedness" for the case where vertices are Ints (https://github.com/JuliaLang/Graphs.jl/blob/master/src/dijkstra_spath.jl#L260). Since |
Oh! I see now that you require access to |
@sbromberger, there's really not much to |
See above: the reason you need the actual vertices is because (until #140 is resolved) you need to test for membership in |
for i in 1:length(parents) | ||
path = V[] | ||
currvertex = allvertices[i] | ||
connected = isdefined(parents,i) && (parents[i] in allvertices) |
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.
this is going to be pretty inefficient since allvertices
is usually quite large; see the workaround proposed in #140
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.
For SimpleGraph
, allvertices
is just a range hence pretty efficient. For other graph types, you're right.
to use enumerate_paths to return the paths corresponding to a (sub)set of destination vertices. See discussion in JuliaAttic#141
Function that will return the actual nodes involved in dijkstra_shortest_paths as an array of (arrays of vertices).
Ref: #139