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

enumerate paths should support DijkstraState all paths. #266

Closed
bicycle1885 opened this issue Dec 28, 2015 · 8 comments
Closed

enumerate paths should support DijkstraState all paths. #266

bicycle1885 opened this issue Dec 28, 2015 · 8 comments
Labels
enhancement new or improved functionality help wanted ideal for new contributors who want to help

Comments

@bicycle1885
Copy link
Contributor

The following graph is a diamond-shaped graph with two paths between 1st and 4th vertices:

using LightGraphs

g = DiGraph(4)
add_edge!(g, 1 => 2)
add_edge!(g, 2 => 4)
add_edge!(g, 1 => 3)
add_edge!(g, 3 => 4)
for path in enumerate_paths(dijkstra_shortest_paths(g, 1, allpaths=true))
    @show path
end

Apparently, there is a path 1 => 3 => 4 in the graph but it is not printed:

path = Int64[]
path = [1,2]
path = [1,3]
path = [1,2,4]

I naively thought that allpaths=true would enumerate all paths but it doesn't. Is this a bug or an intended behavior?

@sbromberger
Copy link
Owner

The graph you created only has four vertices so there cannot be an edge to vertex 5....

ETA: if you mean "the path 1->3->4", then the answer is that enumerate_paths does not (currently) treat an allpaths DijkstraState any differently than a non-allpaths. We should probably change this.

@CarloLucibello
Copy link
Contributor

probably @bicycle1885 meant 1->3->4. Should not the output look like this?

path = [1]
path = [1,2]
path = [1,3]
path = [1,2,4]
path = [1,3,4]

@sbromberger
Copy link
Owner

@CarloLucibello yes - ideally. enumerate_paths was not designed to handle all_paths dijkstra states though. I'll make this an enhancement.

@sbromberger sbromberger added enhancement new or improved functionality help wanted ideal for new contributors who want to help labels Dec 28, 2015
@sbromberger sbromberger changed the title enumerate_paths(dijkstra_shortest_paths(allpaths=true) doesn't enumerate all paths. enumerate paths should support DijkstraState all paths. Dec 28, 2015
@bicycle1885
Copy link
Contributor Author

if you mean "the path 1->3->4"

Sorry, I made a mistake. I meant "1 -> 3 -> 4" as you said. Edited the original post.

@sbromberger
Copy link
Owner

PS @bicycle1885 - this might make a nice easy PR if you've got some time :) I'm out of pocket for a week or two.

@bicycle1885
Copy link
Contributor Author

It would be suitable for an exercise of a graph theory 101 class :)
Okay, I'll make a pull request later.

@sbromberger
Copy link
Owner

Yes, I didn't mean to imply it would be a challenge for you - just that if you wanted a fix quickly, it might be best for you to create the PR since I'm on vacation :)

@sbromberger
Copy link
Owner

I've given this some thought lately, and I'm not sure I want to do this after all. It's recursive and will only really work for small graphs. Please feel free to continue the discussion but I'll close this out until someone can persuade me this is generally useful.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement new or improved functionality help wanted ideal for new contributors who want to help
Projects
None yet
Development

No branches or pull requests

3 participants