-
Notifications
You must be signed in to change notification settings - Fork 64
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
Heuristic function overestimates cost, leading to suboptimal plans. #9
Comments
Good point. |
Has this been resolved? |
This issue is still present in the current code base. You could follow steadmon's approach, or for an even quicker fix: returning a constant value 1 (or better: the lowest cost of all actions) for heuristic will also get rid of suboptimal paths. To thoroughly fix, you would have to determine lowest cost of flipping on a
Then dynamically, add this cost for each differing atom value based on direction. This will slow down the calculation of the heuristic of course, so if you can live with occasional sub optimal paths, the current code may be better. Note: If you decide to go steadmon's route, you will need to use floating point values for the heuristic. |
Output:
Am I missing something? |
Maybe OP's example was not a good one, but it is a valid point that overestimating the remaining cost can cause suboptimal plans. Personally, I don't worry much about those cases. In practice, they probably don't occur often, and if they do, you still end up with a working plan. If you are hell-bent on always getting the best plan, you can make the search un-directed, and always put the estimate at '1'. But then you get a combinatorial explosion. Playing with the heuristic is left as an exercise for the reader. Use what works for you. What's in the repo now works for me. |
It would be nice if issues like this one had practical unit test coverage, rather than theoretical. |
A* with a closed set can select suboptimal plans if the heuristic function overestimates the remaining cost of an intermediate state. The current heuristic of counting the conflicting states can be an overestimate in some cases. Consider the following setup:
Six state values: a, b, c, d, e, f
Initial state: all six values are False
Goal state: all six values are True
Four actions:
The optimal plan is "setA" followed by "optimal", with a total cost of 3. However, with the current heuristic, the code actually selects a plan of "setAB" followed by "trap", with a total cost of 6. This is because the heuristic overestimates the remaining cost after the action "setA" as having a likely remaining cost of 5, when in fact the remaining cost is only 1.
This can be fixed by changing the heuristic function as follows:
After all actions and costs are known, find the action with the minimum (cost / number of output states) ratio. Save this optimal ratio, and pass it as an additional argument to the heuristic function. The heuristic function should then return the number of conflicting states multiplied by the cost/output ratio.
The text was updated successfully, but these errors were encountered: