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

Bug when edges are defined from the end #51

Closed
Lalbatros opened this issue Nov 27, 2023 · 1 comment
Closed

Bug when edges are defined from the end #51

Lalbatros opened this issue Nov 27, 2023 · 1 comment

Comments

@Lalbatros
Copy link

Lalbatros commented Nov 27, 2023

Good afternoon,

I just realised that if a link is defined from the end of a path to be found, the DijkstraFinder seems to give absurd results:

from pathfinding.core.diagonal_movement import DiagonalMovement
from pathfinding.core.graph import Graph
from pathfinding.core.node import Node
from pathfinding.finder.a_star import AStarFinder

edges = [
    [0, 1, 1],
    [1, 0, 1],
    [1, 2, 1],
    [2, 1, 1],
]
graph = Graph(edges=edges, bi_directional=False)
finder = DijkstraFinder()
path, runs = finder.find_path(graph.node(0), graph.node(2), graph)
print(len(path), [n.node_id for n in path])

output: 1 [2]

Comment the last edge out, and all is right again.

@brean
Copy link
Owner

brean commented Nov 27, 2023

Thank you! Nice catch!
Yes, this is a bug, that happens during the generation of the Graph, we are not checking if an element with the same id already exists, so there are multiple GraphNodes for number 2!
Funny side effect was that the order in which the elements are in your array are important, if you change the order to

    edges = [
        [0, 1, 1],
        [1, 0, 1],
        [2, 1, 1],
        [1, 2, 1],
    ]

it was also working...
Anyway. I fixed it and will released the fix as version 1.0.5 !

@brean brean closed this as completed in 2c9b9be Nov 27, 2023
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

2 participants