Problem Solving by Search Objectives Problem solving agent Tree search Uninformed search strategies: BFS, DFS, DLS, and IDS Heuristic search strategies: GBFS and A* Reference Russell & Norvig: 3 and 4.1 Goals Goals Agent s task at hand can often be specified in terms of a goal to be satisfied. A goal is a set of desirable env states (goal states). Examples of goals Goal formulation Agent formulates its goal based on the current state and its performance measure. Goals help agent organize behavior by limiting the objectives to be achieved. Y. Xiang, CIS 3700, Introduction to Intelligent Systems 1 Y. Xiang, CIS 3700, Introduction to Intelligent Systems 2 Problem Formulation and Search Problem formulation is the process of deciding what states and actions to consider, given a goal. Ex Storage in an open-floor warehouse Ex Delivery in Reynolds building Search Agent needs to find out which sequence of actions will get it from the current state to a goal state. Search is the process of looking for such a sequence. Y. Xiang, CIS 3700, Introduction to Intelligent Systems 3 Problem Solving Agents simpleproblemsolvingagent(percept) { static actionseq=, state=initstate, goal=null, problemform=null; state = updatestate(state, percept); if actionseq =, do goal = formulategoal(state); problemform = formulateproblem(state, goal); actionseq = Search(problemForm); action = getfirst(actionseq); actionseq = getrest(actionseq); return action; } Y. Xiang, CIS 3700, Introduction to Intelligent Systems 4 1
Environmental Assumptions Assumptions on environment Observable initial state Deterministic Static Discrete Consequence Open-loop system An example No surprises Well-defined Problems in Search Problem definition Initial state Possible actions in terms of a Successor function Successor(state) maps a state to a set of (action, state ) pairs. State space: the set of states reachable from initial state Goal test Path cost (in terms of step cost) A solution is a path from initial state to a goal state. What else are contained in a solution (implicitly)? An optimal solution has the lowest path cost among all solutions. Y. Xiang, CIS 3700, Introduction to Intelligent Systems 5 Y. Xiang, CIS 3700, Introduction to Intelligent Systems 6 Type of Problems Toy problems A concise, exact description can be given. Performance of algorithms can be easily compared. Ex Simple vacuum cleaner, 8-puzzle, etc. Real-world problems Solutions affect people s life. There is no single, precise, and agreed-upon description. Ex Unmanned vehicles, airline scheduling, medical diagnosis, etc. A potential confusion Y. Xiang, CIS 3700, Introduction to Intelligent Systems 7 Search Tree Search tree Root: The initial env state Expand: Apply Successor() to a node to generate its child nodes. Fringe: The set of all leaf nodes Relation to state space A search tree is superimposed over the state space. It may not include all states, unless fully expanded. A given state may reappear in a search tree. Search strategy: Given the current search tree, which leaf node should be expanded next? 8 2
The Idea of Tree Search treesearch(problem, strategy) { set root of search tree to initial state of problem; loop find a leaf x to expand according to strategy; if no qualified leaf is found, return failure; if x corresponds to a goal state, return the corresponding solution; else expand x; add children of x to the search tree; } Y. Xiang, CIS 3700, Introduction to Intelligent Systems 9 River-Crossing Problem A farmer, with a wolf, a sheep, and a cabbage, needs to cross a river using a boat. The boat can carry farmer plus only one other thing. Wolf and sheep cannot be left in the same bank unattended, nor can sheep and cabbage. How can farmer cross river with belongings intact? Step 1: Identify factors affecting rational behavior. Step 2: Identify initial state and goal. Step 3: Find action sequence by treesearch(). Y. Xiang, CIS 3700, Introduction to Intelligent Systems 10 Data Structure for Node on Search Tree Components in node data structure 1. Corresponding env state 2. Parent node on search tree 3. Action that generated this node from its parent 4. Depth: Length of the path from root 5. Path cost from root to the node Data structure of fringe Set Queue Y. Xiang, CIS 3700, Introduction to Intelligent Systems 11 Algorithm for Tree Search treesearch(problem, strategy) { // fringe as queue tree.makerootnode(problem.initialstate); fringe.insert(problem.initialstate); loop if ( fringe.isempty() ) return failure; node = fringe.removefirst(); if ( problem.isgoal(node.getstate()) ) return node.getsolution(); successors = node.expand(problem); tree.addleaves(successors); fringe.insert(successors, strategy); } Y. Xiang, CIS 3700, Introduction to Intelligent Systems 12 3
expand(problem) { // method in class Node successors = ; actionstatepairs = problem.successor(getstate()); for each p in actionstatepairs, do n = new Node(); n.state = p.state; n.action = p.action; n.parent = this; n.depth = this.depth + 1; n.pathcost = this.pathcost + getstepcost(p.action); successors.add(n); return successors; } 13 When Does Agent Test For Goal? Test-Before-Expansion vs Test-At-Expansion Examples of alternative approaches Algorithm comparison Difference in complexity The default Usage of phrases relative to tree nodes Visit Expansion Generation Y. Xiang, CIS 3700, Introduction to Intelligent Systems 14 Measure Problem Solving Performance 1. Completeness: A search algorithm is complete if it guarantees to find a solution when one exists. 2. Optimality: A search algorithm is optimal if it guarantees to find the optimal solution. 3. Time complexity: Time taken to find a solution Measured by max # of nodes generated 4. Space complexity: Memory needed to perform search Measured by max number of nodes stored Efficiency of solution vs efficiency of search Measure Size of Problem Why do we measure the size of a problem? Size of a search problem can be measured by the following parameters of the fully expanded search tree. Branching factor: b Max number of successors of any node Depth of the shallowest goal node: d Max length of any path: m Y. Xiang, CIS 3700, Introduction to Intelligent Systems 15 Y. Xiang, CIS 3700, Introduction to Intelligent Systems 16 4
Search Strategies Search strategy determines the problem solving performance for a given problem. Depending on the amount of agent knowledge, search strategies can be grouped into two broad classes: Uninformed (blind) search strategies Agent has no additional information about states beyond the problem definition. Informed (heuristic) search strategies Agent has knowledge about whether one non-goal state is more promising than another. Breadth-First Search (BFS) BFS strategy Each node at a given depth is expanded before any node at the next level is expanded. Ex 8-puzzle Can be implemented with a FIFO queue for fringe in TreeSearch(). What should fringe.insert(successors, BFS) do? Y. Xiang, CIS 3700, Introduction to Intelligent Systems 17 Y. Xiang, CIS 3700, Introduction to Intelligent Systems 18 Properties of BFS Is BFS complete? Is BFS optimal? What is its time complexity? What is the space complexity? Depth-First Search (DFS) DFS strategy Visit the deepest node in the fringe An example Can be implemented with a LIFO queue (stake) Is DFS complete? Is DFS optimal? What is the time complexity? Y. Xiang, CIS 3700, Introduction to Intelligent Systems 19 Y. Xiang, CIS 3700, Introduction to Intelligent Systems 20 5
Space Complexity of DFS A node can be removed from memory, as soon as all its descendants have been visited. Need to store only a single path from root to a leaf, and unvisited siblings for each node on the path Space complexity How many nodes must be stored in the worst case? Y. Xiang, CIS 3700, Introduction to Intelligent Systems 21 Depth-Limited Search (DLS) Motivation: Avoid being stuck in unbounded branches DLS strategy Depth-first search with a depth limit l Nodes at depth l are treated as having no successors. Is DLS guaranteed to terminate? Space complexity Time complexity Is DLS complete? Is DLS optimal? Summery 22 Iterative Deepening Search (IDS) Motivation: Combine merits from BFS and DFS IDS strategy: Perform DLS with increasing depth limit l = 0, 1, 2,, until a goal node is found. Visiting node x: if x is a goal node, return solution; else if x.depth < l, expand x; else remove x from memory; if x is the last child, rm y=x.parent from memory; if y is the last child, rm z=y.parent from memory; Properties of IDS Is IDS complete? Is IDS optimal? What is its space complexity? What is its time complexity? An example 23 Y. Xiang, CIS 3700, Introduction to Intelligent Systems 24 6
Avoiding Repeated States Causes of repeated states Reversible actions Multiple paths to reach a state from the initial state Tradeoff in checking and deleting repeated nodes: Save time & space for processing repeated subtrees. Need space to store all uniquely generated nodes, and time to check each newly generated node against them. Heuristic Search Strategies General approach: Best-First Search Problem-specific knowledge on the promise of a node n for leading to a goal is expressed with an evaluation function f(n). Expand the leaf with the best f(.) value Convention: The lower the f(.) value, the better. Implementation: Maintain fringe as a queue sorted in ascending order of f(.) values If f(n) is accurate, what properties does it have? Can we always find accurate f(n)? Y. Xiang, CIS 3700, Introduction to Intelligent Systems 25 Y. Xiang, CIS 3700, Introduction to Intelligent Systems 26 Greedy Best-First Search (GBFS) Greedy Best-First Search Define a heuristic function h(n): Estimated cost of the cheapest path from node n to a goal node What should the value of h(n) be if n is a goal node? Define f(n) = h(n) Ex Routing from city A to city B with straight-line distance heuristics Y. Xiang, CIS 3700, Introduction to Intelligent Systems 27 118 75 Area Map A T 71 Z 111 O 140 L 70 M 75 D 151 S 80 R 120 146 C 99 97 138 F P A 366 B 0 C 160 D 242 E 161 F 176 G 77 H 151 101 Y. Xiang, CIS 3700, Introduction to Intelligent Systems 28 G B 90 N Straight-line distance to B 85 87 U I 92 98 V 211 142 H I 226 L 244 M 241 N 234 O 380 P 100 R 193 S 253 T 329 U 80 V 199 Z 374 86 E 7
Evaluation of GBFS Is GBFS optimal? Is GBFS complete? Ex Routing from city I to F Time complexity GBFS behaves similarly to DFS. Space complexity Comparison with DFS Y. Xiang, CIS 3700, Introduction to Intelligent Systems 29 A* Tree Search A* Tree Search Idea: Combine the cost g(n) from root to n, with the cost estimate h(n) from n to a goal node. Define f(n) = g(n)+h(n). What is its interpretation? Ex Routing from city A to B Issue of optimality None of the blind search strategies is optimal. Admissible heuristic Heuristic function h(n) is admissible if h(n) c(n), where c(n) is the minimum path cost from n to a goal node. What is the implication to f(n)? Y. Xiang, CIS 3700, Introduction to Intelligent Systems 30 Optimality of A* Tree Search Theorem: A* is optimal, if h(n) is admissible. Proof idea: 1) C*: cost of optimal solution t : a sub-optimal goal in the current fringe 2) Claim: f(t ) > C* 3) n: a fringe node on the optimal solution path 4) Claim: f(n) C* 5) Claim: t cannot be expanded before n 6) The first goal node visited must be the optimal. Monotonicity of Heuristic Function Monotonic (consistent) heuristic A heuristic function h(n) is monotonic, if for each node n and each child n of n, the following holds: h(n) c(n,n ) + h(n ), [triangle inequality] where c(n,n ) is the step cost from n to n. Ex Is straight-line distance heuristics monotonic? Ex An non-monotonic h(n) Comparison with blind search strategies Y. Xiang, CIS 3700, Introduction to Intelligent Systems 31 Y. Xiang, CIS 3700, Introduction to Intelligent Systems 32 8
Completeness of A* Tree Search Proposition: If h(n) is monotonic, then f(n ) f(n), where n is a child node of n. Observation: If h(n) is monotonic, then A* expands nodes at concentric contours of non-decreasing f(n) values in state space. Theorem: A* tree search is complete, if 1. h(n) is monotonic, 2. each step cost is positive, and 3. the branching factor b is finite. Complexity Time complexity For most problems of interest to AI, the number of nodes within the search space of goal contour is exponential in the length of the solution. Space complexity A* needs to store all nodes expanded. Hence, space and time complexity are the same. Y. Xiang, CIS 3700, Introduction to Intelligent Systems 33 Y. Xiang, CIS 3700, Introduction to Intelligent Systems 34 9