evenfurther / pathfinding

Pathfinding library for rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can weights be ALL NEGATIVE for yen's method?

dovahcrow opened this issue · comments

It says

successors returns a list of successors for a given node, along with the cost of moving from the node to the successor. Costs MUST be positive.

in https://docs.rs/pathfinding/latest/pathfinding/directed/yen/fn.yen.html

However, it seems like all weights being negative also works.

Yen's algorithm has been designed for a network without any negative loops. In his 1971 paper, Yen describes two ways of obtaining the initial shortest path, one in which weights cannot be negative and one in which weights can be negative but must not form a negative loop.

In the current implementation, Dijkstra's algorithm is used to find the initial shortest path, which means that no negative weights can be used. If you want to propose a patch to use another algorithm, please go ahead.