Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Path extraction function #89

Open
dionyziz opened this issue Aug 25, 2018 · 0 comments · May be fixed by #94
Open

Path extraction function #89

dionyziz opened this issue Aug 25, 2018 · 0 comments · May be fixed by #94

Comments

@dionyziz
Copy link

Given the result of a single-source algorithm like Dijkstra or Bellman–Ford, provide a function which can extract the path from a given source to a given destination. Ideally, we should define a new object type for a shortest path tree that has the method to do so on it:

var shortestPathTree = graphlib.alg.dijkstra(g, "A", weight)
{weight, path} = shortestPathTree.path("A", "B")
console.log(weight, path)

The above should print two things: The weight of the path from A to B (which is literally shortestPathTree["B"].distance) as well as the path, which should be an array of nodes, in the correct order.

Alternatively, if we want to maintain the current data type returned by dijkstra for backwards compatibility, we could introduce a new function for path extraction:

var shortestPathTree = graphlib.alg.dijkstra(g, "A", weight)
{weight, path} = graphlib.extractPath(shortestPathTree, "A", "B")
console.log(weight, path)

The rationale for the above is that it is often the case that the application has to extract the shortest path between a source and a destination. While it is not a lot of work to traverse the predecessor pointers, it ends up being repetitive and we would rather avoid duplication by incorporating it in the library.

@pkakelas perhaps you can solve this by migrating our "getOptimalPath" code into a graphlib PR.

@mstou mstou linked a pull request Aug 25, 2018 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant