11

I know that A* with admissible non consistent heuristic will not find optimal solution but I am struggling with finding example when will it happen.

I can not find example because of this thought - after inserting our goal node (with non optimal f(n)) to the priority queue, priority queue must also contains node e.g. node_1 which is on the optimal path. f(n) of node_1 in priority queue must be less than f(n) of our goal node, since we are using admissible heuristic. That is why node_1 will be dequeued earlier and after some iterations of A* (using the same idea) goal_node will get dequeued later after optimal path is found.

Where am I thinking wrong ? Can someone give me concise example of simple graph when A* with admissible non consistent heuristic will find non optimal path ?

Thank you.

Druudik
  • 955
  • 1
  • 10
  • 32
  • 1
    IMHO, this question is rather for cs.stackexchange.com or even math.stackexchange.com – user31264 Aug 04 '18 at 10:59
  • Does this quote from [Wikipedia](https://en.wikipedia.org/wiki/A*_search_algorithm) answer your question? - "**If a closed set is used**, then h must also be monotonic (or consistent) for A* to be optimal. ... [If it's not monotonic], nodes in the closed set may be rediscovered and their cost improved". – Bernhard Barker Aug 04 '18 at 12:02
  • @Dukeling I said that I already know about this. I am asking for the example of the graph where this will happen or prove why it will not be optimal. – Druudik Aug 04 '18 at 15:27
  • 1
    If you use the A* algorithm [as originally defined](https://ieeexplore.ieee.org/document/4082128)[PDF], it will find an optimal solution with an admissible heuristic. – jazzpi Sep 22 '19 at 15:28

1 Answers1

24

Here's an example of a graph where we get the wrong answer with an inconsistent heuristic. Here, heuristics are shown with parentheses near each node and edge costs written next to the edges:

     (8)
      A
     / \
+1  /   \ +3
   /     \   
  B ----- C ----- D
(7)  +1  (0)  +6  (0)

Here, the optimal path from A to D is A - B - C - D for a total cost of 8. But let's see what A* would do:

  • Starting at A, the options are to go A - B for a cost plus heuristic of 8, or to go from A - C for a cost plus heuristic of 3. So we pick A - C.

  • Now, our options are to expand out A - B for a cost plus heuristic of 8, or expand C - D for a cost plus heuristic of 9. So we pick A - B.

  • We've already closed out C by the earlier path, so we don't consider the edge B - C. Instead, we pick C - D for a cost of 9.

  • Overall, we found the path A - C - D. Oops.

The next question is how on earth you'd find an example like this one, and for that, a perspective that I think is quite useful for thinking about how A* works is the following:

Running A* on a graph whose edges have costs c(u, v), using a heuristic function h(v), is equivalent to running Dijkstra's algorithm on a graph where the cost of an edge (u, v) is c(u, v) + h(v) - h(u).

In other words, you can think of what A* is doing as though you were running Dijkstra's algorithm, tweaking the cost of each edge by adding in the change in the heuristic value across each edge.

The reason this is useful is that Dijkstra's algorithm, famously, will give back the wrong answer in cases where there are negative edges in the graph. So we can ask - when we change the edge costs to be c(u, v) + h(v) - h(u), could we ever end up with a negative cost? In other words, what would have to happen to ensure that

c(u, v) + h(v) - h(u) ≥ 0?

With a quick rearrangement, you might notice that this happens precisely if

c(u, v) + h(v) ≥ h(u)

or, equivalently, uf

h(u) ≤ c(u, v) + h(v).

And hey! That's the definition of a consistent heuristic.

What this means is that things can go wrong using A* with an inconsistent heuristic in exactly the same way that things can go wrong with Dijkstra's algorithm using negative edge weights. You'd (mostly likely) run into an issue where you find a suboptimal path to some intermediary node on the path to the goal, and from there get the wrong answer.

I ended up making the above graph where A* fails by starting with this graph where Dijkstra's gets the wrong answer, then reverse-engineering a heuristic that made the edge costs all positive:

    A
+0 / \ -5
  /   \
 B --- C --- D
    -6    +6

Here, the path Dijkstra's would find from A to D is the path A - C - D for a cost of 1, rather than the path A - B - C - D for a cost of 0. That's the same wrong path as in the A* example up top.

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
  • Thank you for your answer. It was helpful. But it did not really answered my question. In you graph example you are using heuristic which is not admissible (heuristic for node B is 7 but cost of actual path is 4). I know that with not admissible heuristic A* may find non optimal solution. But I was curious about finding the example of such a graph where we will find non optimal solution using ADMISSIBLE and not consistent heuristic for A* graph search. – Druudik Aug 05 '18 at 11:07
  • 2
    @User5458622 Oops! I’ve just updated the example to use an admissible, inconsistent heuristic that still gives the wrong path. – templatetypedef Aug 05 '18 at 15:39
  • 1
    Wrong example. Expanding CD means a cost of 7. – geek101 Sep 18 '18 at 17:34
  • The new example is not admissible @templatetypedef – geek101 Sep 18 '18 at 17:40
  • @JaiMahajan I believe I've fixed things. The new example is an admissible heuristic (it never underestimates the total distance), but it's inconsistent and thus leads to a wrong answer. – templatetypedef Sep 18 '18 at 18:44
  • @templatetypedef I dont agree with your decision of not going through BC because C is closed. I thing you are confusing things. A* just goes by the F value and stops when the path including the goal state is expanded. See the following video it gives a good explanation of the A* traversal to a graph like yours. https://youtu.be/DhtSZhakyOo – geek101 Sep 18 '18 at 21:36
  • Even after getting S->B we explore S->A->B, etc in the video. Open and closed lists work out in IDA* and SMA*. – geek101 Sep 18 '18 at 21:42
  • Also I quote "With a consistent heuristic, once a node is expanded and placed on the closed list, it never moves back to the open list."https://www.google.co.in/url?sa=t&source=web&rct=j&url=https://webdocs.cs.ualberta.ca/~holte/Publications/ijcai09.pdf&ved=2ahUKEwiQ_43aw8XdAhUSWX0KHYXTCysQFjADegQIGxAB&usg=AOvVaw0mi_uod0wCi3yGenN1rzY3 the heuristic in your case is not consistent – geek101 Sep 18 '18 at 21:50
  • 2
    I’ve seen several different variations on A*. If you use the idea of a closed list, as in Dijkstra’s algorithm, then A* requires consistent heuristics in addition to admissible ones to avoid the sort of issue illustrated in my answer. If you don’t use closed lists, then you’ll always get the right answer if your heuristic is admissible, but the runtime can become exponentially large in the size of the input state space. So in that sense, perhaps the best answer would be “if you use closed lists, you can get the wrong answer, and if you don’t, then inconsistency can lead to a performance hit.” – templatetypedef Sep 18 '18 at 22:50
  • Note that, in the original paper, Hart uses the concepts of open/closed nodes, but defines the expansion as such: "Calculate f for each successor of n and mark as open each successor not already marked closed. **Remark as open any closed node n_i which is a successor of n and for which f(n_i) is smaller now than it was when n_i was marked closed.**" (Emphasis mine) Which is why the paper can then go on to prove that A* does indeed find optimal solutions if the heuristic does not overestimate in Theorem 1. – jazzpi Sep 22 '19 at 15:20
  • The cost for A - C - B would be 11. The cost for A - C - D would be 9. So why did you choose A - C - B first? – Kataran Dec 24 '20 at 11:05