# Search

## Search

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
##### Presentation Transcript

1. Search Introduction to Artificial Intelligence CS440/ECE448 Lecture 3

2. This lecture • Uninformed search • Breadth-first search • Uniform-cost search • Depth-first search • Depth-limited search • Iterative deepening search • Informed search • Best-first search • Greedy search • A* Reading • Chapters 3 and 4

3. Problem Solving • World state – values of all attributes of interest in the world. • State space – the set of all possible world states. • Operators – change one state into another; cost of applying operator. • Goal– an (often partial) world state or states; in an agent, often implemented as a function of state and current percept. • Initial state – the values of attributes that are in effect at the beginning of a problem before any operators have been applied. • Solution (path) – a sequence of operators leading from the initial state to a goal state. • Path cost – e.g., sum of distances, number of operators executed, …

4. 2 8 3 1 2 3 1 6 4 8 4 7 5 7 6 5 Start Goal Example: The 8-puzzle • States: • Operators: • Goal Test: • Path Cost: Integer location of tiles (ignore intermediate positions) Move blank left, right, up, down (preconditions, effects) = goal state (given) 1 per move

5. The state space

6. Implementation of Search Algorithms Nodes: state, parent-node,operator, depth, path cost Function GENERAL-SEARCH (problem, queing-fn) returns a solution or failure queue MAKE-QUEUE (MAKE-NODE(INITIAL-STATE[problem])) loop do ifqueueis empty, then return failure node Remove-Front(queue) if GOAL-TEST [problem] applied to STATE(node) succeeds then return node else queueQUEING-FN(queue,EXPAND(node,operators[problem])) end

7. States vs. nodes • A state is a (representation of a) physical configuration. • A node is a data structure constituting part of a search tree includes parent, children, depth, path costg(n). • States do not have parents, children, depth, or path cost!

8. Search Strategies A 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? • optimality– does it always find a least-cost solution? • time complexity– number of nodes generated/expanded • space complexity– maximum number of nodes in memory 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 (may be infinite)

10. Properties of Breadth-first Search Yes (if b is finite) Yes (if cost = 1 per step); not in general 1 + b + b2 + b3 + b4 + … + bd = O(bd) O(bd) -- Keeps every node in memory • Complete: • Optimal: • Time: • Space: Let b: Branching factor d: Solution depth m: Maximum depth

11. Romania with Edge Costs

12. Zerind Sibiu Timisoara 118 75 140 140 118 75 75 111 71 118 Arad Oradea Arad Lugoj 150 146 236 229 Uniform-cost Search (Dijkstra, 1959) • Let g(n) be path cost of node n. • Expand least-cost unexpanded node • Implementation: QueueingFn = Keep Q sorted in increasing path length order Arad

13. Properties of Uniform-Cost Search • Complete: • Optimal: • Time: • Space: Yes if arc costs bounded below by  > 0. Yes # of nodes with g(n)  cost of optimal solution # of nodes with g(n)  cost of optimal solution Note: Breadth first is equivalent to Uniform-Cost Search with edge cost equal a constant.

14. Zerind Sibiu Timisoara Arad Oradea Timisoara Zerind Sibiu Depth-First Search • Expand deepest unexpanded node • Implementation QueueingFn = insert successors at front of queue Arad Note: Depth-first search can perform infinite cycle excursions. Need a finite, non-cyclic search space or repeated-state checking.

15. Properties of Depth-First Search Complete: Optimal: Time: Space: No: Fails in infinite-depth spaces, spaces with loops. Modify to avoid repeated states on path  Complete in finite spaces No. O(bm): terrible if m is much larger than d. but if solutions are dense may be much faster than breadth first. O(bm) i.e. linear in depth. Let b: Branching factor m: Maximum Depth

16. Explicit graphs: e.g. road maps Finite number of states Implicit graphs: e.g. problem solving. Graph is usually constructed on the fly starting from initial state and applying operators to find connected states. Possibly infinite number of states Search spaces are usually graphs

17. Repeated States To avoid repeating states already expanded, consider the following three techniques: • Do not add to queue parent of current node. • Check that state associated with child is not on path from current node to root. • Check that state has never been visited before (closed list)

18. Implementation of Search Algorithms Function GENERAL-SEARCH (problem, queing-fn) returns a solution or failure queue MAKE-QUEUE (MAKE-NODE(INITIAL-STATE[problem])) loop do ifqueueis empty, then return failure node Remove-Front(queue) if GOAL-TEST [problem] applied to STATE(node) succeeds then return node ifSTATE(node) is not in closed then add STATE(node) to closed; queueQUEING-FN(queue,EXPAND(node,operators[problem])) end

19. Zerind Sibiu Timisoara Oradea Sibiu Fagaras Rimnicu Vilcea Depth-First Search • Expand deepest unexpanded node • Implementation QueueingFn = insert successors at front of queue Arad

20. Writing Depth-First Search as a Recursive Procedure Procedure DEPTH-FIRST (N) Begin If N=Goal Then Return (“SUCCESS”) ELSE For C in CHILDREN (N) DO DEPTH-FIRST (C) Return(“FAILURE”) End Note: In a recursive implementation, the program stack acts as the queue.

21. Depth-Limited Search • Same as depth-first search with depth limit l. • Implementation: • Nodes at depth l have no successors.

22. Iterative Deepening Search Repeated depth-limited search with increasing depth Function ITERATIVE-DEEPENING-SEARCH (problem) returns a solution or failure for depth  0 to MAXDEPTH do result  DEPTH-LIMIT-SEARCH (problem, depth) if result then return result end return FAILURE

23. Zerind Sibiu Timisoara Iterative Deepening Search: depth=1 Arad