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

Support dynamic path decisions within the YenShortestPathsAlgorithm #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MichaelSchneider-Wtg
Copy link

Problem description

We have a more complex scenario to find the k shortest path just based on k. k is a fixed number like in a for loop. We want instead continue to search until we have met a certain condition, so like in a while loop.

Example

Let's plan a bike tour including some stops for refreshing.

Let's find some routes:

  • have a minimal length otherwise it is not worth it
  • have a maximum length, as our fitness is limited
  • have 2 or 3 intermediate stops to have a good balance between biking and resting
  • try to find up to 5 routes but not more as I want some choice, but if the list is too long I'm overwhelmed and I cannot decide

Using existing k parameter and filter

To find 5 routes, we could set k to 5, but this will likely contains some unwanted routes or even no route at all.
We could now using a k of 100 for example, but this could lead to potential overhead in calculation as we find more routes than necessary. Also 100 is just a guess, it could be also 50 or 500, we just do not know in advance.

The filter at the end is not a problem, but we have to ensure that our found routes pool is big enough to pick the wanted routes.

Change

Provide a new function to YenShortestPathsAlgorithm constructor that inspects each path individually and decides:

  • accept the path and add it to the result list (same as filter would do)
  • decide whether to continue to search for more paths (let's take it as a condition based k parameter)

The default behavior, in case the method parameter is not provided, would be to accept all paths and continue until k is reached.

Technically it would be enough to just check for search continuation based on the found shortest path and then filter at the end. But allowing the filtering right after finding the path would allow to compare the new path with only the wanted path. Otherwise I might have to do the calculation to filter the path in each iteration to check if my abort condition is met.

Main benefit

We can reduce the path finding iterations to the minimum we actual need to met our preset condition. A fixed k could lead to too less results or too many unnecessary iterations which is bad for the performance.

- do not rely on a fixed k, but find as many path until a certain condition is met
- decide whether to add a path to the final result set right after finding this path instead of having to wait until all paths are discovered
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 this pull request may close these issues.

None yet

1 participant