Uploaded by bjnzivu

Lesson 3.2 - Problem solving - Informed Search(6)

advertisement
INFORMED SEARCH
ALGORITHMS
ADVANCED SEARCH
• They find solutions more efficiently than can an
uninformed strategy. Several algorithms exists:
• Best-first search (Informed)
•
•
Greedy best-first search -heuristics
A* search – heuristics + cost
BEST-FIRST SEARCH – INFORMED
SEARCH
•
Here a node is selected for expansion based on an evaluation function, f(n).
The evaluation function is a cost and heuristic estimate, so the node with the
lowest evaluation is expanded first.
•
It is identical to that for uniform-cost search however the uniform cost uses
cost only (g-goal only).
•
The best-first algorithms include as a component of a heuristic
(help/way/information) function in addition to the cost hence is also known as
an informed search strategy. Heuristic functions provide additional
knowledge of the problem which is imparted to the search algorithm.
EXAMPLE - ROMANIA WITH STEP
COSTS IN KM
• In this example we store the cost as well as the direct distance shown alongside
INFORMED SEARCH ALGORITHMS
• Two ways to implement the Best First Search approach
1. greedy best-first search
2. A* search
GREEDY BEST-FIRST SEARCH
•
Greedy best-first search tries to expand the node that is closest to the goal,
on the grounds that this is likely to lead to a solution quickly.
•
This shows why the algorithm is called “greedy”—at each step it tries to get
as close to the goal as it can.
•
The first node to be expanded from Arad will be Sibiu because it is closer to
Bucharest than either Zerind or Timisoara. The next node will be Fagaras and
then Bucharest, which is the goal. In this case finds a solution. However it is
not optimal because the path through Rimnicu Vilcea and Pitesti is 32 KM
shorter.
•
It is also incomplete even in a finite state space. For example
getting from Iasi to Fagaras might mean that Neamt be
expanded first because it is closest to Fagaras - a dead end.
Additionally the algorithm will suggest going to Iasi once we
reach Neamt leading to an infinite loop.
•
The worst-case time and space complexity for the tree version
is O(bm),where m is the maximum depth of the search space.
•
With a good heuristic function, however, the complexity can be
reduced substantially.
PROPERTIES OF GREEDY BEST-FIRST
SEARCH
• Evaluation function f(n) = h(n)
• Complete? No – can get stuck in loops, e.g., Iasi  Neamt  Iasi 
Neamt  
• Time? O(bm), but a good heuristic can give dramatic improvement 
• Space? O(bm) -- keeps all nodes in memory 
• Optimal? No 
•
A* SEARCH
• Another way to evaluate the solution is add the sum of
the cost g(n) on a current path plus h(n), cost of the
straight path and then selecting the option that gives the
minimum total.
• Evaluation function f(n) = g(n) + h(n)
• Given a good heuristic h, A* is both complete and
optimal.
• Which path would A* recommend?
• f(n) = g(n) + h(n) where g(n) will include the previous g(n) if it exists
• To calculate:
Arad to Timisoara = 118+329=447 …X
Arad to sibiu = 140+253=393 …√
sibiu to Fagara= (140+99)+176 =239+176 = 415 …X
sibiu to Rimnicu Vilcea = (140+80)+193 =220+293 = 413 …√
• Notice in particular that Bucharest first
appears on the frontier (Neighbourhood)
at step (e), but the algorithm did not pick
it because Its f-cost is 450 which is higher
than that of Pitesti (417).
• The algorithm will not settle for a solution
that costs higher hence is more optimal
than the Greedy algorithm.
• Its important we select a good Heuristic
PROPERTIES OF A* SEARCH
• Complete? Yes (unless there are infinitely many nodes with f ≤ f(G) 
• Time? Exponential 
• Space? Keeps all nodes in memory 
• Optimal? Yes if we have good heuristics 
• The simplest way to reduce memory requirements for A∗ is to adapt
the idea of iterative deepening to the heuristic search context,
resulting in the iterative-deepening A∗
FINDING GOOD HEURISTICS
for the 8-sliding puzzle, two possible heuristics are:
h1(n) = number of misplaced tiles
h2(n) = no. of squares from desired location of each tile
• h1(S) = ? =8
• h2(S) = ? 3+1+2+2+2+3+3+2 = 18
• Experimental results show that it is generally better to use
a heuristic function with higher values, provided it is
consistent and that the computation time for the
heuristic is not too long.
CONDITIONS FOR OPTIMALITY:
• The ability of the A* algorithm to be optimal depends
largely on the heuristic selected. A good heuristic will
fulfil two conditions:
• Admissibility - never overestimates the cost (actual cost is more
than the heuristic)
• Consistency - value of the heuristic is always less than: the cost of
getting to a node’ + the heuristics of the node
ADMISSIBILITY
• An admissible heuristic is one that never overestimates the
cost to reach the goal i.e. doesn't give a value bigger
than the actual value. In this example our heuristic is
admissible because it is a Straight-line distance and in
real life this is the shortest path between any two points
so no overestimate.
Sibiu 99
Fagaras
253
140
Arad
211
366
Bucharest
Admissibility - 366<140+99+211
CONSISTENCY
• A consistent (or monotonicity) heuristic is one where the
value of the heuristic is less than the cost of getting to a
node’ plus the estimated cost of reaching the goal from the
node h(n) ≤ c(n,a,n’)+h(n’). In our example the heuristic for
Arad is 366. The cost of getting to Sibiu is 140. The
Heuristic for Sibiu is 253. Thus 366 ≤ 140+253(=393)
• This is a form of the general triangle inequality, which
stipulates that each side of a triangle cannot be longer
than the sum of the other two sides. If there were a route
from n to G via n’ that was cheaper than h(n), that would
violate the consistency property.
Sibiu 99
Fagaras
253
140
Arad
211
366
• Every consistent heuristic is also admissible therefore
Consistency is a stricter requirement than admissibility. In
our example the heuristic is a straight-line distance (Hence
h(n) is admissible) therefore the distance between n and G
is no greater than c(n,a,n')+h(n’). Hence, h(n) is a consistent
heuristic.
Bucharest
Admissibility - 366<140+99+211
Consistency - 366<140+253
CALCULATING MANHATTAN DISTANCE
• For path finding problems such as a maze we can derive
heuristics from "Manhattan distance" from the Goal.
• This is the direct distance between two points if you were
only allowed to walk on paths that were at 90-degree
angles (up-down-left-right) from each other (similar to
walking the streets of Manhattan) hence the name.
Manhattan=2+2=4
Euclidean=√(22+22)=2.83
USING MANHATTAN DISTANCE
• Mathematically, the Manhattan distance is the Absolute value of:
(cellx - exitx) + (celly - exity)
• For example if my current status is 1 and the Goal is 3 I need to decide
whether to go to 2 or 4
• The Manhattan distance from 2 is mod[(2-3)+(3-3)]=1 while from 4 is
mod[(1-3)+(2-3)]=3 therefore traveling from 1 the greedy search algorithm
would suggest go to 2 rather than 4.
4
3
2
1
0
1
2
3
4
USING EUCLIDEAN DISTANCE
• The Euclidean Distance can also be used instead of the Manhattan Distance
because it is slightly more accurate however its a little more complex to write
so we shall use the simpler option for now. It finds the straight line using
Pythagoreans theorem.
4
3
2
1
0
1
2
3
4
DEFINE THE ENVIRONMENT
4
3
2
1
0
1
2
3
4
DEFINE THE ENVIRONMENT
4
3
2
1
0
1
2
3
4
IMPLEMENTING AGENTS FOR GBFS & A*
• Try and run it for Different Starts and Goals e.g. 1 to 9
• Manually calculate the expected outcome of GBFS and
A* to validate the algorithm
Exercise:
Try and use the Euclidean distance.
EXERCISE
• Write a program to find the best path based on heuristics
derived from the Manhattan distance
• Prove that the heuristics are optimal
ASSIGNMENT
• Create heuristics for the surveillance robot below that
enable it to factor in the distance when trying to save the
battery. Prove that your selected heuristics are optimal.
Download