Skip to content
This repository was archived by the owner on Oct 21, 2021. It is now read-only.

How to process dijkstra shortest path parents that return #undef? #140

Closed
sbromberger opened this issue Dec 28, 2014 · 7 comments · Fixed by #145
Closed

How to process dijkstra shortest path parents that return #undef? #140

sbromberger opened this issue Dec 28, 2014 · 7 comments · Fixed by #145

Comments

@sbromberger
Copy link
Contributor

This may be a more general Julia question, but I'm at a loss as to how to treat something like this:

h = graph(["a","b","c","d"],[])
add_edge!(h,"a","b"); add_edge!(h,"b","c"); add_edge!(h,"a","c"); add_edge!(h,"c","d")


julia> dijkstra_shortest_paths(h,"b").parents
4-element Array{ASCIIString,1}:
 #undef
    "b"
    "b"
    "c"

How do I test for this #undef in code?
Also, more of an enhancement request, I guess - is there ANY way to get Graphs to return something consistent when a node is not reachable? That is, strings return #undef, ints return either some very large number or 0 (not sure why):

julia> dijkstra_shortest_paths(g,2).parents
4-element Array{Int64,1}:
 140253310593744
               2
               2
               3
...

julia> dijkstra_shortest_paths(g,2).parents
4-element Array{Int64,1}:
 0
 2
 2
 3

and I'm not quite sure how to test for all these cases other than checking to see whether the value is in graph.vertices, which apparently fails with ERROR: access to undefined reference if the value is #undef...

@mlubin
Copy link
Contributor

mlubin commented Dec 28, 2014

Well, you can use isdefined(x,10) to check if x[10] is #undef. I agree though that this behavior could be improved. Maybe parents should use the new Nullable type?

@sbromberger
Copy link
Contributor Author

I'd like some consistent way - right now it's two checks that cover strings and ints, but I don't have a ton of confidence that I've caught edge cases.

The other case where I'm seeing what appears to be uninitialized array values (see 140253310593744 above) is additionally worrying. I'll try to dig into the code a bit but I'm neck-deep in centrality right now.

@pozorvlak
Copy link
Contributor

I think @mlubin's suggestion of using Nullable is the way to go here.

@yeesian
Copy link
Contributor

yeesian commented Jan 1, 2015

Is Nullable only available in base julia 0.4?

@mlubin
Copy link
Contributor

mlubin commented Jan 1, 2015

yes

@mlubin
Copy link
Contributor

mlubin commented Jan 1, 2015

Or we can just use a simple bool array to indicate if a parent has been set or not.

@yeesian
Copy link
Contributor

yeesian commented Jan 1, 2015

Yeah, I was thinking the same thing, at least for older versions of Julia

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

Successfully merging a pull request may close this issue.

5 participants