04 problem solving in ai - search algorithms
TRANSCRIPT
8/8/2019 04 Problem Solving in AI - Search Algorithms
http://slidepdf.com/reader/full/04-problem-solving-in-ai-search-algorithms 1/28
Problem Solving in AI: Search Algorithms
Most AI problem solving techniques areimplemented as a search for a solution
8/8/2019 04 Problem Solving in AI - Search Algorithms
http://slidepdf.com/reader/full/04-problem-solving-in-ai-search-algorithms 2/28
The nature of problem solving
Human problem solving involves searching for a solution
The solution is a structured object built, i.e. synthesised,
along the way
Three generic problem types are
State space transformation
Manipulate a current situation in an allowable way starting from
some initial position until a satisfactory end position is reached Transformation is achieved by bringing an operator to bear on the
current state
There is usually a choice of operators at each point
8/8/2019 04 Problem Solving in AI - Search Algorithms
http://slidepdf.com/reader/full/04-problem-solving-in-ai-search-algorithms 3/28
8/8/2019 04 Problem Solving in AI - Search Algorithms
http://slidepdf.com/reader/full/04-problem-solving-in-ai-search-algorithms 4/28
State space transformation
Uses the notion that each intermediate problemposition is a 'state of the world
The set of all possible positions is the state space
There are three ingredients in the statement of sucha problem:1. The set of initial states
2. The set of operators for moving from one state to another
3. The set of goal states or conditions that a state must satisfy to be agoal state
The problem is solved by finding a path, i.e. asequence from an initial state to a goal state
8/8/2019 04 Problem Solving in AI - Search Algorithms
http://slidepdf.com/reader/full/04-problem-solving-in-ai-search-algorithms 5/28
Search spaces, graphs and trees
A problem is represented as a graph with the nodes characterisingsituations and arcs (edges) indicating the permitted transformations
This is usually implicit since it is too vast to generate wholly
Arcs are usually directed (giving direction of permitted travel)
If there is a directed arc from a to b, then a is a predecessor or parent of b and b is a successor of a
Additionally they may be labelled (say with costs of traversal)
The average number of successors to a node is the branching factor
and is a key indicator in considering the computational complexity of thesearch
8/8/2019 04 Problem Solving in AI - Search Algorithms
http://slidepdf.com/reader/full/04-problem-solving-in-ai-search-algorithms 6/28
Search spaces, graphs and trees ctd A directed acyclic graph (DAG) is one containing no loops or cycles
An important type of DAG is a tree
This has a special node called the root
For each node (other than the root) there is one parent, i.e. there is a singlearc directed from the parent to the nod.
A node having no successor is called a leaf
The maximum distances in terms of arcs from the root to a leaf is the depth of the tree
As the search progresses an explicit graph (or more usually a tree) is
built - this is the search graph or search tree It can be used to keep track of the development of the solution
The 'solution' may require finding a path with particular properties(e.g. least cost)
8/8/2019 04 Problem Solving in AI - Search Algorithms
http://slidepdf.com/reader/full/04-problem-solving-in-ai-search-algorithms 7/28
A simple problem
Start: aGoal: f, j
Successors:
a p b, c b p d, ec p f, g d p h
e p i, j f p k
8/8/2019 04 Problem Solving in AI - Search Algorithms
http://slidepdf.com/reader/full/04-problem-solving-in-ai-search-algorithms 8/28
Search tree
b
g
a
d e
ih k
c
f
j
Goals at depth 2 and 3
Average branching factor < 2
8/8/2019 04 Problem Solving in AI - Search Algorithms
http://slidepdf.com/reader/full/04-problem-solving-in-ai-search-algorithms 9/28
A basic search algorithm
Specifying a search algorithm involves giving a recipe for
which successor nodes to try And, optionally, for recording what has already been tried
Examining the successors of a node is called expanding thenode
1. Set L, the open list, to be the list of start nodes
2. If L is empty, fail. Otherwise pick a node, n, from L
3. If n is a goal node, stop and return it together with the path from
the initial node to n
4. Otherwise remove n from L and add all of n's successors to L
labelling each with its path from the initial node Return to step 2.
8/8/2019 04 Problem Solving in AI - Search Algorithms
http://slidepdf.com/reader/full/04-problem-solving-in-ai-search-algorithms 10/28
Types of search
This general procedure does not specif y how a node is chosenfor expansion,
i.e. in what order such nodes are chosen This specification is all important leading to different actual
algorithms
Search can be blind or heuristic
A blind search method follows a fixed prescription regardless of the
particular characteristics of the problem This is unrealistic except for toy problems
A heuristic search method uses knowledge, in the form of heuristicsappropriate to the problem in hand, to guide search
thus narrowing the space actually covered
8/8/2019 04 Problem Solving in AI - Search Algorithms
http://slidepdf.com/reader/full/04-problem-solving-in-ai-search-algorithms 11/28
Blind search
Depth-first (with or without a depth bound)
Dive deep into the search tree
Nodes for expansion are selected from the front of L and successors to a node are also added to the front of L
Use of depth bound, M, prevents excessive pursuit of a goal tosubstantial depths when there may be a shallow goal on anotherbranch
Br eadth-first Move acr oss th e s ear ch tr ee th en down
Nodes for expa nsi on a r e s elect ed f r om th e f r ont of L and successors to a node are also added to the end of L
8/8/2019 04 Problem Solving in AI - Search Algorithms
http://slidepdf.com/reader/full/04-problem-solving-in-ai-search-algorithms 12/28
Example of depth-first search
b
g
a
d e
ih k
c
f
j
Nodes are visited in the order : a, b, d, h, e, i, j.
Solution path is : a, b, e, j
8/8/2019 04 Problem Solving in AI - Search Algorithms
http://slidepdf.com/reader/full/04-problem-solving-in-ai-search-algorithms 13/28
Example of breadth-first search
b
g
a
d e
ih k
c
f
j
Nodes are visited in the order : a, b, c, d, e, f
Solution path is : a, c, f
8/8/2019 04 Problem Solving in AI - Search Algorithms
http://slidepdf.com/reader/full/04-problem-solving-in-ai-search-algorithms 14/28
Complexit y of algorithms
Search algorithms have properties of
time complexit y
i.e. how long they take to complete the search memory (or space) complexit y,
i. e. how much storage space they need for intermediate results
Calculations are made in general or average terms as theact ual req uirements will differ from problem to problem
Complexities are specified in terms of parameters of theproblem, e.g. branching factor, using o notation (meaningorder of) o(x2) means complexit y varies as x2
8/8/2019 04 Problem Solving in AI - Search Algorithms
http://slidepdf.com/reader/full/04-problem-solving-in-ai-search-algorithms 15/28
Complexities for depth and breadth-first
Both have same time complexit y
exponential in depth
It is impossible to improve on this as a general result for any blind search algorithm
Memory req uirement for breadth-first is much worse again, exponential in depth
because alternative paths are stored
M e t o T im e M e m o r y
D e p t h i r s t~ ( )
2
d
d bo b
( 1) 1 ( )d b o d b
B r e a d t h i r s t (1 1 / ) ~ ( )2
d
d b
b o b 1 ( )d d b o b
8/8/2019 04 Problem Solving in AI - Search Algorithms
http://slidepdf.com/reader/full/04-problem-solving-in-ai-search-algorithms 16/28
Other blind search algorithmsDepth-limited
A variation on depth-first
A maximum depth parameter is specified for the search.
This acts a glass floor
when the max depth is reached, backtracking occurs and the searchmoves across instead of continuing down
Iterative deepening
A seq uence of depth-limited searches beginning with max depth =1 If the goal is not found the search is repeated with max depth =2 and
so on ...
Has the same complexit y as depth-first yet finds shallow nodes first like breadth-first
8/8/2019 04 Problem Solving in AI - Search Algorithms
http://slidepdf.com/reader/full/04-problem-solving-in-ai-search-algorithms 17/28
Avoiding loops in the search If a node has more than one parent then expansion may
lead to re-visiting of nodes alread y considered
making a loop or repetition in the path
Here it is usef ul to maintain another list to store the nodeswhich have been visited alread y
This is called the closed list
After a node has been expanded, it is placed in the closed list
A successor node is added to L (the open list) provided:
it is not in L alread y and it is not in the closed list
8/8/2019 04 Problem Solving in AI - Search Algorithms
http://slidepdf.com/reader/full/04-problem-solving-in-ai-search-algorithms 18/28
Sample problem:
missionaries and cannibals
T h ree missionaries and th ree cannibals are on one side of a river
Using a boat wh ich can h old at most tw o people th ey must all get t o
th e oth er side If th e missionaries are ever ou t numbered on one side of th e river
th ey w ill be eat en by cannibals
A st at e can be represent ed as:(Left, Boat-left, Right)
Left represents the people on the left bank,
Boat represents those on the boat and
Right those on the right
Each of Left, Boat and Right is a pair (M,C) where M is the number of missionaries and C the number of cannibals
Initial state: ( (3,3), (0,0)-left, (0,0) )
Goal state: ( (0,0), (0,0)-right, (3,3) )
8/8/2019 04 Problem Solving in AI - Search Algorithms
http://slidepdf.com/reader/full/04-problem-solving-in-ai-search-algorithms 19/28
Sample problem:
water containers
Given bot h a seven and a five litre container, initially empty, t h e goal is tofind a sequence of actions wh ich leaves four litres of liquid in t h e seven litrecontainer
T h ere are t h ree kinds of actions wh ich can alter t h e state of t h e containers:
i. A container can be filled
ii. A container can be emptied
iii. Liquid can be poured from one container into t h e ot h er, until t h e first isempty or t h e second is full
A state can be represented as:
(C1, C2) where C1 and C2 are the current volumes in the first (seven litre) and second (five litre) containers
Initial state is is (0, 0)
Goal state is (4, _) , i.e the volume of the second container is irrelevant
8/8/2019 04 Problem Solving in AI - Search Algorithms
http://slidepdf.com/reader/full/04-problem-solving-in-ai-search-algorithms 20/28
Heuristic search
A heuristic, h, is an inspired guess or rule-of thumb about where to go next in the search:
It is often a measure of distance from (or, closeness to) thegoal - called an evaluation f unction
It uses knowledge of the particular problem
Nodes not yet visited are evaluated using the
measure and the one with the best score is chosen Heuristics offer no guarantees
They are used because they tend to give betterresults
8/8/2019 04 Problem Solving in AI - Search Algorithms
http://slidepdf.com/reader/full/04-problem-solving-in-ai-search-algorithms 21/28
Types of heuristic search Hill climbing
From the current node choose (if possible) a successor node with the best evaluation and which improves upon that of the node itself
This is a local choice of best leading to a depth-first approach
B est-first Choose the best node globally to expand next from the open list
Depth and breadth first are special cases
Heuristic search will only improve on blind search if theheuristic contains real information about how near thegoal is. This will enable it to:
find a short, direct path to the goal and
find this path with little meandering along the way
8/8/2019 04 Problem Solving in AI - Search Algorithms
http://slidepdf.com/reader/full/04-problem-solving-in-ai-search-algorithms 22/28
Example of hill-climbing search
b
g
a
d e
ih k
c
f
j
Nodes are visited in the order : a, b, e, j
Solution path is : a, b, e, j
h =1.6
h = 0.7
h=0.8
h =1.8 h =0.9 h =2.7
h =0h =3.7h =4.9 h =6.2
h=0
8/8/2019 04 Problem Solving in AI - Search Algorithms
http://slidepdf.com/reader/full/04-problem-solving-in-ai-search-algorithms 23/28
Example of best first search
b
g
a
d e
ih k
c
f
j
Nodes are visited in the order : a, b, c, f
Solution path is : a, c, f
h=1.6
h=0.7
h=0.8
h=1.8 h=0.9 h=2.7
h=0h=3.7h=4.9 h=6.2
h=0
8/8/2019 04 Problem Solving in AI - Search Algorithms
http://slidepdf.com/reader/full/04-problem-solving-in-ai-search-algorithms 24/28
The A* algorithm
This is a version of best-first which applies to a specialclass of evaluation f unction: f(n)=g(n) + h'(n)
g(n) is the 'cost' incurred in reaching n Costs are attached to arcs of the graph
If a solution with shortest path length is req uired, arc cost = 1
g(n) is the act ual cost in reaching n
There may be a path (not found) to n with lower cost
Thus g(n) over-estimates the minimum cost
h'(n) is a heuristic that estimates the cost that will beincurred in reaching the goal from n
8/8/2019 04 Problem Solving in AI - Search Algorithms
http://slidepdf.com/reader/full/04-problem-solving-in-ai-search-algorithms 25/28
The A* algorithm ctd If the estimate h'(n) always under-estimates the true cost,
then h' is said to be admissible
In this case A* will always find a least cost path to thegoal assuming such a path exists
Ideally h'(n) should be a tight estimate Should be close to the true cost without going over
The tighter the estimate the more direct or focused the search willbe
there will be less meandering on the way
The h'(n) = true cost (as determined from arc costs, thensearches progresses directly to the goal
8/8/2019 04 Problem Solving in AI - Search Algorithms
http://slidepdf.com/reader/full/04-problem-solving-in-ai-search-algorithms 26/28
Example of A* search
b
g
a
d e
ih k
c
f
j
h=1.6
h=0.7
h=0.8
h=1.8 h=0.9 h=2.7
h=0h=3.7h=4.9 h=6.2
h=0
Cost per arc = 1
h values are admissible, e.g. at b, act ual cost of reaching goal (j) is 1+1=2 but h
is only 0.7. At b, f (b) =g (b) + h (b) = 1 + 0.7 =1.8
8/8/2019 04 Problem Solving in AI - Search Algorithms
http://slidepdf.com/reader/full/04-problem-solving-in-ai-search-algorithms 27/28
Sample problem:the 8-puzzle Req uires the eight numbered tiles in a 3*3 grid to be rearranged
(an example is shown below)
An individ ual move consists of a horizontal or vertical shift of a tileinto the space
Can generalise problem to n*n-1
2 1 6
4 8
7 5 3
1 2 3
8 4
7 6 5
8/8/2019 04 Problem Solving in AI - Search Algorithms
http://slidepdf.com/reader/full/04-problem-solving-in-ai-search-algorithms 28/28
Heuristic for the 8-puzzle
A good heuristic is provided by the total, over numbered tiles, of the Manhatten distance (md) of a tile from its final
positionmd = sum of horizontal and vertical distance to correct position
E.g. in diagram, tile number 6 has to travel distances of 1to the left and 2 dow n : md = 1+2
Can be improved by adding a seq uence misalignment factor A tile in the centre scores 1
A tile on a non-central sq uare scores 0 if it is follow ed the clockw isedirection by the correct tile in the goal configuration; else its score is 2