610 likes | 820 Views
Search I: Uninformed Search Strategies (final revision) AIMA Chapter 3. Intro to A.I. CIS 391 Fall 2008. Outline (3-4 lectures). Problem-solving agents A kind of goal-based agent Problem formulation Example problems Tree Search Basics Basic uninformed search algorithms
E N D
Search I: Uninformed Search Strategies(final revision)AIMA Chapter 3 Intro to A.I. CIS 391 Fall 2008
Outline (3-4 lectures) • Problem-solving agents • A kind of goal-based agent • Problem formulation • Example problems • Tree Search Basics • Basic uninformed search algorithms • Breadth-first search • Depth-first Search • Iterative-deepening Search • Step-cost functions & Uniform-cost search CIS 391 - Intro to AI 2
Simple Problem Solving Agents • Assumes Environment is • Static • Fully Observable • Deterministic • Usually: Discrete CIS 391 - Intro to AI 4
Review: Relevant Environment Types • Static(vs. dynamic): The environment is unchanged while an agent is deliberating. • Fully observable (vs. partially observable): An agent's sensors give it access to the complete state of the environment at each point in time. • Discrete (vs. continuous): A limited number of distinct, clearly defined percepts and actions. • Deterministic (vs. stochastic): The next state of the environment is completely determined by the current state and the action executed by the agent. CIS 391 - Intro to AI 5
Example: Holiday in Romania You are here You need to be here CIS 391 - Intro to AI 6
Example: Holiday in Romania • 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, … CIS 391 - Intro to AI 7
Problem formulation • A problem is defined by: • An initial state, e.g. Arad • Successor function S(X)= set of action-state pairs • e.g. S(Arad)={<Arad Zerind, Zerind>,…} • initial state + successor function* = state space • Goal test, can be • Explicit, e.g. x=‘at bucharest’ • Implicit, e.g. checkmate(x) • Path cost (additive) • e.g. sum of distances, number of actions executed, … • c(x,a,y) is the step cost, assumed to be >= 0 • (where action a takes one from state x to state y) A solution is a sequence of actions from initial to goal state. Optimal solution has the lowest path cost. CIS 391 - Intro to AI 8
Selecting a state space • Real world is absurdly complex State space must be abstracted for problem solving • (abstract) State = set (equivalence class) of real/abstract states • (abstract) Action = complex combination of real/abstract actions • e.g. Arad Zerind represents a complex set of possible routes, detours, rest stops, etc • The abstraction is valid if the path between two states is reflected in the real world • (abstract) Solution = set of real/abstract paths that are solutions in the real/abstract world • Each abstract action should be “easier” than the real problem CIS 391 - Intro to AI 9
aab S1 Action: (change a to b) aaa bbb abb Start Goal S2 CIS 391 - Intro to AI 10
Formulating a Search Problem Decide: • Which properties matter & how to represent • Initial State, Goal State, Possible Intermediate States • Which actions are possible & how to represent • Operator Set • Which action is next • Path Cost Function CIS 391 - Intro to AI 11
Example: 8-puzzle • States?? • Initial state?? • Actions?? • Goal test?? • Path cost?? CIS 391 - Intro to AI 12
Example: 8-puzzle • States?? Integer location of each tile • Initial state?? Any state can be initial • Actions?? {Left, Right, Up, Down} • Goal test?? Check if goal configuration is reached • Path cost?? Number of actions to reach goal CIS 391 - Intro to AI 13
Example: Missionaries & Cannibals Three missionaries and three cannibals come to a river. A rowboat that seats two is available. If the cannibals ever outnumber the missionaries on either bank of the river, the missionaries will be eaten. How shall they cross the river? CIS 391 - Intro to AI 14
Formulation: Missionaries & Cannibals • How to formalize: • Initial state: all M, all C, and boat on one bank • Goal test: True if all M, all C, and boat on other bank • Operators: ?? • Cost: ?? Remember: • Representation: • States: Which properties matter & how to represent • Operators: Which actions are possible & how to represent • Path Cost: Deciding which action is next CIS 391 - Intro to AI 15
Missionaries and Cannibals States: (CL, ML, BL) Initial 331 Goal 000 Operators: Travel Across Travel Back -101 101 -201 201 -011 011 -021 021 -111 111 CIS 391 - Intro to AI 16
Important Definitions • State space: the set of all states reachable from the initial state by any sequence of actions • when several operators can apply to each state, this gets large very quickly. • Path: a sequence of actions leading from one state sj to another state sk • Frontier:those states that are available for the application of operators/actions • Solution: a path from the initial state (si) to a state sf that satisfies the goal test CIS 391 - Intro to AI 17
Basic search algorithms: Tree Search • How do we find the solutions for the previous problem formulations? • Search the state space (remember complexity of space depends on state representation) • Here: search through explicit tree generation • ROOT= initial state. • Nodes and leafs generated through successor function. • In general search generates a graph (same state through multiple paths), but we’ll just look at trees • Treats different paths to the same node as distinct CIS 391 - Intro to AI 18
Simple tree search example function TREE-SEARCH(problem, strategy) return a solution or failure Initialize search tree to the initial state of the problem do if no candidates for expansion thenreturnfailure choose leaf node for expansion according to strategy if node contains goal state thenreturnsolution else expand the node and add resulting nodes to the search tree enddo CIS 391 - Intro to AI 19
Simple tree search example function TREE-SEARCH(problem, strategy) return a solution or failure Initialize search tree to the initial state of the problem do if no candidates for expansion thenreturnfailure choose leaf node for expansion according to strategy if node contains goal state thenreturnsolution else expand the node and add resulting nodes to the search tree enddo CIS 391 - Intro to AI 20
Simple tree search example function TREE-SEARCH(problem, strategy) return a solution or failure Initialize search tree to the initial state of the problem do if no candidates for expansion thenreturnfailure choose leaf node for expansion according to strategy if node contains goal state thenreturnsolution else expand the node and add resulting nodes to the search tree enddo • Determines search process!! CIS 391 - Intro to AI 21
8-Puzzle: States and Nodes • A state is a (representation of a) physical configuration • A node is a data structure constituting part of a search tree • Also includes parent, children, depth, path cost g(x) • Here node= <state, parent-node, action, path-cost, depth> • States do not have parents, children, depth or path cost! • The EXPAND function • creates new nodes, • fills in the various fields • uses the OPERATORS (or SUCCESSOR-FN) of the problem to create the corresponding states Node State parent Action= Up Cost = 6 Depth = 6 state children CIS 391 - Intro to AI 22
8-Puzzle Search Tree • Leaving Action, Cost, Depth Implicit • Ignoring “backwards” moves (Ignoring “backwards” moves) CIS 391 - Intro to AI 23
Tree search algorithm function TREE-SEARCH(problem,fringe) return 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) • fringe: generated nodes which are not yet expanded • Initially an empty queue, with operations insert, insert-all, remove-first , … & predicates empty?, … • The search strategy is implemented in the details of insert-all, in where new items are inserted into the queue CIS 391 - Intro to AI 24
Tree search algorithm (2) function EXPAND(node,problem) return 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 successors returnsuccessors CIS 391 - Intro to AI 25
Search Strategies • Strategy = order of expansion • Dimensions for evaluation • Completeness- always find the solution? • Time complexity - # of nodes generated • Space complexity - # of nodes in memory • Optimality - finds a least cost solution? • Time/space complexity measurements • b,maximum branching factor of search tree • d,depth of the least cost solution • m, maximum depth of the state space (potentially ) CIS 391 - Intro to AI 26
Uninformed search strategies • (a.k.a. blind search) = use only information available in problem definition. • When strategies can determine whether one non-goal state is better than another informed search. • Categories defined by expansion algorithm: • Breadth-first search • Depth-first search • (Depth-limited search) • Iterative deepening search • Uniform-cost search • Bidirectional search CIS 391 - Intro to AI 28
Breadth-first search • Idea: • Expand shallowest unexpanded node • Implementation: • Fringe is FIFO (First-In-First-Out) Queue: • Put successors at the end of fringe successor list. CIS 391 - Intro to AI 29
2 8 3 1 6 4 7 5 2 8 3 1 4 7 6 5 2 8 3 1 6 4 7 5 2 8 3 1 6 7 5 4 2 8 3 1 4 7 6 5 2 8 3 6 4 1 7 5 2 3 1 8 4 7 6 5 2 8 3 1 4 7 6 5 Breadth-first Search 2 8 3 1 6 4 7 5 1 • Expand shallowestunexpanded node • Implementation: fringe is a FIFO queue 2 3 4 9 8 5 7 6 CIS 391 - Intro to AI 30
Review: Tree search algorithm function TREE-SEARCH(problem,fringe) return 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) Test immediately after removing from queue Position within queue of new items determines search strategy Nodes inserted into queue without testing to see if they are goal states CIS 391 - Intro to AI 31
Properties of breadth-first search • Complete? • Time? • Space? • Optimal? CIS 391 - Intro to AI 32
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 = 1 per step) (not optimal in general) b: maximum branching factor of search tree d: depth of the least cost solution m: maximum depth of the state space () CIS 391 - Intro to AI 33
Exp Space worse than Exp Time… • Two lessons: • Memory requirements are a bigger problem than execution time. • Exponential complexity search problems cannot be solved by uninformed search methods for any but the smallest instances. Fig 3.11 Assumes b=10, 10Knodes/sec, 1K bytes/nodes CIS 391 - Intro to AI 34
Depth-first search • Idea: • Expand deepest unexpanded node • Implementation: • Fringe is LIFO (Last-In-First-Out) Queue: • Put successors at the front of fringe successor list. CIS 391 - Intro to AI 36
Uninformed search strategies • Categories defined by expansion algorithm: • Breadth-first search: FIFO queue • Depth-first search: LIFO queue • (Depth-limited search) • Iterative deepening search • Uniform-cost search • Bidirectional search CIS 391 - Intro to AI 37
2 8 3 1 6 4 7 5 2 8 3 1 4 7 6 5 2 8 3 1 6 4 7 5 2 8 3 1 6 7 5 4 2 8 3 1 4 7 6 5 2 8 3 6 4 1 7 5 2 3 1 8 4 7 6 5 2 8 3 1 4 7 6 5 Depth-first Search 2 8 3 1 6 4 7 5 1 • Expand deepestunexpanded node • Implementation: fringe is a LIFO queue 8 2 4 9 7 3 6 5 CIS 391 - Intro to AI 38
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 b: maximum branching factor of search tree d: depth of the least cost solution m: maximum depth of the state space () CIS 391 - Intro to AI 39
Depth-first vs Breadth-first • Use depth-first if • Space is restricted • There are many possible solutions with long paths and wrong paths can be detected quickly • Search can be fine-tuned quickly • Use breadth-first if • Possible infinite paths • Some solutions have short paths • Can quickly discard unlikely paths CIS 391 - Intro to AI 40
Search Conundrum • Breadth-first • Complete • uses O(bd+1) space • Depth-first • Not complete unless m is bounded • Uses O(bm) time; terrible if m >> d • butonly uses O(bm) space How can we get the best of both? CIS 391 - Intro to AI 42
Depth-limited search: A building block • Depth-First search but with depth limit l. • i.e. nodes at depth l have no successors. • Solves the infinite-path problem. • If l = d (by luck!), then optimal • But: • If l < d then incompleteness results. • If l > d then not optimal. • Time complexity: • Space complexity: CIS 391 - Intro to AI 43
Iterative deepening search • A general strategy to find best depth limit l. • Key idea: use Depth-limited search as subroutine, with increasing l . • Complete: Goal is always found at depth d, the depth of the shallowest goal-node. • Combines benefits of DF-search & BF-search CIS 391 - Intro to AI 44
Iterative Deepening Search For d = 0 to do depth-limited-search to level d if it succeeds then return solution (for details see full algorithm in AIMA pp 77-79) Could this possibly be efficient? Corrected! CIS 391 - Intro to AI 45
ID-search, example • Limit=0 CIS 391 - Intro to AI 46
ID-search, example • Limit=1 CIS 391 - Intro to AI 47
ID-search, example • Limit=2 CIS 391 - Intro to AI 48
ID-search, example • Limit=3 CIS 391 - Intro to AI 49
ID search, Evaluation I: Complete? • Complete: YES (no infinite paths) CIS 391 - Intro to AI 50