albertorestifo/node-dijkstra

Finding sevaral nearest paths

vadimJS opened this issue · 1 comments

Is there any chance to add option parameter like count of nearest paths (default 1), which will return nearest paths by their cost in ascending order?
For example:

const route = new Graph({
'A': {'B': 2, 'D': 1},
'B': {'C': 3, 'D': 4},
'C': {'D': 3},
'D': {'B': 4}
});

route.path('A', 'D', {count: 3});

RETURNS:
[
{path: ['A', 'D'], cost: 1},
{path: ['A', 'B', 'C'], cost: 6},
{path: ['A', 'B', 'C', 'D'], cost: 8}
]

Unfortunately this is not possible with this library:

In order to be faster, the implementation uses a priority queue. This effectively means that only the best path is visited, other options are discarded as soon as possible, in order to reach a conclusion fast.

For your goal, I suggest using a different algorithm or a different library.