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

In A* algorithm, There seems to be a problem when putting neighboring nodes into heap #1242

Open
ProofNight opened this issue Jun 22, 2023 · 0 comments

Comments

@ProofNight
Copy link

In the astar.cpp file, costs receive the map as a one-dimensional array.
This program uses the manhattan distance.
Select nodes up, down, left, and right through +i, -i, +nx_, and -nx_ at 68:71 line.
In the case of nodes at the edge of the map, simply using +i and -i will select the opposite node of the upper or lower line, respectively, so a conditional statement is required.

The code below is the code I modified

    if(i%nx_!=0)    add(costs, potential, potential[i], i - 1, end_x, end_y);
    if(i%nx_!=nx_-1)    add(costs, potential, potential[i], i + 1, end_x, end_y);
    add(costs, potential, potential[i], i + nx_, end_x, end_y);
    add(costs, potential, potential[i], i - nx_, end_x, end_y);
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

1 participant