460 likes | 651 Views
CS 416 Artificial Intelligence. Lecture 3 Uninformed Searches. Romania. On holiday in Romania; currently in Arad. Flight leaves tomorrow from Bucharest at 1:00. Let’s configure this to be an AI problem. Romania. What’s the problem? Accomplish a goal Reach Bucharest by 1:00
E N D
CS 416Artificial Intelligence Lecture 3 Uninformed Searches
Romania • On holiday in Romania; currently in Arad. • Flight leaves tomorrow from Bucharest at 1:00. • Let’s configure this to be an AI problem.
Romania • What’s the problem? • Accomplish a goal • Reach Bucharest by 1:00 • So this is a goal-based problem
Romania • Is there more to it? • Do it well… according to a performance measure • Minimize distance traveled
Romania • What’s an example of a non-goal-based problem? • Live long and prosper • Maximize the happiness of your trip to Romania • Don’t get hurt too much
Romania • What qualifies as a solution? • You can/cannot reach Bucharest by 1:00 • You can reach Bucharest in x hours • The shortest path to Bucharest passes through these cities • The sequence of cities in the shortest path from Arad to Bucharest is ________ • The actions one takes to travel from Arad to Bucharest along the shortest path
Romania • What additional information does one need? • A map
State Space • Real world is absurdly complex state space must be abstracted for problem solving • (Abstract) state = set of real states • (Abstract) action = complex combination of real actions, e.g., “AradZerind” represents a complex set of possible routes, detours, rest stops, etc. • (Abstract) solution = set of real paths that are solutions in the real world • Each abstract action should be “easier” than the original problem and should permit expansion to a more detailed solution
Important notes about this example • Static environment (available states, successor function, and cost functions don’t change) • Observable (the agent knows where it is… percept == state) • Discrete (the actions are discrete) • Deterministic (successor function is always the same)
Problem Solving Agents • Restricted form of general agent: • function SIMPLE-PROBLEM-SOLVING-AGENT(percept) returns an action • static: seq, an action sequence, initially empty • state, some description of the current world state • goal, a goal, initially null • problem, a problem definition • state <- UPDATE-STATE(state, percept) • ifseq is empty then • goal <- FORMULATE-GOAL(state) • problem <- FORMULATE-PROBLEM(state, goal) • seq <- SEARCH(problem) • action <- RECOMMENDATION(seq, state) • seq <- REMAINDER(seq, state) • returnaction
Vacuum world example • Floor has two locations • Vacuum can move from one location to the other • Locations are clean/dirty • Vacuum can clean the location in which it is • Clean the floor
States: Integer dirt and robot locations (ignore dirt amounts) Actions: Left, Right, Suck, NoOp Goal test: No dirt Path cost: 1 per action (0 for NoOp) Example: Vacuum World state space graph
Example: Vacuum World state space graph • States? Actions? Goal test? Path cost?
Other Examples • Fifteen Puzzle • Robotic Assembly • Traveling Salesman • Protein Design
Tree Search Algorithms • Basic idea: • Simulated exploration of state space by generating successors of already explored states (AKA expanding states) function TREE-SEARCH(problem, strategy) returns a solution, or failure initialize the search tree using the initial state of problem loop do if there are no more candidates for expansion then return failure choose a leaf node for expansion according to strategy if the node contains a goal state then return the corresponding solution else expand the node and add the resulting nodes to the search tree end
Example: Arad Bucharest function TREE-SEARCH(problem, strategy) returns a solution, or failure initialize the search tree using the initial state of problem loop do if there are no more candidates for expansion then return failure choose a leaf node for expansion according to strategy if the node contains a goal state then return the corresponding solution else expand the node and add the resulting nodes to the search tree end
Example: Arad Bucharest function TREE-SEARCH(problem, strategy) returns a solution, or failure initialize the search tree using the initial state of problem loop do if there are no more candidates for expansion then return failure choose a leaf node for expansion according to strategy if the node contains a goal state then return the corresponding solution else expand the node and add the resulting nodes to the search tree end
Example: Arad Bucharest function TREE-SEARCH(problem, strategy) returns a solution, or failure initialize the search tree using the initial state of problem loop do if there are no more candidates for expansion then return failure choose a leaf node for expansion according to strategy if the node contains a goal state then return the corresponding solution else expand the node and add the resulting nodes to the search tree end
Example: Arad Bucharest function TREE-SEARCH(problem, strategy) returns a solution, or failure initialize the search tree using the initial state of problem loop do if there are no more candidates for expansion then return failure choose a leaf node for expansion according to strategy if the node contains a goal state then return the corresponding solution else expand the node and add the resulting nodes to the search tree end
Example: Arad Bucharest function TREE-SEARCH(problem, strategy) returns a solution, or failure initialize the search tree using the initial state of problem loop do if there are no more candidates for expansion then return failure choose a leaf node for expansion according to strategy if the node contains a goal state then return the corresponding solution else expand the node and add the resulting nodes to the search tree end
Example: Arad Bucharest function TREE-SEARCH(problem, strategy) returns a solution, or failure initialize the search tree using the initial state of problem loop do if there are no more candidates for expansion then return failure choose a leaf node for expansion according to strategy if the node contains a goal state then return the corresponding solution else expand the node and add the resulting nodes to the search tree end
Example: Arad Bucharest function TREE-SEARCH(problem, strategy) returns a solution, or failure initialize the search tree using the initial state of problem loop do if there are no more candidates for expansion then return failure choose a leaf node for expansion according to strategy if the node contains a goal state then return the corresponding solution else expand the node and add the resulting nodes to the search tree end
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!
Implementation: general tree search function TREE-SEARCH (problem, fringe) returns a solution, or failure fringe INSERT(MAKE-NODE(INITIAL-STATE[problem]), fringe) loop do if fringe is empty then return false node REMOVE-FRONT(fringe) if GOAL-TEST[problem] applied to STATE(node) succeeds returnnode fringe INSERTALL(EXPAND(node, problem), fringe) function EXPAND (node, problem) returns a set of states successors the empty set for each action, resultin SUCCESSOR-FN[problem](STATE[node]) do s a new NODE PARENT-NODE[s] node; ACTION[s] action; STATE(s) result PATH-COST[s] PATH-COST[node] + STEP-COST(node, action, s) DEPTH[s] DEPTH[node] + 1 add s to successors return successors Find the error on this page!
Search strategies • A strategy is defined by picking the order of node expansion • Strategies are evaluated along the following dimensions: • Completeness – does it always find a solution if one exists? • Time complexity – number of nodes generated/expanded • Space complexity – maximum nodes in memory • Optimality – does it always find a least cost solution? • Time and space complexity 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 infinite)
Uninformed Search Strategies • Uninformed strategies use only the information available in the problem definition • Breadth-first search • Uniform-cost search • Depth-first search • Depth-limited search • Iterative deepening search
Breadth-first search • Expand shallowest unexpanded node • Implementation: • Fringe is a FIFO queue, i.e., new successors go at end • Execute first few expansions of Arad to Bucharest using Breadth-first search
Computation cost of BFS Level Nodes 1 0 1 b 2 b2 3 b3
Computation cost of BFS Level Nodes • If goal is in d = level 2 • Cost = 1 + b + b2 + b3 – b = O (bd+1) 1 0 1 b 2 b2 3 b3
Computation cost of BFS • Cost = 1 + b + b2 + b3 – b = O (bd+1) • Big Oh Notation • There exist positive constants: c, b0, d0 such thatfor all b >= b0 and d >= d0 Figure 2.1 from Cormen, Leiserson, Rivest
Space cost of BFS • Because you must be able to generate the path upon finding the goal state, all visited states must be stored
Properties of breadth-first search • Complete?? Yes (if b (max branch factor) is finite) • Time?? 1 + b + b2 + … + bd + b(bd-1) = O(bd+1), i.e., exponential in d • Space?? O(bd+1) (keeps every node in memory) • Optimal?? Only if cost = 1 per step, otherwise not optimal in general • Space is the big problem; can easily generate nodes at 10 MB/s, so 24hrs = 860GB!
Uniform-first search • Expand least-cost unexpanded node • Implementation: • Fringe is a queue ordered by cost • Execute first few expansions of Arad to Bucharest using Breadth-first search
Uniform-cost search • Complete?? If step cost ≥ε • Time?? • If all costs are equal = O (bd) • Space?? O(bC/ ε) • Optimal?? Yes–nodes expanded in increasing order of g(n)
Depth-first search • Expand deepest unexpanded node • Implementation: • Fringe = LIFO queue, i.e., a stack • Execute first few expansions of Arad to Bucharest using Depth-first search
Depth-first search • Complete?? • Time?? • Space?? • Optimal??
Depth-first search • Complete?? • No: fails in infinite-depth spaces, spaces with loops. • Can be modified to avoid repeated states along path complete in finite spaces • Time?? • O(bm): terrible if m is much larger than d, but if solutions are dense, may be much faster than breadth-first • Space?? • O(bm), i.e., linear space! • Optimal?? • No
Depth-limited search • Depth-first search with depth limit l • i.e., nodes at depth l have no successors
Iterative deepening search function ITERATIVE-DEEPENING-SEARCH(problem) returns a solution inputs: problem, a problem for depth 0 to∞ do result DEPTH-LIMITED-SEARCH(problem, depth) ifresult ≠ cutoffthen returnresult end
Properties of iterative deepening • Complete?? • Yes • Time?? • (d+1)b0 + db1 + (d-1)b2 + … bd = O(bd) • Space?? • O(bd) • Optimal?? • If step cost = 1 • Can be modified to explore uniform-cost tree
Summary • All tree searching techniques are more alike than different • Breadth-first has space issues, and possibly optimality issues • Uniform-cost has space issues • Depth-first has time and optimality issues, and possibly completeness issues • Depth-limited search has optimality and completeness issues • Iterative deepening is the best uninformed search we have explored • Next class we study informed searches