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

Option to have multiple paths #6

Open
kristijanPetr opened this issue Oct 5, 2018 · 4 comments
Open

Option to have multiple paths #6

kristijanPetr opened this issue Oct 5, 2018 · 4 comments

Comments

@kristijanPetr
Copy link

Is there a way to have an option to show at least 3 shortest paths for given nodes?

@huangssssx
Copy link

同问

@nemosmithasf
Copy link

Looking for this as well, though the problem is that you'd have to somehow tell the graph to avoid minute variations. The graph has no way to know what constitutes a sufficiently unique path.

The best way to solve this is perhaps to tell the graph to avoid [array of nodes...] when path finding. That way, it's just a matter of running findPath 3 times with different avoidances.

  • Alternatively, you can probably hack this by just adjusting the weight of links every iteration of findPath

Would love to see a more elegant implementation though.

@anvaka
Copy link
Owner

anvaka commented Jun 6, 2020

That's right! All you need to do to get this is:

  1. Find the shortest path
  2. Pick an edge in the shortest path an assign its weight to Infinity
  3. Go to step 1.

When you repeat second time the path will be different, as we've made one previous edge impassible.

@nemosmithasf
Copy link

nemosmithasf commented Jun 25, 2020

A suggestion is to make a link "impassible" if the weight is set to "undefined".

I've tried setting it to MAX_SAFE_INTEGER. The problem is that when the pathfinding becomes impossible (e.g. you block off all the routes) with this method, the pathfinder will still treat MAX_SAFE_INTEGER as a number and return a path rather than failing.

This contradicts the mental model, leads to silent failures/bugs and is just more overhead to manage.

EDIT: I tried using Number.POSITIVE_INFINITY, when all the paths are blocked, it just returns the last Node instead of an array of nodes.

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

No branches or pull requests

4 participants