馃攳
A* Search - YouTube
Channel: unknown
[0]
Second algorithm I'm going to run for
[1]
you is the A* search algorithm. This
[5]
is also going to return for me the
[7]
optimal path but the theory is that you
[10]
should do a little less work or even a
[12]
lot less work just the fact it's going
[14]
to use a heuristic to do an informed
[18]
version of the search. Let's have a look
[20]
at how this works. As you can see in the
[23]
search space now each node in the search
[26]
space has a number next to it and that
[28]
number is an estimate, a quick compute
[32]
estimate, of what the cost is between
[35]
that state and one of the goal states. So
[40]
the estimate is the between node B and
[43]
one of the goals it's going to cost six.
[47]
As you can see the actual cost which the
[52]
shortest path between D and the goal
[55]
state is actually nine so this is an
[59]
under estimate and this turns out to be
[61]
important. In order for the A* search
[64]
algorithm to return the shortest path
[67]
you must use a heuristic that never
[73]
overestimates the cost. So it either
[76]
underestimates or get it gets it entirely
[79]
correct. So here I've got heuristic
[82]
values that are never over estimating
[85]
the cost and therefore what that means
[88]
is that A* is going to return the
[90]
optimal path for it let's see how this
[93]
works. It works in a similar way to
[98]
uniform cost search except that we use
[100]
the A8 search score that's the cost
[103]
of the path so far as we used in uniform
[107]
cost search plus we add on to that the
[110]
heuristic of the end node of the path so
[114]
that gives you an estimate of the total
[116]
cost of the path that you're looking at
[119]
so far. Let's see how this goes here. We
[122]
look at this it's not the goal state
[124]
so we're going to expand it we'll add it
[127]
to the visited list and we'll also store
[129]
it's A*
[132]
score so that we know it's A* score if
[134]
we find a better one than that and we
[136]
know that we need to visit it and this
[138]
can happen in the A* search
[140]
algorithm. Let's expand it so we can go
[145]
to A to B and to D for a cost of five, nine
[153]
and six. We have to take the heuristic
[156]
measure into account as well the
[159]
heuristic measure for A is seven so it
[162]
the algorithm thinks it's going to take
[165]
seven units of cost to get from A to the
[168]
goal state.
[168]
From B the heuristic measure is three
[172]
and from D the heuristic measure is six.
[176]
So the A* score is the cost of the
[180]
path so far ,so for this one that's
[183]
five plus the cost of the heuristic
[186]
measure so that's an estimate of how far
[189]
it's still to go to get to the goal
[191]
state and that gives you an estimate of
[194]
what the total cost of this path is
[197]
going to be once it's actually got down
[199]
to a goal state. So it's 12 here 9 plus 3
[203]
is 12 for this path as well and 6 plus 6
[208]
is also 12 for this part so at the
[211]
moment the A* search is not
[214]
distinguishing between these
[216]
possibilities it thinks that each of
[217]
these paths is going to cost 12 in the
[221]
end. So let's just take them in
[223]
alphabetical order as we did before
[224]
we'll look at this one first. From A we
[229]
can go to B or we can go to G1 so let's
[232]
put those up there B and G1 the
[238]
heuristic measure for B is 3 and the
[242]
heuristic measure for G1 is 0 because
[244]
it's a goal state and the heuristic
[247]
measure can understand that G1 is a
[250]
goal state and therefore it doesn't cost
[252]
any units in order to get to a goal
[255]
state from there. From A to B that's a
[259]
cost of 3, from A to G1 is a cost
[264]
of nine so we now calculate the A*
[269]
scores so the total cost of the path
[272]
along there here is eight, five plus
[275]
three, within add in the further three
[278]
here and that gets us to 11. So the total
[282]
estimated cost of that path is 11 the
[286]
eight plus another three. And for this
[289]
path it's five plus nine which is 14
[292]
plus the zero and that takes us to 14.
[295]
And we now mark A as visited and add it
[301]
to the visited list with an A* score
[303]
of 12. If later on in the search we find
[310]
a path to A that has an A* score
[314]
of less than 12 then we will look at
[317]
that. However if we find later on in the
[320]
algorithm a path to A with an A*
[323]
score of more than 12 then we can
[325]
completely ignore it and prune that part
[327]
of the search. Okay so we now continue
[331]
we've got four active paths in the tree
[334]
and the one with the best A* score
[337]
is this one here ending in node B. So
[342]
look at node B. From note B we can go to
[345]
a for a cost of two or you can go to C for
[350]
three. Now if we went to A for a cost of
[353]
two then the total A* score of the
[357]
path leading to A here would in fact be
[359]
twenty, thirteen plus seven,
[362]
so we've already visited it to 12 we
[365]
don't need to add it back to the tree.
[366]
But for the other node B to C we will
[370]
add that to the tree. So C has a
[373]
heuristic cost before that's the
[376]
estimate of how far it is to a goal
[378]
state and its cost of one to get there.
[382]
So it's now nine along that path plus
[386]
the four which makes it 13,
[390]
and that one has now been visited so B has now
[393]
been visited and it's A* score for
[396]
the visit was 11. We've now got four
[402]
paths in the tree one for 13 one for 14
[406]
and 2 for 12. So we're going to take one
[410]
of these two. We'll just take the first.
[413]
What B has already been visited for an
[416]
A* score of 11 over here so there's
[420]
no point in visiting it for an A* score
[422]
of 12 so that's a dead end.
[425]
Now look at D from D we can go back to S,
[431]
we can go to C and to E the route back
[435]
to S is not going to be visited because
[438]
we've already visited that for A*
[440]
score of 5. However we can add in C and
[446]
we can add in E the cost is 2 in each
[452]
case C has a heuristic value of 4 E has
[459]
a heuristic value of 5. Let's calculate
[461]
the A* scores. so it's 8 plus 4
[465]
that's 12 along that path and along this
[469]
path here it's 6 plus 2 that's 8, plus 5 which
[473]
brings us to 13 along this path. We now
[477]
add that to our visited list so D has
[481]
has been visited for an A* score of 12. Let's
[487]
look at the remaining active paths in the
[489]
tree. Well we've got this one for 13
[493]
this one for 14 here's one for 12 and
[498]
again C and here's one for 13 ending in
[501]
E so it's going to be this one that gets
[504]
explored next one ending in E for an
[506]
A* score of 12,
[508]
that's lining is C for an A* score of
[510]
12 rather so let's look where we can go
[513]
to from C. Well we can go back to S but
[516]
we're not going to do that because it's
[517]
A* score when we visit it was 5 and
[520]
it's going to be more if we visit this
[522]
time, but we can go to G2
[524]
and we can go to F so let's put those
[527]
into the tree.G2 that has a
[533]
heuristics cost of zero and the cost of the
[536]
arc is five and to F, F has a heuristic
[542]
score,
[543]
a heuristic estimate of six and the cost
[546]
of the arc is seven. So let's calculate
[551]
the new A* scores along these new
[553]
branches. So it's eight plus five plus
[557]
zero is 13. And 8 plus 7 is 15 15 and 6 is
[566]
21 for that branch there so that's our
[569]
most expensive branch so far. Good to see
[575]
a tick and add it to the visited list so
[577]
C has been visited for a cost of 12.
[582]
Let's look at the remaining branches.
[584]
Well we've got C here for an A* score of
[588]
13, G1 A* score 14 G2 for an A*
[594]
score 13, F for an A* score 21 and E
[600]
for 13. We're just going to we've got
[603]
three end in a 13 3 have score of 13 we're
[607]
just going to take them in alphabetical
[609]
order. So we'll visit this one for the C
[613]
for a score of 13 but we already visited
[617]
C for an A* score of 12 it's in there
[620]
so there's no point in expanding that
[622]
note that's a dead end.
[624]
Then we go to E for the next one E we can
[628]
go to G3 for a cost of 7, G3 here.
[639]
We calculate the A* score of this
[642]
new path so that six plus two is eight
[646]
plus seven is 15, 15 and zero is 15
[652]
for this branch E has now been visited
[655]
for an A* score of 13. And at this
[662]
point we've now got one, two, three, four
[667]
active branches 14, 13, 21, and 15 so this
[673]
is the best one we look at the node to
[675]
see if it's a goal state and it is so we
[679]
have now reached the goal and because
[682]
the heuristic that we used was an
[686]
admissible heuristic we know that this
[689]
path here is the optimal path through
[693]
the tree. Now I'll mark that for you in red
[696]
as before. What we noticed was that the
[703]
algorithm the A* algorithm here has
[706]
done a fair amount of work, it's visited
[708]
a fair number of nodes, and it expanded
[712]
quite a lot of the tree. The reason for
[715]
this is that the heuristic measure that
[719]
we used in the search space wasn't very
[722]
accurate. So for example the heuristic is
[725]
estimating that it costs 5 to get from S
[729]
to a goal state and we now know that the
[733]
actual cost is 13. So what I'm going to
[737]
ask you to do for the assignment is that
[739]
I'm going to ask you to run the search
[742]
the A* search again but I'm going to
[744]
give you more accurate measures for the
[747]
heuristics from each of the node to see
[749]
what difference that makes.
Most Recent Videos:
You can go back to the homepage right here: Homepage





