Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why isn't my heuristic for the A* algorithm admissible?

I am going through the CS 188 availible to the public at edx.org. Right now I have to develop a heuristic for an A* search to eat all the pellets as shown here: Pacman

My heuristic that I was sure would work, (as both admissible and consistent) went like this:

  • initialize heuristic accumulator called h to be 0
  • initialize pos to be the current position of pacman
  • while pellets not eaten:
    • get nearest pellet from pos using astar search (Manhattan distance as the heuristic)
    • add the distance to h
    • remove the pellet from pellets
    • set pos to be the position of pellet

I also cache the previously computed distances so the astar search to find the nearest pellet isn't done if it has already been done before in another computation of a state. It is able to solve the problem very quickly, and the outcome is optimal.

When I use this algorithm in the autograder, it fails the admissibility test.

Don't worry, I am not asking for a solution to the problem, only why my current solution is not admissible? When I go through the example in the picture in my head the heuristic is never overestimating the cost.

So if anyone was able to understand this, and has any ideas your input is greatly appreciated!

like image 843
Zach Avatar asked Dec 13 '13 06:12

Zach


People also ask

What makes a heuristic inadmissible?

For a heuristic to be admissible to a search problem, needs to be lower than or equal to the actual cost of reaching the goal.

WHY a * is not always optimal with an admissible heuristic?

A problem with A* is that it fails to guarantee optimal solutions when its heuristic, h, overestimates. Since optimal solutions are often desired and an underestimating h is not always available, we seek to remedy this. From a non- admissible h an admissible one is generated using h's statistical properties.

What is admissible heuristic function for a * algorithm?

In computer science, specifically in algorithms related to pathfinding, a heuristic function is said to be admissible if it never overestimates the cost of reaching the goal, i.e. the cost it estimates to reach the goal is not higher than the lowest possible cost from the current point in the path.

IS a * algorithm admissible?

Key Point: All A* algorithms are admissible. In other words, bread-first search uses a trivial estimate of the distance to the goal. Route Finding Example: For route-finding problems, the straight-line distance from city n to a goal city is a lower bound on the distance of an optimal route from n to the goal.


2 Answers

A heuristic for A* needs to provide a number that is no more than the best possible cost. Your heuristic is a plausible greedy solution that does not guarantee this. Suppose that there is a single line of pellets and the pac-man is slightly off centre on this line. The cheapest solution is work out which end of the line is nearest, eat all the pellets to the end of that line, and then move in the other direction to eat all the other pellets without having to reverse in the longer half of the line.

Your greedy heuristic moves first to whichever pellet is nearest the pac-man which might not be the side that has the shortest distance, so in this case it may not return a cost no greater than the optimal cost - it returns the cost of a possible solution which may not be optimal.

like image 164
mcdowella Avatar answered Sep 20 '22 10:09

mcdowella


Here is way to set up heuristic which is feasible for your problem. Firstly if your goal is to eat all pellets in minimum distance then your solution is too greedy to achieve a feasible solution for it. Here is way to redesign your heuristic:-

Goal : Eat all pellets in minimum path length.

Heuristic Estimate :

1.> Use A* to calculate all shortest paths from current position to pellets independently.

2.> Cost function: (sum of all unvisited pellets shortest path from current)*2 + total distance from start state.

The Cost function is upper bound .

Note: There can be more efficient way to calculate shortest paths to uneaten pellets at each state. Would need some research.

like image 30
Vikram Bhat Avatar answered Sep 21 '22 10:09

Vikram Bhat