Problem Solving Russell and Norvig Chapter 3 ProblemSolving
Problem Solving Russell and Norvig: Chapter 3
Problem-Solving Agent sensors ? environment agent actuators
Problem-Solving Agent sensors ? environment agent actuators • Formulate Goal • Formulate Problem • States • Actions • Find Solution
Example: Route finding
Holiday Planning 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: Arad, Sibiu, Fagaras, Bucharest
Problem Solving States Actions Start Solution Goal
Vacuum World
Another graph example However, graphs can also be much more abstract. • A path through such a graph (from a start node to a goal node) is a "plan of action" to achieve some desired goal state from some known starting state. • It is this type of graph that is of more general interest in AI.
Problem-solving agent Four general steps in problem solving: n Goal formulation w What are the successful world states n Problem formulation w What actions and states to consider given the goal n Search w Determine the possible sequence of actions that lead to the states of known values and then choosing the best sequence. n Execute w Give the solution perform the actions.
Assumptions Made (for now) The The environment is static environment is discretizable environment is observable actions are deterministic
Problem formulation A problem is defined by: n n An initial state, e. g. Arad Successor function S(X)= set of action-state pairs w e. g. S(Arad)={<Arad Zerind, Zerind>, …} intial state + successor function = state space n Goal test, can be w Explicit, e. g. x=‘at bucharest’ w Implicit, e. g. checkmate(x) n Path cost (additive) w e. g. sum of distances, number of actions executed, … w c(x, a, y) is the step cost, assumed to be >= 0 A solution is a sequence of actions from initial to goal state. Optimal solution has the lowest path cost.
Selecting a state space Real world is absurdly complex. State space must be abstracted for problem solving. State = set of real states. Action = complex combination of real actions. n n 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. Solution = set of real paths that are solutions in the real world. Each abstract action should be “easier” than the real problem.
Example: vacuum world States? ? Initial state? ? Actions? ? Goal test? ? Path cost? ?
Example: vacuum world States? ? two locations with or without dirt: 2 x 22=8 states. Initial state? ? Any state can be initial Actions? ? {Left, Right, Suck} Goal test? ? Check whether squares are clean. Path cost? ? Number of actions to reach goal.
Example: 8 -puzzle States? ? Initial state? ? Actions? ? Goal test? ? Path cost? ?
Example: 8 -puzzle States? ? Integer location of each tile Initial state? ? Any state can be initial Actions? ? {Left, Right, Up, Down} Goal test? ? Check whether goal configuration is reached Path cost? ? Number of actions to reach goal
Example: 8 -puzzle 8 2 3 4 5 1 1 2 3 7 4 5 6 6 7 8 Initial state Goal state
Example: 8 -puzzle 8 2 3 4 7 5 1 6 8 2 3 4 5 1 8 7 6 2 8 2 3 4 7 5 1 6
Example: 8 -puzzle Size of the state space = 9!/2 = 181, 440 15 -puzzle . 65 x 1012 0. 18 sec 6 days 24 -puzzle . 5 x 1025 12 billion years 10 million states/sec
Example: 8 -queens Place 8 queens in a chessboard so that no two queens are in the same row, column, or diagonal. A solution Not a solution
Example: 8 -queens problem Incremental formulation vs. complete-state formulation States? ? Initial state? ? Actions? ? Goal test? ? Path cost? ?
Example: 8 -queens Formulation #1: • States: any arrangement of 0 to 8 queens on the board • Initial state: 0 queens on the board • Actions: add a queen in any square • Goal test: 8 queens on the board, none attacked • Path cost: none 648 states with 8 queens
Example: 8 -queens 2, 067 states Formulation #2: • States: any arrangement of k = 0 to 8 queens in the k leftmost columns with none attacked • Initial state: 0 queens on the board • Successor function: add a queen to any square in the leftmost empty column such that it is not attacked by any other queen • Goal test: 8 queens on the board
Real-world Problems Route finding Touring problems VLSI layout Robot Navigation Automatic assembly sequencing Drug design Internet searching …
Example: robot assembly States? ? Initial state? ? Actions? ? Goal test? ? Path cost? ?
Example: robot assembly States? ? Real-valued coordinates of robot joint angles; parts of the object to be assembled. Initial state? ? Any arm position and object configuration. Actions? ? Continuous motion of robot joints Goal test? ? Complete assembly (without robot) Path cost? ? Time to execute
Basic search algorithms How do we find the solutions of previous problems? n n Search the state space (remember complexity of space depends on state representation) Here: search through explicit tree generation w ROOT= initial state. w Nodes and leafs generated through successor function. n In general search generates a graph (same state through multiple paths)
Simple Tree Search Algorithm function TREE-SEARCH(problem, strategy) return solution or failure Initialize search tree to the initial state of the problem do if no candidates for expansion then return failure choose leaf node for expansion according to strategy if node contains goal state then return solution else expand the node and add resulting nodes to the search tree enddo
Take home points Difference between State Space and Search Tree
Search of State Space
Search of State Space
Search State Space
Search of State Space
Search of State Space
Search of State Space search tree
Take home points Difference between State Space and Search Tree Blind Search Learn names,
State space vs. search tree A state is a (representation of) a physical configuration A node is a data structure belong to a search tree n n n A node has a parent, children, … and ncludes path cost, depth, … Here node= <state, parent-node, action, path-cost, depth> FRINGE= contains generated nodes which are not yet expanded.
Search Strategies A strategy is defined by picking the order of node expansion Performance Measures: n n 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 Optimality – does it always find a least-cost solution Time and space complexity are measured in terms of n n n b – maximum branching factor of the search tree d – depth of the least-cost solution m – maximum depth of the state space (may be ∞)
Uninformed search strategies (a. k. a. blind search) = use only information available in problem definition. n When strategies can determine whether one non-goal state is better than another informed search. Categories defined by expansion algorithm: n n n Breadth-first search Uniform-cost search Depth-first search Depth-limited search Iterative deepening search. Bidirectional search
Breadth-First Strategy Expand shallowest unexpanded node Implementation: fringe is a FIFO queue New nodes are inserted at the end of the queue 1 2 4 8 FRINGE = (1) 3 5 6 9 7
Breadth-First Strategy Expand shallowest unexpanded node Implementation: fringe is a FIFO queue New nodes are inserted at the end of the queue 1 2 4 8 FRINGE = (2, 3) 3 5 6 9 7
Breadth-First Strategy Expand shallowest unexpanded node Implementation: fringe is a FIFO queue New nodes are inserted at the end of the queue 1 2 4 8 FRINGE = (3, 4, 5) 3 5 6 9 7
Breadth-First Strategy Expand shallowest unexpanded node Implementation: fringe is a FIFO queue New nodes are inserted at the end of the queue 1 2 4 8 FRINGE = (4, 5, 6, 7) 3 5 6 9 7
Breadth-First Strategy Expand shallowest unexpanded node Implementation: fringe is a FIFO queue New nodes are inserted at the end of the queue 1 2 4 8 FRINGE = (5, 6, 7, 8) 3 5 6 9 7
Breadth-First Strategy Expand shallowest unexpanded node Implementation: fringe is a FIFO queue New nodes are inserted at the end of the queue 1 2 4 8 FRINGE = (6, 7, 8) 3 5 6 9 7
Breadth-First Strategy Expand shallowest unexpanded node Implementation: fringe is a FIFO queue New nodes are inserted at the end of the queue 1 2 4 8 FRINGE = (7, 8, 9) 3 5 6 9 7
Breadth-First Strategy Expand shallowest unexpanded node Implementation: fringe is a FIFO queue New nodes are inserted at the end of the queue 1 2 4 8 FRINGE = (8, 9) 3 5 6 9 7
Example BFS 48
Breadth-first search: evaluation Completeness: n Does it always find a solution if one exists? n YES w If shallowest goal node is at some finite depth d w Condition: If b is finite n (maximum num. of succ. nodes is finite)
Breadth-first search: evaluation Completeness: n YES (if b is finite) Time complexity: n Assume a state space where every state has b successors. w root has b successors, each node at the next level has again b successors (total b 2), … w Assume solution is at depth d w Worst case; expand all but the last node at depth d w Total numb. of nodes generated: w 1 + b 2 + … + bd + b(bd-1) = O(bd+1)
Breadth-first search: evaluation Completeness: n YES (if b is finite) Time complexity: n Total numb. of nodes generated: w 1 + b 2 + … + bd + b(bd-1) = O(bd+1) Space complexity: O(bd+1)
Breadth-first search: evaluation Completeness: n YES (if b is finite) Time complexity: n Total numb. of nodes generated: w 1 + b 2 + … + bd + b(bd-1) = O(bd+1) Space complexity: O(bd+1) Optimality: n Does it always find the least-cost solution? n In general YES w unless actions have different cost.
Uniform-cost search Extension of BF-search: n Expand node with lowest path cost Implementation: fringe = queue ordered by path cost. UC-search is the same as BF-search when all stepcosts are equal.
Uniform-cost search Breadth-first is only optimal if step costs is increasing with depth (e. g. constant). Can we guarantee optimality for any step cost? Uniform-cost Search: Expand node with smallest path cost g(n). Proof Completeness: Given that every step will cost more than 0, and assuming a finite branching factor, there is a finite number of expansions required before the total path cost is equal to the path cost of the goal state. Hence, we will reach it. Proof of optimality given completeness: Assume UCS is not optimal. Then there must be an (optimal) goal state with path cost smaller than the found (suboptimal) goal state (invoking completeness). However, this is impossible because UCS would have expanded that node first by definition. Contradiction. 54
Uniform-cost search Completeness: n YES, if step-cost > (smal positive constant) Time complexity: n n n Assume C* the cost of the optimal solution. Assume that every action costs at least Worst-case: Space complexity: n Idem to time complexity Optimality: n n nodes expanded in order of increasing path cost. YES, if complete.
Depth-First Strategy Expand deepest unexpanded node Implementation: fringe is a LIFO queue (=stack) 1 2 4 FRINGE = (1) 5 3
Depth-First Strategy Expand deepest unexpanded node Implementation: fringe is a LIFO queue (=stack) 1 2 4 FRINGE = (2, 3) 5 3
Depth-First Strategy Expand deepest unexpanded node Implementation: fringe is a LIFO queue (=stack) 1 2 4 FRINGE = (4, 5, 3) 5 3
Depth-First Strategy Expand deepest unexpanded node Implementation: fringe is a LIFO queue (=stack) 1 2 4 3 5
Depth-First Strategy Expand deepest unexpanded node Implementation: fringe is a LIFO queue (=stack) 1 2 4 3 5
Depth-First Strategy Expand deepest unexpanded node Implementation: fringe is a LIFO queue (=stack) 1 2 4 3 5
Depth-First Strategy Expand deepest unexpanded node Implementation: fringe is a LIFO queue (=stack) 1 2 4 3 5
Depth-First Strategy Expand deepest unexpanded node Implementation: fringe is a LIFO queue (=stack) 1 2 4 3 5
Depth-First Strategy Expand deepest unexpanded node Implementation: fringe is a LIFO queue (=stack) 1 2 4 3 5
Depth-First Strategy Expand deepest unexpanded node Implementation: fringe is a LIFO queue (=stack) 1 2 4 3 5
Depth-First Strategy Expand deepest unexpanded node Implementation: fringe is a LIFO queue (=stack) 1 2 4 3 5
Depth-First Strategy Expand deepest unexpanded node Implementation: fringe is a LIFO queue (=stack) 1 2 4 3 5
Depth-First Strategy Expand deepest unexpanded node Implementation: fringe is a LIFO queue (=stack) 1 2 4 3 5
Depth-first search: evaluation Completeness; n Does it always find a solution if one exists? n NO w unless search space is finite and no loops are possible.
Depth-first search: evaluation Completeness; n NO unless search space is finite. Time complexity; n n Terrible if m is much larger than d (depth of optimal solution) But if many solutions, then faster than BFS
Depth-first search: evaluation Completeness; n NO unless search space is finite. Time complexity; Space complexity; n Backtracking search uses even less memory w One successor instead of all b.
Depth-first search: evaluation Completeness; n NO unless search space is finite. Time complexity; Space complexity; Optimality; No
Depth-Limited Strategy Depth-first with depth cutoff k (maximal depth below which nodes are not expanded) Three possible outcomes: n n n Solution Failure (no solution) Cutoff (no solution within cutoff) Solves the infinite-path problem. If k< d then incompleteness results. If k> d then not optimal. Time complexity: O(bk) Space complexity O(bk)
Iterative deepening search • To avoid the infinite depth problem of DFS, we can decide to only search until depth L, i. e. we don’t expand beyond depth L. Depth-Limited Search • What if solution is deeper than L? Increase L iteratively. Iterative Deepening Search • As we shall see: this inherits the memory advantage of Depth-First search, and is better in terms of time complexity than Breadth first search. 74
Iterative deepening search L=0 75
Iterative deepening search L=1 76
Iterative deepening search L=2 77
Iterative Deepening Search L=3 78
Properties of iterative deepening search Complete? Yes Time? O(bd) Space? O(bd) Optimal? Yes, if step cost = 1 or increasing function of depth. 79
Iterative Deepening Strategy Repeat for k = 0, 1, 2, …: Perform depth-first with depth cutoff k Complete Optimal if step cost =1 Time complexity is: (d+1)(1) + db + (d-1)b 2 + … + (1) bd = O(bd) Space complexity is: O(bd)
Comparison of Strategies Breadth-first is complete and optimal, but has high space complexity Depth-first is space efficient, but neither complete nor optimal Iterative deepening combines benefits of DFS and BFS and is asymptotically optimal
Bidirectional Strategy 2 fringe queues: FRINGE 1 and FRINGE 2 Time and space complexity = O(bd/2) << O(bd) The predecessor of each node should be efficiently computable.
Summary of algorithms Criterion Breadth. First Uniformcost Depth. First Depthlimited Iterative deepening Bidirectio nal search Complete ? YES* NO YES, if l d YES* Time bd+1 b. C*/e bm bl bd bd/2 Space bd+1 b. C*/e bm bl bd bd/2 Optimal? YES* NO NO YES
Example for illustrating uninformed search strategies S 3 3 D A B 15 7 E 8 1 C 20 G 5
Breadth-First Search Expanded node Nodes list S { S 0 } 0 3 B 1 C 8 } 8 S { A 3 1 A 3 { B 1 C 8 D 6 E 10 G 18 } A B C B 1 { C 8 D 6 E 10 G 18 G 21 } 3 8 6 E 10 G 18 G 21 G 13 } 15 C { D 7 20 5 D 6 { E 10 G 18 G 21 G 13 } D E G E 10 { G 18 G 21 G 13 } G 18 { G 21 G 13 } Solution path found is S A G , cost 18 Number of nodes expanded (including goal node) = 7
Depth-First Search Expanded node Nodes list { S 0 } S 0 3 B 1 C 8 } 8 S { A 3 1 A 3 { D 6 E 10 G 18 B 1 C 8 } A B C 6 10 G 18 B 1 C 8 } D { E 3 15 7 205 E 10 { G 18 B 1 C 8 } D E G G 18 { B 1 C 8 } Solution path found is S A G, cost 18 Number of nodes expanded (including goal node) = 5
Uniform-Cost Search Expanded node Nodes list { S 0 } S S 0 { B 1 A 3 C 8 } 1 3 C 8 G 21 } 8 3 B { A 1 A 3 { D 6 C 8 E 10 G 18 G 21} A B C D 6 { C 8 E 10 G 18 G 21 } 3 15 C 8 { E 10 G 13 G 18 G 21 } 7 20 5 E 10 { G 13 G 18 G 21 } D E G 13 { G 18 G 21 } G Solution path found is S C G, cosst 13 Number of nodes expanded (including goal node) = 7
How they perform Depth-First Search: n Expanded nodes: S A D E G n Solution found: S A G (cost 18) Breadth-First Search: n Expanded nodes: S A B C D E G n Solution found: S A G (cost 18) Uniform-Cost Search: n Expanded nodes: S A D B C E G n Solution found: S C G (cost 13) This is the only uninformed search that worries about costs. Iterative-Deepening Search: n nodes expanded: S S A B C S A D E G n Solution found: S A G (cost 18)
Repeated states Failure to detect repeated states can turn a solvable problems into unsolvable ones.
Avoiding Repeated States Requires comparing state descriptions Breadth-first strategy: n n Keep track of all generated states If the state of a new node already exists, then discard the node
Avoiding Repeated States Depth-first strategy: n Solution 1: w Keep track of all states associated with nodes in current tree w If the state of a new node already exists, then discard the node Avoids loops n Solution 2: w Keep track of all states generated so far w If the state of a new node has already been generated, then discard the node Space complexity of breadth-first
Summary Problem Formulation: state space, initial state, successor function, goal test, path cost Search tree state space Evaluation of strategies: completeness, optimality, time and space complexity Uninformed search strategies: breadth-first, depth-first, and variants Avoiding repeated states
- Slides: 92