Question 1: First of all, you state that that the goal G2 will be found first by relying on the expansion order R, B, D, G2
.
This is wrong. It is extremely easy to see that this is wrong, because A* is a search algorithm that guarantees to find an optimal solution given that only admissible heuristics are used. (A heuristic is being admissible if it never over-estimates the optimal goal distance. This is the case in your example.) Since the true cost for reaching G1 is 11 and the true cost for reaching G2 is 13, clearly G1 must be found first.
Thus, your expansion order is wrong as well. Let us first give the f-values for all nodes:
f(A)=11, f(B)=10, f(C)=11, f(D)=13
Assuming that h(G1)=h(G2)=0 (i.e, the heuristic is "goal-aware"), we get f(G1)=11
and f(G2)=13
.
Because A* expands search nodes by lowest f-values of the search nodes in the open list (the search nodes not yet expanded), we get the following expansion order:
R, B, A, C, G1
You very-likely did a mistake that is done extremely often: after heaving expanded D, you add G2 to the open list. Because G1 is a goal node and you are already "seeing" it, you return it as a solution. But this is wrong! Goal nodes are not returned when being created, but when being selected for expansion! So, although the expansion of D generates G2, you are not allowed to return G2 as solution, because it has not been selected for expansion.
Question 2:
Can G2 be found as well?
As NietzscheanAI pointed out, you can simple continue search. That is, after heaving expanded R, B, A, C, G1
, A* will expand D, G2
.