-
Notifications
You must be signed in to change notification settings - Fork 36
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
Limitation on cost 0 #17
Comments
The cost in the Dijkstra algorithm is expected to be a factor of the distance between nodes. If a node cost in 0, it means that node is in the same position as the neighboring node. This means the node will always be visited, no matter what. Supposing the two nodes have the same connections, this means the node will always appear in the result. Suppose we have:
If we start from A to D, the path will be Supposing the two nodes have a different connection. If the cost between them is 0, it means they are in the same spot. Consequentially they should be merged into one. Maybe I'm missing a use-case where you want a connection with cost 0? It would not break the algorithm but might lead to results containing more nodes than necessary, which is why there is the check. |
The problem I was solving is this one. Basically the solution is using graphs like:
It has a cost to move from 1 to 2 but it is free to move the other way around (2 to 1). On this case the nodes are different and it is ok to include them on the path. For instance moving from 1 to 6 is faster |
I agree that costs of 0 should be valid. Dijkstra's algorithm doesn't necessarily mean distance - just cost. Maybe it is free to move from node A to node B, but not free to move from node A to node C |
Looking at the function isValidNode I see that a cost of 0 is forbidden.
I think a cost of 0 is a valid situation meaning that there is a connection between 2 nodes while it is costless.
Is there any reason for this limitation?
The text was updated successfully, but these errors were encountered: