610 likes | 754 Views
The next RP deliverable. 20. Review: Generate and Test Paradigm. Propose possible solutions then test whether each proposal constitutes a solution Will illustrate with n-Queens problem. n-Queens Problem. n-Queens are to be placed on an n x n board
E N D
Review: Generate and Test Paradigm • Propose possible solutions then test whether each proposal constitutes a solution • Will illustrate with n-Queens problem
n-Queens Problem • n-Queens are to be placed on an n x n board • No two Queens should occupy the same row, column or diagonal • Example with a 4 x 4 board with 4 Queens
Exhaustive Enumeration • A search methodology that looks everywhere for a solution to a problem (consider all 1820 combos in the 4-queens problem). • A partial solution is developed further even after it has been discovered that this set of steps cannot possibly lead to a successful problem solution
Backtracking • An improvement to exhaustive enumeration • A proposed solution is divided into stages • In the 4-Queens problem, placing each queen on the board is a stage • In Stage i, Queens have been successfully placed in columns 1,…, i-1 • If no square remains on which the ith Queen may be placed that does not violate any of the constraints, then we must return to Stage i-1
Backtracking / cont. • Undo the placement of the Queen at Stage i-1, make the next choice for this Queen, and return to Stage i. If it is not possible to successfully place the (i-1)st Queen, then backtracking continues to Stage i-2 • Can use Backtracking with Generate and Test • The Generator will attempt to place a Queen in each column. • The Test module will view a possible solution as it is being developed. • The algorithm contains four stages.
Artificial Intelligence in the 21st CenturyS. Lucci / D. Kopec • Chapter 2:Uninformed Search
Blind Search Algorithms • AKA Tree Search Algorithms (although this can be somewhat misleading as we will see later)
Tree Search Algorithms • Basic idea:offline, simulated exploration of state spaceby generating successors of already-explored states (a.k.a. expanding states)
Blind Search Algorithms • AKA Tree Search Algorithms (although this can be somewhat misleading as we will see later) • Three principal algorithms (but each may have variations) • depth first search (dfs) • breadth first search (bfs) • depth first search with iterative deepening (dfs-id) • Two key properties • They do not use heuristics • Their aim is to find some solution to a problem
Heuristics A heuristic is a “a rule of thumb” for solving a problem. This is to be contrasted with an algorithm which is a definite, effective procedure guaranteed to solve a problem. A heuristic may be helpful in solving a problem but it does not guarantee a solution. In the context of searches, a heuristic is an estimate of how close you are to the goal state.
Depth First Search • Attempts to plunge as deeply into a tree as quickly as possible • If there is a choice, it selects the leftmost branch
Depth-First Search • Expand deepest unexpanded nodeImplementation: fringe = LIFO queue, I.e., put successors at front
Depth-First Search • Expand deepest unexpanded nodeImplementation: fringe = LIFO queue, I.e., put successors at front
Depth-First Search • Expand deepest unexpanded nodeImplementation: fringe = LIFO queue, I.e., put successors at front
Depth-First Search • Expand deepest unexpanded nodeImplementation: fringe = LIFO queue, I.e., put successors at front
Depth-First Search • Expand deepest unexpanded nodeImplementation: fringe = LIFO queue, I.e., put successors at front
Depth-First Search • Expand deepest unexpanded nodeImplementation: fringe = LIFO queue, I.e., put successors at front
Depth-First Search • Expand deepest unexpanded nodeImplementation: fringe = LIFO queue, I.e., put successors at front
Depth-First Search • Expand deepest unexpanded nodeImplementation: fringe = LIFO queue, I.e., put successors at front
Depth-First Search • Expand deepest unexpanded nodeImplementation: fringe = LIFO queue, I.e., put successors at front
Depth-First Search • Expand deepest unexpanded nodeImplementation: fringe = LIFO queue, I.e., put successors at front
Depth-First Search • Expand deepest unexpanded nodeImplementation: fringe = LIFO queue, I.e., put successors at front
Depth-First Search • Expand deepest unexpanded nodeImplementation: fringe = LIFO queue, I.e., put successors at front
Implementing Search • Searches are implemented by maintaining two lists: • open list – list of nodes still being explored • closed list – list of nodes already explored and no longer under consideration • The differences between strategies effect the management of the open list • Depth first search is accomplished by maintaining the open list as a stack (Consult Chapter 2, p 63)
Implementing dfs Algorithm stops once it reaches the goal at G1
Breadth First Search • Nodes are visited from the top of the tree to the bottom, from left to right • All nodes on level i are visited before any nodes on level i+1 are visited
Breadth-First Search • Expanding shallowest unexpanded nodeImplementation fringe is a FIFO queue, i.e., new successors go at end
Breadth-First Search • Expanding shallowest unexpanded nodeImplementation fringe is a FIFO queue, i.e., new successors go at end
Breadth-First Search • Expanding shallowest unexpanded nodeImplementation fringe is a FIFO queue, i.e., new successors go at end
Breadth-First Search • Expanding shallowest unexpanded nodeImplementation fringe is a FIFO queue, i.e., new successors go at end
Recall: Implementing Search • Searches are implemented by maintaining two lists: • open list – list of nodes still being explored • closed list – list of nodes already explored and no longer under consideration • The differences between strategies effect the management of the open list • Breadth first search is accomplished by maintaining the open list as a queue(Consult Chapter 2, p 65)
Implementing bfs Algorithm stops once goal G1 is reached .
Measuring Problem Solving Performance • Completeness – an algorithm is complete when it is guaranteed to find a solution when there is one • Optimality – an algorithm is optimal if it provides the lowest cost path amongst all solutions • Time Complexity – measured in the number of nodes generated during the search • Space Complexity – how much memory is required to perform the search. We must also determine the maximum number of nodes
The Branching Factor • The branching factor of a node is the number of branches emanating from it The branching factor of A is three • If every node in a search tree has a branching factor of b, then the branching factor of the tree is b
Branching Factor / cont. • d : this parameter measures the depth of the shallowest goal node • m : this parameter measures the maximum length of any path
Properties of Depth-first Search • Complete??
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
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 • Optimal??
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 • Optimal?? No.
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 • Optimal?? No. • Time??
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 • Optimal?? No. • Time?? O(bm): terrible if m is much larger than dbut if solutions are dense, may be much faster than breadth-first
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 • Optimal?? No. • Time?? O(bm): terrible if m is much larger than dbut if solutions are dense, may be much faster than breadth-first • Space??
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 • Optimal?? No. • Time?? O(bm): terrible if m is much larger than dbut if solutions are dense, may be much faster than breadth-first • Space?? O(bm), I.e., linear space!