search search plays a key role in many parts of ai. these algorithms provide the conceptual backbone...

60
Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration of alternatives . There are four classes of search algorithms, which differ along two dimensions: First, is the difference between uninformed (also known as blind) search and then informed (also known as heuristic) searches. • Informed searches have access to task-specific information that can be used to make the search process more efficient. The other difference is between any solution searches and optimal searches. • Optimal searches are looking for the best possible solution while any-path searches will just settle for finding some solution.

Upload: dominic-watkins

Post on 26-Mar-2015

219 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Search• Search plays a key role in many parts of AI. These algorithms

provide the conceptual backbone of almost every approach to the systematic exploration of alternatives.

• There are four classes of search algorithms, which differ along two dimensions: – First, is the difference between uninformed (also known as blind)

search and then informed (also known as heuristic) searches. • Informed searches have access to task-specific information that can be

used to make the search process more efficient.

– The other difference is between any solution searches and optimal searches.

• Optimal searches are looking for the best possible solution while any-path searches will just settle for finding some solution.

Page 2: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Graphs• Graphs are everywhere; E.g., think about road networks or

airline routes or computer networks.

• In all of these cases we might be interested in finding a path through the graph that satisfies some property.

• It may be that any path will do or we may be interested in a path having the fewest "hops" or a least cost path assuming the hops are not all equivalent.

Page 3: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Romania graph

Page 4: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Formulating the problem• On holiday in Romania; currently in Arad.

• Flight leaves tomorrow from Bucharest.

• Formulate goal:– be in Bucharest

• Formulate problem:– states: various cities

– actions: drive between cities

• Find solution:– sequence of cities, e.g., Arad, Sibiu, Fagaras, Bucharest

Page 5: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Another graph example• However, graphs can also be much more abstract.

• A path through such a graph (from a start node to a goal node) is a "plan of action" to achieve some desired goal state from some known starting state.

• It is this type of graph that is of more general interest in AI.

Page 6: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Problem solving• One general approach to problem solving in AI is to reduce the

problem to be solved to one of searching a graph.

• To use this approach, we must specify what are the states, the actions and the goal test.

• A state is supposed to be complete, that is, to represent all the relevant aspects of the problem to be solved.

• We are assuming that the actions are deterministic, that is, we know exactly the state after the action is performed.

Page 7: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Goal test• In general, we need a test for the goal, not just one specific goal

state. – So, for example, we might be interested in any city in Germany

rather than specifically Frankfurt.

• Or, when proving a theorem, all we care is about knowing one fact in our current data base of facts. – Any final set of facts that contains the desired fact is a proof.

Page 8: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Vacuum cleaner?

Page 9: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Vacuum cleaner

Page 10: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Vacuum cleaner

Page 11: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Formally…A problem is defined by four items:

1. initial state e.g., "at Arad"2. actions and successor function S: = set of action-state tuples

– e.g., S(Arad) = {(goZerind, Zerind), (goTimisoara, Timisoara), (goSilbiu,

Silbiu)}3. goal test, can be

– explicit, e.g., x = "at Bucharest"– implicit, e.g., Checkmate(x)

4. path cost (additive)– e.g., sum of distances, or number of actions executed, etc.– c(x,a,y) is the step cost, assumed to be ≥ 0

• A solution is a sequence of actions leading from the initial state to a goal state

Page 12: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Example: The 8-puzzle

• states?

• actions?

• goal test?

• path cost?

Page 13: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Example: The 8-puzzle

• states? locations of tiles • actions? move blank left, right, up, down • goal test? = goal state (given)• path cost? 1 per move

Page 14: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Romania graph

Page 15: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Tree search example

Page 16: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Tree search example

Page 17: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Tree search example

Page 18: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Tree search algorithms

• Basic idea:– Exploration of state space by generating successors of already-explored

states (i.e. expanding states)

Page 19: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

(

Page 20: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Data type node:Data type node:

components : STATE , PARENT_NODE , OPERATOR , components : STATE , PARENT_NODE , OPERATOR , DEPTH , PATH_COSTDEPTH , PATH_COST

Page 21: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

FunctionFunction GENERAL-SEARCH ( problem ,QUEUING_FN )GENERAL-SEARCH ( problem ,QUEUING_FN ) returnsreturns a solution or failurea solution or failure

nodes nodes MAKE_QUEUE (MAKE_NODE (INITIAL_STATE MAKE_QUEUE (MAKE_NODE (INITIAL_STATE [problem ] ))[problem ] ))

LoopLoop dodo ifif nodes is empty nodes is empty thenthen returnreturn failure failure node node REMOVE_FRONT (nodes ) REMOVE_FRONT (nodes ) ifif GOAL_TEST [problem ] applied to STATE ( node ) succeeds GOAL_TEST [problem ] applied to STATE ( node ) succeeds thenthen returnreturn node node

nodes nodes QUEUING_FN (nodes , EXPAND (node ,OPERATORS QUEUING_FN (nodes , EXPAND (node ,OPERATORS [problem ] ))[problem ] ))

EndEnd

Page 22: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Function SIMPLE-PROBLEM-SOLVING-AGENT(percept) returns an action

Inputs: percept , a perceptStatic: seq , an action sequence , initially empty state , some description of the current world state goal , a goal , initially null problem , a problem formulationState ← UPDATE-STATE(state,percept)If seq is empty then do goal ← FORMULATE-GOAL(state) problem ← FORMULATE-PROBLEM(state,goal) seq ← SEARCH(problem)action ← FIRST(seq)seq ← REST(seq)Return action

Page 23: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Function Tree-Search(problem,fringe) returns a solution, or failure fringe←Insert(MAKE-NODE(INITIAL-STATE[problem]),fringe) loop do if Empty?(fringe) then return failure node ← REMOVE-FIRST(fringe) if GOAL-TEST[problem] applied to STATE[node] succeeds then return SOLUTION(node) fringe ← INSERT-ALL(EXPAND(node,problem),fringe)

Function EXPAND(node,problem) returns a set of nodes successors ← the empty set For each(action,result)in SUCCESSOR-FN[problem](STATE[node]) do s ← a new node STATE[s] ← result PARENT-NODE[s] ← node ACTION[s] ← action PATH-COST[s] ← PATH-COST[node]+STEP-COST(node,action,s) DEPTH[s] ← DEPTH[node]+1 add s to successorsreturn successors

Page 24: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Search strategies• A search strategy is defined by picking the order of node

expansion

• Strategies are evaluated along the following dimensions:– completeness: does it always find a solution if one exists?– time complexity: number of nodes generated– space complexity: maximum number of nodes in memory– optimality: does it always find a least-cost solution?

• Time and space complexity are measured in terms of – b: maximum branching factor of the search tree– d: depth of the least-cost solution– m: maximum depth of the state space

Page 25: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Uninformed search strategies• Uninformed do not use information relevant to the specific

problem.

• Breadth-first search

• Uniform-cost search

• Depth-first search

• Depth-limited search

• Iterative deepening search

• Bidirectional search

Page 26: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

• Function BREADTH_FIRST_SEARCH ( problem ) return a solution or failure

• return GENERAL_SEARCH (problem ,ENQUEUE_AT_END

Page 27: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Breadth-first search• TreeSearch(problem, FIFO-QUEUE()) results in a breadth-first

search.

• The FIFO queue puts all newly generated successors at the end of the queue, which means that shallow nodes are expanded before deeper nodes. – I.e. Pick from the fringe to expand the shallowest unexpanded node

Page 28: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Breadth-first search• Expand shallowest unexpanded node

• Implementation:

– fringe is a FIFO queue, i.e., new successors go at end

Page 29: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Breadth-first search• Expand shallowest unexpanded node

• Implementation:– fringe is a FIFO queue, i.e., new successors go at end

Page 30: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Breadth-first search• Expand shallowest unexpanded node

• Implementation:– fringe is a FIFO queue, i.e., new successors go at end

Page 31: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Properties of breadth-first search• Complete?

– Yes (if b is finite)• Time?

– 1+b+b2+b3+… +bd + b(bd-1) = O(bd+1)• Space?

– O(bd+1) (keeps every node in memory)• Optimal?

– Yes (if cost is a non-decreasing function of depth, e.g. when we have 1 cost per step)

Page 32: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Depth Nodes Time Memory

0 1 1 millisecodns 100 bytes

2 111 .1 sec 11 kilobytes

4 11,111 11 sec 1 Megabyte

6 106 18 min 111 Megabyte

8 108 31 hours 11Gigabyte

10 1010 128 days 1 Terabyte

12 1012 35 years 111 Terabyte

14 1014 3500 years 11111 Terabyte

Suppose b=10, 1000 nodes/sec, 100 bytes/node

Page 33: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Uniform-cost search• Expand least-cost unexpanded node. • The algorithm expands nodes in order of increasing path cost. • Therefore, the first goal node selected for expansion is the optimal solution.

• Implementation:

– fringe = queue ordered by path cost (priority queue)• Equivalent to breadth-first if step costs all equal

• Complete? Yes, if step cost ≥ ε (I.e. not zero)

• Time? number of nodes with g ≤ cost of optimal solution, O(bC*/ ε) where C* is the cost of the optimal solution

• Space? Number of nodes with g ≤ cost of optimal solution, O(bC*/ ε)

• Optimal? Yes – nodes expanded in increasing order of g(n)

Page 34: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration
Page 35: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Depth-first search• Expand deepest unexpanded node

• Implementation:

– fringe = LIFO queue, i.e., put successors at front

Page 36: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Depth-first search• Expand deepest unexpanded node

• Implementation:

– fringe = LIFO queue, i.e., put successors at front

Page 37: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Depth-first search• Expand deepest unexpanded node

• Implementation:

– fringe = LIFO queue, i.e., put successors at front

Page 38: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Depth-first search• Expand deepest unexpanded node

• Implementation:

– fringe = LIFO queue, i.e., put successors at front

Page 39: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Depth-first search• Expand deepest unexpanded node

• Implementation:

– fringe = LIFO queue, i.e., put successors at front

Page 40: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Depth-first search• Expand deepest unexpanded node

• Implementation:

– fringe = LIFO queue, i.e., put successors at front

Page 41: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Depth-first search• Expand deepest unexpanded node

• Implementation:

– fringe = LIFO queue, i.e., put successors at front

Page 42: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Depth-first search• Expand deepest unexpanded node

• Implementation:

– fringe = LIFO queue, i.e., put successors at front

Page 43: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Depth-first search• Expand deepest unexpanded node

• Implementation:

– fringe = LIFO queue, i.e., put successors at front

Page 44: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Depth-first search• Expand deepest unexpanded node

• Implementation:

– fringe = LIFO queue, i.e., put successors at front

Page 45: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Depth-first search• Expand deepest unexpanded node

• Implementation:

– fringe = LIFO queue, i.e., put successors at front

Page 46: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Depth-first search• Expand deepest unexpanded node

• Implementation:

– fringe = LIFO queue, i.e., put successors at front

Page 47: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Properties of depth-first search• Complete? No: fails in infinite-depth spaces, spaces with loops

– Modify to avoid repeated states along path complete in finite spaces

• Time? O(bm): terrible if m is much larger than d– but if solutions are dense, may be much faster than breadth-first

• Space? O(bm), i.e., linear space!

• Optimal? No

Page 48: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Function DEPTH_FIRST_SEARCH ( problem ) return a solution or failure

return GENERAL_SEARCH (problem ,ENQUEUE_AT_FRONT )

DEPTH_FIRST_SEARCH1.List s2.if List = null then fail , stop 3.n First (List)4.if n = GOAL then success , stop5. ListTail ( List )6. ClistExpand( n )7. ListAppend (Clist , List )8. Goto 2

Nilsson Algorithm

Page 49: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

DepthLimitedSearch (int limit) {

stackADT fringe;insert root into the fringedo {

if (Empty(fringe)) return NULL; /* Failure */

nodePT = Pop(fringe);if (GoalTest(nodePT->state))

return nodePT;

/* Expand node and insert all the successors */ if (nodePT->depth < limit) insert into the fringe Expand(nodePT)

} while (1);}

Depth-limited search

Page 50: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Iterative deepening Search

Function ITERATIVE_DEEPING_SEARCH( problem ) returns a solution sequence or failure

inputs: problem , a problem for depth ← 0 to ∞ do if DEPTH_LIMITED_SEARCH ( problem , depth ) succeeds

then return its result end return failure

Page 51: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Iterative deepening search l =0

Page 52: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Iterative deepening search l =1

Page 53: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Iterative deepening search l =2

Page 54: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Iterative deepening search l =3

Page 55: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Iterative deepening search• Number of nodes generated in a breadth-first search to depth d

with branching factor b: NBFS = b0 + b1 + b2 + … + bd-2 + bd-1 + bd

• Number of nodes generated in an iterative deepening search to depth d with branching factor b:

NIDS = (d+1)b0 + d b1 + (d-1)b2 + … + 3bd-2 +2bd-1 + 1bd

• For b = 10, d = 5,– NBFS = 1 + 10 + 100 + 1,000 + 10,000 + 100,000 = 111,111– NIDS = 6 + 50 + 400 + 3,000 + 20,000 + 100,000 = 123,456

• Overhead = (123,456 - 111,111)/111,111 = 11%–

Page 56: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Properties of iterative deepening search

• Complete? Yes

• Time? (d+1)b0 + d b1 + (d-1)b2 + … + bd = O(bd)

• Space? O(bd)

• Optimal? Yes, if step cost = 1

Page 57: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Which Direction Should We Search?

Our choices: Forward, backwards, or bidirectional

The issues: How many start and goal states are there?Branching factors in each directionHow much work is it to compare states?

Page 58: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Summary of algorithms

Criterion

Breadth-First

Uniform-

Cost

Depth-

First

Depth-

Limited

IterativeDeepening

Bidirectional

(if applicable)

Complete? Yes Yes No

Yes,

If l d Yes Yes

Time bd bd bm

bl bd bd/2

Space bd bd bm bl bd bd/2

Optimal? Yes Yes No No Yes Yes

Page 59: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Repeated states• Failure to detect repeated states can turn a linear problem into an

exponential one!

Page 60: Search Search plays a key role in many parts of AI. These algorithms provide the conceptual backbone of almost every approach to the systematic exploration

Graph search