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

Error in A* implementation #120

Closed
gdalle opened this issue Apr 21, 2022 · 7 comments
Closed

Error in A* implementation #120

gdalle opened this issue Apr 21, 2022 · 7 comments
Labels
bug Something isn't working

Comments

@gdalle
Copy link
Member

gdalle commented Apr 21, 2022

In the implementation of the A* algorithm, there is a vector called closed_set which is used to indicate whether a vertex has already been expanded.

Judging by the similar notations, this implementation is taken almost as-is from the Wikipedia page, but on Wikipedia the closed_set does not exist. In fact, the article clearly states that

When the heuristic being used is admissible but not consistent, it is possible for a node to be expanded by A* many times, an exponential number of times in the worst case.

Therefore, I think the presence of closed_set in the code is a mistake and should be corrected.

@gdalle
Copy link
Member Author

gdalle commented Apr 21, 2022

@matbesancon @etiennedeg

@matbesancon
Copy link
Member

if a vertex is expanded several times, are the following ones redundant with the first time this vertex is encountered? From your message I assume not

@gdalle
Copy link
Member Author

gdalle commented Apr 21, 2022

Probably not, because this means we have found a cheaper path to said vertex, which may reveal a cheaper path to its neighbors

@gdalle gdalle added the bug Something isn't working label Apr 21, 2022
@matbesancon
Copy link
Member

I'm ok with removing this. Even better if there is an example that fails to add to the tests

@captchanjack
Copy link

captchanjack commented May 22, 2022

Hello! Just looking into this as well

Looks like the Wikipedia page you referenced used to have the closed_set documented in its algorithm, found a reference to an older version of the page

Pretty much all the implementations I've found online use a closed_set, e.g. another julia package, python, c++, even this youtube video

According to this source and this, both may be correct:

The first approach (i.e. one with closed_set) is optimal only if the optimal path to any repeated state is always the first to be followed. This property holds if the heuristic function has the property of consistency (also called monoticity). A heuristic function is consistent if, for every node n and every successor n' of n, the estimated cost of reaching the goal from n is no greater than the step cost of getting to n' from n plus the estimated cost of reaching the goal from n.

@gdalle
Copy link
Member Author

gdalle commented May 22, 2022

Thanks for your input! Indeed, it looks like the closed set is useful to preserve optimality in cases where the heuristic is admissible but not consistent. See the following screenshots from Artificial Intelligence, a Modern Approach

Screenshot 2022-05-22 at 07 58 06

Screenshot 2022-05-22 at 07 56 10

@gdalle
Copy link
Member Author

gdalle commented May 22, 2022

I left the closed_set in #125, let's close this for now

@gdalle gdalle closed this as completed May 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants