Advanced Artificial Intelligence, DT4048 Part 2 — Problem Solving and Search: Uninformed Search Strategies Federico Pecora [email protected] Center for Applied Autonomous Sensor Systems (AASS) Örebro University, Sweden © 2014 Hyun Sek Oh, www.aistudy.co.kr Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Tree Search Algorithms Offline, simulated exploration of search space Generate successors of already explored states (i.e., expanding states) Algorithm 1: Tree-Search(problem,strategy) : solution/failure initialize the search tree using the initial state of problem while true do if @ candidates for expansion then return failure node ← choose a leaf node for expansion according to strategy if node contains a goal state then return the corresponding solution else expand the node and add the resulting nodes to the search tree © 2015 F. Pecora / Örebro University – aass.oru.se 2 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Tree Search Example © 2015 F. Pecora / Örebro University – aass.oru.se 3 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Tree Search Example © 2015 F. Pecora / Örebro University – aass.oru.se 3 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Tree Search Example © 2015 F. Pecora / Örebro University – aass.oru.se 3 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Implementation: States vs. Nodes State: representation of a physical configuration Node: data structure constituting part of a search tree includes parent, children, depth, path cost g(x) States do not have parents, children, depth, or path cost! these are properties of the nodes representing states expand function creates new nodes, fills the various fields successor function creates the corresponding states © 2015 F. Pecora / Örebro University – aass.oru.se 4 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References General Implementaiton of Tree Search (I) Algorithm 2: Tree-Search(problem, fringe) returns a solution, or failure fringe ← insert(make-node(initial-state(problem)), fringe) while true do if fringe = ∅ then return failure node ← remove-front(fringe) if goal-test(problem,state(node)) then return solution(node) fringe ← insert-all(expand(node, problem), fringe) © 2015 F. Pecora / Örebro University – aass.oru.se 5 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References General Implementaiton of Tree Search (II) Algorithm 3: expand(node, problem) returns a set of nodes successors ← ∅ foreach haction, result i ∈ sucessor(problem, state(node)) do s ← a new node set-parent(s, node) set-action(s, action) set-state(s, result ) set-path-cost(s, path-cost(node) + c(state(node), action, result )) set-depth(s, depth(node)+1 ) successors ← successors ∪ {s} return successors © 2015 F. Pecora / Örebro University – aass.oru.se 6 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Strategies in Tree Search A search strategy is defined by picking the order of node expansion Strategies are evaluated along four dimentions Completeness: does it always find a solution if one exists? Time complexity: number of nodes generated/expanded Space complexity: maximum number of nodes in memory Optmiality: does it always find a least-cost solution? Time and space comlexity 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 ∞) © 2015 F. Pecora / Örebro University – aass.oru.se 7 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Uninformed Search Strategies Uninformed strategies use only the information available in the problem definition Breadth-first search (BFS) Uniform-cost search (UCS) Depth-first search (DFS) Depth-limited search (DLS) Iterative deepening search (IDS) © 2015 F. Pecora / Örebro University – aass.oru.se 8 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Selecting vs. Sorting All algorithms shown here are obtained by altering the order in which nodes are selected for expansion Any selection rule can be achieved by employing an appropriate ordering of the frontier set order the elements on the frontier always select the first element © 2015 F. Pecora / Örebro University – aass.oru.se 9 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Breadth-First Search BFS expands shallowest unexpanded node Implementation in expand() function: fringe is a FIFO queue © 2015 F. Pecora / Örebro University – aass.oru.se 10 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Breadth-First Search BFS expands shallowest unexpanded node Implementation in expand() function: fringe is a FIFO queue © 2015 F. Pecora / Örebro University – aass.oru.se 10 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Breadth-First Search BFS expands shallowest unexpanded node Implementation in expand() function: fringe is a FIFO queue © 2015 F. Pecora / Örebro University – aass.oru.se 10 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Breadth-First Search BFS expands shallowest unexpanded node Implementation in expand() function: fringe is a FIFO queue © 2015 F. Pecora / Örebro University – aass.oru.se 10 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Breadth-First Search: Properties Completeness: Time complexity: Space complexity: Optmiality: © 2015 F. Pecora / Örebro University – aass.oru.se 11 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Breadth-First Search: Properties Completeness: yes (if b is finite) Time complexity: Space complexity: Optmiality: © 2015 F. Pecora / Örebro University – aass.oru.se 11 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Breadth-First Search: Properties Completeness: yes (if b is finite) Time complexity: b + b 2 + b 3 + · · · + b d = O (b d ) Space complexity: Optmiality: © 2015 F. Pecora / Örebro University – aass.oru.se 11 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Breadth-First Search: Properties Completeness: yes (if b is finite) Time complexity: b + b 2 + b 3 + · · · + b d = O (b d ) Space complexity: O (b d ) (keeps all nodes) Optmiality: © 2015 F. Pecora / Örebro University – aass.oru.se 11 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Breadth-First Search: Properties Completeness: yes (if b is finite) Time complexity: b + b 2 + b 3 + · · · + b d = O (b d ) Space complexity: O (b d ) (keeps all nodes) Optmiality: yes (if cost = 1 per step); not optimal in general © 2015 F. Pecora / Örebro University – aass.oru.se 11 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Breadth-First Search: Properties Completeness: yes (if b is finite) Time complexity: b + b 2 + b 3 + · · · + b d = O (b d ) Space complexity: O (b d ) (keeps all nodes) Optmiality: yes (if cost = 1 per step); not optimal in general Note: space complexity is the biggest problem can generate nodes at 100MB/sec, so 24 hrs of computation requires 8640GB © 2015 F. Pecora / Örebro University – aass.oru.se 11 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Uniform-Cost Search Simple extension to BFS that is optimal with any step cost function such that g(successor(x)) ≥ g(x) Implementation in expand() function: order the fringe queue according to lowest step cost first Completeness: Time complexity: Space complexity: Optmiality: © 2015 F. Pecora / Örebro University – aass.oru.se 12 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Uniform-Cost Search Simple extension to BFS that is optimal with any step cost function such that g(successor(x)) ≥ g(x) Implementation in expand() function: order the fringe queue according to lowest step cost first Completeness: yes (if step cost is > , i.e., path cost always increases) Time complexity: Space complexity: Optmiality: © 2015 F. Pecora / Örebro University – aass.oru.se 12 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Uniform-Cost Search Simple extension to BFS that is optimal with any step cost function such that g(successor(x)) ≥ g(x) Implementation in expand() function: order the fringe queue according to lowest step cost first Completeness: yes (if step cost is > , i.e., path cost always increases) ∗ Time complexity: O (b dC /e ) = number of nodes such that g(node) < cost of optimal solution C ∗ Space complexity: Optmiality: © 2015 F. Pecora / Örebro University – aass.oru.se 12 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Uniform-Cost Search Simple extension to BFS that is optimal with any step cost function such that g(successor(x)) ≥ g(x) Implementation in expand() function: order the fringe queue according to lowest step cost first Completeness: yes (if step cost is > , i.e., path cost always increases) ∗ Time complexity: O (b dC /e ) = number of nodes such that g(node) < cost of optimal solution C ∗ Space complexity: O (b dC ∗ /e ) Optmiality: © 2015 F. Pecora / Örebro University – aass.oru.se 12 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Uniform-Cost Search Simple extension to BFS that is optimal with any step cost function such that g(successor(x)) ≥ g(x) Implementation in expand() function: order the fringe queue according to lowest step cost first Completeness: yes (if step cost is > , i.e., path cost always increases) ∗ Time complexity: O (b dC /e ) = number of nodes such that g(node) < cost of optimal solution C ∗ Space complexity: O (b dC ∗ /e ) Optmiality: yes (nodes expanded in increasing order of g(x)) © 2015 F. Pecora / Örebro University – aass.oru.se 12 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Uniform-Cost Search Simple extension to BFS that is optimal with any step cost function such that g(successor(x)) ≥ g(x) Implementation in expand() function: order the fringe queue according to lowest step cost first Completeness: yes (if step cost is > , i.e., path cost always increases) ∗ Time complexity: O (b dC /e ) = number of nodes such that g(node) < cost of optimal solution C ∗ Space complexity: O (b dC ∗ /e ) Optmiality: yes (nodes expanded in increasing order of g(x)) Note: O (b dC ∗ /e ) can be (and usually is) O (b d ) © 2015 F. Pecora / Örebro University – aass.oru.se 12 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Uniform-Cost Search Simple extension to BFS that is optimal with any step cost function such that g(successor(x)) ≥ g(x) Implementation in expand() function: order the fringe queue according to lowest step cost first Completeness: yes (if step cost is > , i.e., path cost always increases) ∗ Time complexity: O (b dC /e ) = number of nodes such that g(node) < cost of optimal solution C ∗ Space complexity: O (b dC ∗ /e ) Optmiality: yes (nodes expanded in increasing order of g(x)) Note: O (b dC ∗ /e ) can be (and usually is) O (b d ) Note: UCS is a variant of Dijkstra’s algorithm © 2015 F. Pecora / Örebro University – aass.oru.se 12 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Depth-First Search DFS expands deepest unexpanded node Implementation in expand() function: fringe is a LIFO queue © 2015 F. Pecora / Örebro University – aass.oru.se 13 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Depth-First Search DFS expands deepest unexpanded node Implementation in expand() function: fringe is a LIFO queue © 2015 F. Pecora / Örebro University – aass.oru.se 13 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Depth-First Search DFS expands deepest unexpanded node Implementation in expand() function: fringe is a LIFO queue © 2015 F. Pecora / Örebro University – aass.oru.se 13 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Depth-First Search DFS expands deepest unexpanded node Implementation in expand() function: fringe is a LIFO queue © 2015 F. Pecora / Örebro University – aass.oru.se 13 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Depth-First Search DFS expands deepest unexpanded node Implementation in expand() function: fringe is a LIFO queue © 2015 F. Pecora / Örebro University – aass.oru.se 13 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Depth-First Search DFS expands deepest unexpanded node Implementation in expand() function: fringe is a LIFO queue © 2015 F. Pecora / Örebro University – aass.oru.se 13 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Depth-First Search DFS expands deepest unexpanded node Implementation in expand() function: fringe is a LIFO queue © 2015 F. Pecora / Örebro University – aass.oru.se 13 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Depth-First Search DFS expands deepest unexpanded node Implementation in expand() function: fringe is a LIFO queue © 2015 F. Pecora / Örebro University – aass.oru.se 13 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Depth-First Search DFS expands deepest unexpanded node Implementation in expand() function: fringe is a LIFO queue © 2015 F. Pecora / Örebro University – aass.oru.se 13 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Depth-First Search DFS expands deepest unexpanded node Implementation in expand() function: fringe is a LIFO queue © 2015 F. Pecora / Örebro University – aass.oru.se 13 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Depth-First Search DFS expands deepest unexpanded node Implementation in expand() function: fringe is a LIFO queue © 2015 F. Pecora / Örebro University – aass.oru.se 13 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Depth-First Search DFS expands deepest unexpanded node Implementation in expand() function: fringe is a LIFO queue © 2015 F. Pecora / Örebro University – aass.oru.se 13 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Depth-First Search: Properties Completeness: Time complexity: Space complexity: Optmiality: © 2015 F. Pecora / Örebro University – aass.oru.se 14 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Depth-First Search: Properties Completeness: no (fails in infinite-depth spaces and spaces with loops) ⇒ modify to avoid repeated states along the path ⇒ complete in finite spaces Time complexity: Space complexity: Optmiality: © 2015 F. Pecora / Örebro University – aass.oru.se 14 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Depth-First Search: Properties Completeness: no (fails in infinite-depth spaces and spaces with loops) ⇒ modify to avoid repeated states along the path ⇒ complete in finite spaces Time complexity: O (b m ): worse than BFS if solutions are deep (m d ), better than BFS if solutions are dense Space complexity: Optmiality: © 2015 F. Pecora / Örebro University – aass.oru.se 14 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Depth-First Search: Properties Completeness: no (fails in infinite-depth spaces and spaces with loops) ⇒ modify to avoid repeated states along the path ⇒ complete in finite spaces Time complexity: O (b m ): worse than BFS if solutions are deep (m d ), better than BFS if solutions are dense Space complexity: O (bm): linear space! Optmiality: © 2015 F. Pecora / Örebro University – aass.oru.se 14 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Depth-First Search: Properties Completeness: no (fails in infinite-depth spaces and spaces with loops) ⇒ modify to avoid repeated states along the path ⇒ complete in finite spaces Time complexity: O (b m ): worse than BFS if solutions are deep (m d ), better than BFS if solutions are dense Space complexity: O (bm): linear space! Optmiality: no © 2015 F. Pecora / Örebro University – aass.oru.se 14 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Depth-Limited Search DFS with a depth limit l (nodes at l have no successors) Recursive implementation Algorithm 4: Depth-Limited-Search(problem, limit ) : sol/fail/cutoff init ← make-node(initial-state(problem)) return recursive-DLS( init , problem, limit ) © 2015 F. Pecora / Örebro University – aass.oru.se 15 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Depth-Limited Search DFS with a depth limit l (nodes at l have no successors) Recursive implementation Algorithm 5: recursive-DLS(node, problem, limit ) : solution/failure/cutoff cutoffOccurred ← false if goal-test(problem,state(node)) then return solution(node) if depth(node) = limit then return cutoff foreach successor ∈ expand(node, problem) do result ← recursive-DLS(successor, problem, limit ) if result = cutoff then cutoffOccurred ← true else if result 6= failure then return result if cutoffOccurred then return cutoff else return failure © 2015 F. Pecora / Örebro University – aass.oru.se 15 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Depth-Limited Search: Properties Completeness: Time complexity: Space complexity: Optmiality: © 2015 F. Pecora / Örebro University – aass.oru.se 16 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Depth-Limited Search: Properties Completeness: no (unless we choose l ≥ d ) Time complexity: Space complexity: Optmiality: © 2015 F. Pecora / Örebro University – aass.oru.se 16 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Depth-Limited Search: Properties Completeness: no (unless we choose l ≥ d ) Time complexity: O (b l ) Space complexity: Optmiality: © 2015 F. Pecora / Örebro University – aass.oru.se 16 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Depth-Limited Search: Properties Completeness: no (unless we choose l ≥ d ) Time complexity: O (b l ) Space complexity: O (bl ) Optmiality: © 2015 F. Pecora / Örebro University – aass.oru.se 16 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Depth-Limited Search: Properties Completeness: no (unless we choose l ≥ d ) Time complexity: O (b l ) Space complexity: O (bl ) Optmiality: no © 2015 F. Pecora / Örebro University – aass.oru.se 16 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Depth-Limited Search: Properties Completeness: no (unless we choose l ≥ d ) Time complexity: O (b l ) Space complexity: O (bl ) Optmiality: no Note: the key is to know l , which can be seen as problem-specific knowledge in the Romania travelling example, we could notice that the diameter of the graph is 9 Note: DFS is a special case of DLS with l = ∞ © 2015 F. Pecora / Örebro University – aass.oru.se 16 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Iterative Deepening Search aka Iterative Deepening Depth-First Search Attempts to find the best depth limit Algorithm 6: Iterative-Deepening-Search(problem) : solution for depth ← 0 to ∞ do result ← Depth-Limited-Search (problem, depth ) if result 6= cutoff then return result © 2015 F. Pecora / Örebro University – aass.oru.se 17 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Iterative Deepening Search limit = 0 © 2015 F. Pecora / Örebro University – aass.oru.se 18 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Iterative Deepening Search limit = 1 © 2015 F. Pecora / Örebro University – aass.oru.se 18 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Iterative Deepening Search limit = 2 © 2015 F. Pecora / Örebro University – aass.oru.se 18 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Iterative Deepening Search limit = 3 © 2015 F. Pecora / Örebro University – aass.oru.se 18 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Iterative Deepening Search: Properties Completeness: Time complexity: Space complexity: Optmiality: © 2015 F. Pecora / Örebro University – aass.oru.se 19 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Iterative Deepening Search: Properties Completeness: yes Time complexity: Space complexity: Optmiality: © 2015 F. Pecora / Örebro University – aass.oru.se 19 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Iterative Deepening Search: Properties Completeness: yes Time complexity: (d + 1)b 0 + db 1 + (d − 1)b 2 + . . . + b d = O (b d ) Space complexity: Optmiality: © 2015 F. Pecora / Örebro University – aass.oru.se 19 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Iterative Deepening Search: Properties Completeness: yes Time complexity: (d + 1)b 0 + db 1 + (d − 1)b 2 + . . . + b d = O (b d ) Space complexity: O (bd ) Optmiality: © 2015 F. Pecora / Örebro University – aass.oru.se 19 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Iterative Deepening Search: Properties Completeness: yes Time complexity: (d + 1)b 0 + db 1 + (d − 1)b 2 + . . . + b d = O (b d ) Space complexity: O (bd ) Optmiality: yes (if step cost = 1) © 2015 F. Pecora / Örebro University – aass.oru.se 19 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Iterative Deepening Search: Properties Completeness: yes Time complexity: (d + 1)b 0 + db 1 + (d − 1)b 2 + . . . + b d = O (b d ) Space complexity: O (bd ) Optmiality: yes (if step cost = 1) Note: comparison to BFS with b = 10 and d = 5 N (IDS ) = 50 + 400 + 3, 000 + 20, 000 + 100, 000 = 123, 450 N (BFS ) = 10 + 100 + 1, 000 + 10, 000 + 100, 000 = 111, 110 Number of expanded nodes is comparable, despite repeated generation of states IDS is preferred uninformed search method for large search spaces and unknown depth of solution © 2015 F. Pecora / Örebro University – aass.oru.se 19 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Uninformed Search Algorithms: Summary BFS Completeness Yes a UCS Yes a,b DFS DLS IDS c d Yesa No No Time O (b d ) O (b dC ∗ /e ) O (b m ) O (b l ) O (b d ) Space O (b d ) O (b dC ∗ /e ) O (bm) O (bl ) O (bd ) No No Yese Optimality a. b. c. d. e. Yes e Yes complete if b 6= ∞ complete if step cost > (path cost always increases) complete in finite spaces and if avoids loops complete if we choose l ≥ d optimal if step costs are all identical © 2015 F. Pecora / Örebro University – aass.oru.se 20 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Repeated States One of the most important sources of complexity in the search process: infinite search spaces C1 C7 C8 B1 C2 B4 A B2 C6 B3 C4 C3 C5 © 2015 F. Pecora / Örebro University – aass.oru.se 21 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Repeated States One of the most important sources of complexity in the search process: infinite search spaces Search tree has 4d leaves, but there are only (2d + 1)2 distinct states A B1 C1 A B1 For d = 20 this means 1681 distinct nodes in a trillion! © 2015 F. Pecora / Örebro University – aass.oru.se 21 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Repeated States One of the most important sources of complexity in the search process: infinite search spaces Search tree has 4d leaves, but there are only (2d + 1)2 distinct states A B1 C1 A B1 For d = 20 this means 1681 distinct nodes in a trillion! Solution: compare node to expand with already expanded nodes (closed list) © 2015 F. Pecora / Örebro University – aass.oru.se 21 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Repeated States DFS only maintains in memory nodes from root to current node We can use a closed list to ensure that finite state spaces do not become infinite because of loops © 2015 F. Pecora / Örebro University – aass.oru.se 22 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Repeated States DFS only maintains in memory nodes from root to current node We can use a closed list to ensure that finite state spaces do not become infinite because of loops . . . but will not save DFS from exponential proliferation of non-looping paths © 2015 F. Pecora / Örebro University – aass.oru.se 22 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Repeated States In a square grid we have O (r 2 ) nodes within radius r of the origin O (3r ) paths of length r (each node has three children) BFS can check for duplicates (it maintains all nodes in memory) DFS can only check for duplicates along the current path from root Thus in a graph with many short cycles, BFS is preferrable to DFS — see [Korf, 1998] © 2015 F. Pecora / Örebro University – aass.oru.se 23 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Graph Search Algorithms Tree search with closed list (keeps every node in memory) Closed list can be implemented with hash table to allow efficient lookup Algorithm 7: Graph-Search(problem, fringe) : solution/failure closed ← ∅ fringe ← insert(make-node(initial-state(problem)), fringe) while true do if fringe = ∅ then return failure node ← remove-front(fringe) if goal-test(problem,state(node)) then return solution(node) if state(node) ∈ / closed then closed ← state(node) fringe ← insert-all(expand(node, problem), fringe) © 2015 F. Pecora / Örebro University – aass.oru.se 24 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Summary Problem consists of: initial state, actions, goal test, path cost We have explained the most important uninformed search strategies as variants of Tree-Search BFS: explore all nodes for every at increasing depths — complete and optimal, space complexity makes it often infeasible UCS: like BFS in which “depth” is given by path cost — complete and optimal assuming step cost > DFS: go as deep as possible into search tree — neither complete nor optimal, but uses only linear space DLS: limited version of DFS — useful for implementing IDS IDS: calls DLS with increasing depth limits — complete and optimal for unit step costs, space complexity still linear Graph search for dealing with repeating states © 2015 F. Pecora / Örebro University – aass.oru.se 25 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Part 2 — Problem Solving and Search: Uninformed Search Strategies Thank you! © 2015 F. Pecora / Örebro University – aass.oru.se 26 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References References Korf, R. (1998). Artificial intelligence search algorithms. In Atallah, M., editor, Algorithms and Theory of Computation Handbook. CRC Press. © 2015 F. Pecora / Örebro University – aass.oru.se 27 / 27 Tree Search Algorithms Uninformed Search Strategies Graph Search Algorithms References Acknowledgements Portions of this course are inspired, compiled or taken from scientific presentations and teaching material by the following authors: Fahiem Bacchus, Amedeo Cesta, Gary Cottrell, Rina Dechter, Simone Fratini, Hector Geffner, Geoff Gordon, Russell Greiner, John Harrison, Joachim Hertzberg, David Kriegman, Sharad Malik, Dana Nau, Peter Norvig, Madhusudan Parthasarathy, Rhys Price Jones, Stuart Russel, Tuomas Sandholm, Stephen F. Smith, Padhraic Smyth, Paolo Traverso, Toby Walsh. © 2015 F. Pecora / Örebro University – aass.oru.se 27 / 27
© Copyright 2025 Paperzz