Foundations of Artificial Intelligence March 6, 2019 — 10. State-Space Search: Breadth-first Search 10.1 Blind Search Foundations of Artificial Intelligence 10. State-Space Search: Breadth-first Search 10.2 Breadth-first Search: Introduction 10.3 BFS-Tree Malte Helmert 10.4 BFS-Graph University of Basel 10.5 Properties of Breadth-first Search March 6, 2019 10.6 Summary M. Helmert (University of Basel) Foundations of Artificial Intelligence March 6, 2019 1 / 32 M. Helmert (University of Basel) Foundations of Artificial Intelligence March 6, 2019 2 / 32 10. State-Space Search: Breadth-first Search Blind Search State-Space Search: Overview Chapter overview: state-space search ◮ 5.–7. Foundations 10.1 Blind Search ◮ 8.–12. Basic Algorithms ◮ 8. Data Structures for Search Algorithms ◮ 9. Tree Search and Graph Search ◮ 10. Breadth-first Search ◮ 11. Uniform Cost Search ◮ 12. Depth-first Search and Iterative Deepening ◮ 13.–19. Heuristic Algorithms M. Helmert (University of Basel) Foundations of Artificial Intelligence March 6, 2019 3 / 32 M. Helmert (University of Basel) Foundations of Artificial Intelligence March 6, 2019 4 / 32
10. State-Space Search: Breadth-first Search Blind Search 10. State-Space Search: Breadth-first Search Blind Search Blind Search Blind Search Algorithms: Examples In Chapters 10–12 we consider blind search algorithms: examples of blind search algorithms: ◮ breadth-first search ( � this chapter) Blind Search Algorithms ◮ uniform cost search ( � Chapter 11) Blind search algorithms use no information about state spaces apart from the black box interface. ◮ depth-first search ( � Chapter 12) They are also called uninformed search algorithms. ◮ depth-limited search ( � Chapter 12) ◮ iterative deepening search ( � Chapter 12) contrast: heuristic search algorithms (Chapters 13–19) M. Helmert (University of Basel) Foundations of Artificial Intelligence March 6, 2019 5 / 32 M. Helmert (University of Basel) Foundations of Artificial Intelligence March 6, 2019 6 / 32 10. State-Space Search: Breadth-first Search Breadth-first Search: Introduction 10. State-Space Search: Breadth-first Search Breadth-first Search: Introduction Breadth-first Search Breadth-first search expands nodes in order of generation (FIFO). � e.g., open list as linked list or deque A 10.2 Breadth-first Search: Introduction open: A ◮ searches state space layer by layer ◮ always finds shallowest goal state first M. Helmert (University of Basel) Foundations of Artificial Intelligence March 6, 2019 7 / 32 M. Helmert (University of Basel) Foundations of Artificial Intelligence March 6, 2019 8 / 32
10. State-Space Search: Breadth-first Search Breadth-first Search: Introduction 10. State-Space Search: Breadth-first Search Breadth-first Search: Introduction Breadth-first Search Breadth-first Search Breadth-first search expands nodes in order of generation (FIFO). Breadth-first search expands nodes in order of generation (FIFO). � e.g., open list as linked list or deque � e.g., open list as linked list or deque A A B C B C D E open: B, C open: C, D, E ◮ searches state space layer by layer ◮ searches state space layer by layer ◮ always finds shallowest goal state first ◮ always finds shallowest goal state first M. Helmert (University of Basel) Foundations of Artificial Intelligence March 6, 2019 9 / 32 M. Helmert (University of Basel) Foundations of Artificial Intelligence March 6, 2019 10 / 32 10. State-Space Search: Breadth-first Search Breadth-first Search: Introduction 10. State-Space Search: Breadth-first Search Breadth-first Search: Introduction Breadth-first Search Breadth-first Search Breadth-first search expands nodes in order of generation (FIFO). Breadth-first search expands nodes in order of generation (FIFO). � e.g., open list as linked list or deque � e.g., open list as linked list or deque A A B C B C D E F G H D E F G H I J open: D, E, F, G, H open: E, F, G, H, I, J ◮ searches state space layer by layer ◮ searches state space layer by layer ◮ always finds shallowest goal state first ◮ always finds shallowest goal state first M. Helmert (University of Basel) Foundations of Artificial Intelligence March 6, 2019 11 / 32 M. Helmert (University of Basel) Foundations of Artificial Intelligence March 6, 2019 12 / 32
10. State-Space Search: Breadth-first Search Breadth-first Search: Introduction 10. State-Space Search: Breadth-first Search Breadth-first Search: Introduction Breadth-first Search Breadth-first Search: Tree Search or Graph Search? Breadth-first search expands nodes in order of generation (FIFO). � e.g., open list as linked list or deque Breadth-first search can be performed A ◮ without duplicate elimination (as a tree search) � BFS-Tree B C ◮ or with duplicate elimination (as a graph search) � BFS-Graph D E F G H (BFS = breadth-first search). I J � We consider both variants. ◮ searches state space layer by layer ◮ always finds shallowest goal state first M. Helmert (University of Basel) Foundations of Artificial Intelligence March 6, 2019 13 / 32 M. Helmert (University of Basel) Foundations of Artificial Intelligence March 6, 2019 14 / 32 10. State-Space Search: Breadth-first Search BFS-Tree 10. State-Space Search: Breadth-first Search BFS-Tree Reminder: Generic Tree Search Algorithm reminder from Chapter 9: Generic Tree Search 10.3 BFS-Tree open := new OpenList open . insert(make root node()) while not open . is empty(): n := open . pop() if is goal( n . state): return extract path( n ) for each � a , s ′ � ∈ succ( n . state): n ′ := make node( n , a , s ′ ) open . insert( n ′ ) return unsolvable M. Helmert (University of Basel) Foundations of Artificial Intelligence March 6, 2019 15 / 32 M. Helmert (University of Basel) Foundations of Artificial Intelligence March 6, 2019 16 / 32
10. State-Space Search: Breadth-first Search BFS-Tree 10. State-Space Search: Breadth-first Search BFS-Tree BFS-Tree (1st Attempt) BFS-Tree (1st Attempt): Discussion breadth-first search without duplicate elimination (1st attempt): BFS-Tree (1st Attempt) This is almost a usable algorithm, but it wastes some effort: open := new Deque ◮ In a breadth-first search, the first generated goal node open . push back(make root node()) while not open . is empty(): is always the first expanded goal node. (Why?) n := open . pop front() ◮ Hence it is more efficient to already perform the goal test if is goal( n . state): upon generating a node (rather than upon expanding it). return extract path( n ) � How much effort does this save? for each � a , s ′ � ∈ succ( n . state): n ′ := make node( n , a , s ′ ) open . push back( n ′ ) return unsolvable M. Helmert (University of Basel) Foundations of Artificial Intelligence March 6, 2019 17 / 32 M. Helmert (University of Basel) Foundations of Artificial Intelligence March 6, 2019 18 / 32 10. State-Space Search: Breadth-first Search BFS-Tree 10. State-Space Search: Breadth-first Search BFS-Tree BFS-Tree (2nd Attempt) BFS-Tree (2nd Attempt): Discussion breadth-first search without duplicate elimination (2nd attempt): BFS-Tree (2nd Attempt) open := new Deque open . push back(make root node()) while not open . is empty(): Where is the bug? n := open . pop front() if is goal( n . state): return extract path( n ) for each � a , s ′ � ∈ succ( n . state): n ′ := make node( n , a , s ′ ) if is goal( s ′ ): return extract path( n ′ ) open . push back( n ′ ) return unsolvable M. Helmert (University of Basel) Foundations of Artificial Intelligence March 6, 2019 19 / 32 M. Helmert (University of Basel) Foundations of Artificial Intelligence March 6, 2019 20 / 32
10. State-Space Search: Breadth-first Search BFS-Tree 10. State-Space Search: Breadth-first Search BFS-Graph BFS-Tree (Final Version) breadth-first search without duplicate elimination (final version): BFS-Tree if is goal(init()): 10.4 BFS-Graph return �� open := new Deque open . push back(make root node()) while not open . is empty(): n := open . pop front() for each � a , s ′ � ∈ succ( n . state): n ′ := make node( n , a , s ′ ) if is goal( s ′ ): return extract path( n ′ ) open . push back( n ′ ) return unsolvable M. Helmert (University of Basel) Foundations of Artificial Intelligence March 6, 2019 21 / 32 M. Helmert (University of Basel) Foundations of Artificial Intelligence March 6, 2019 22 / 32 10. State-Space Search: Breadth-first Search BFS-Graph 10. State-Space Search: Breadth-first Search BFS-Graph Reminder: Generic Graph Search Algorithm Adapting Generic Graph Search to Breadth-First Search reminder from Chapter 9: Generic Graph Search Adapting the generic algorithm to breadth-first search: open := new OpenList ◮ similar adaptations to BFS-Tree open . insert(make root node()) (deque as open list, early goal test) closed := new ClosedList while not open . is empty(): ◮ as closed list does not need to manage node information, n := open . pop() a set data structure suffices if closed . lookup( n . state) = none : ◮ for the same reasons why early goal tests are a good idea, closed . insert( n ) we should perform duplicate tests against the closed list if is goal( n . state): and updates of the closed lists as early as possible return extract path( n ) for each � a , s ′ � ∈ succ( n . state): n ′ := make node( n , a , s ′ ) open . insert( n ′ ) return unsolvable M. Helmert (University of Basel) Foundations of Artificial Intelligence March 6, 2019 23 / 32 M. Helmert (University of Basel) Foundations of Artificial Intelligence March 6, 2019 24 / 32
Recommend
More recommend