Presentation is loading. Please wait.

Presentation is loading. Please wait.

Problem solving and search

Similar presentations


Presentation on theme: "Problem solving and search"— Presentation transcript:

1 Problem solving and search

2 Objective In which we see how an agent can find a sequence of actions that achieves its goals when no single action will do.

3 Revision Definition of AI? Turing Test? Intelligent Agents:
Anything that can be viewed as perceiving its environment through sensors and acting upon that environment through its effectors to maximize progress towards its goals. PAGE (Percepts, Actions, Goals, Environment) Described as a Perception (sequence) to Action Mapping: f : P* A Using look-up-table, closed form, etc. Agent Types: Reflex, goal-based, utility-based Rational Action: The action that maximizes the expected value of the performance measure given the percept sequence to date

4 Outline Problem-Solving Agents Searching for Solutions
Uninformed Search Strategies Informed Search Strategies Heuristic Functions

5 Problem-Solving Agents
Example: Measuring problem Problem: Using these three buckets, measure 7 liters of water. 9L 5L 3L

6 Example: Measuring problem
One solution 9L a b c Start 3 5L 3L

7 Example: Measuring problem
Another solution 9L a b c Start 5 5L 3L

8 Which solution to choose?
a b c Start 3 6 1 5 7 a b c Start 5 3 2 7

9 Problem-Solving Agents
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 formulation state  Update-State(state, percept) if seq is empty then Goal  Formulate-Goal(state) Problem  Formulate-Problem(state, goal) seq  Search( problem) action  Recommendation(seq, state) seq  Remainder(seq, state) return action Note: this is offline problem solving; solution executed “eyes closed." Online problem solving involves acting without complete knowledge.

10 Example: Buckets Measure 7 liters of water using a 3-liter, a 5-liter, and a 9- liter buckets. Formulate goal: Have 7 liters of water in 9-liter bucket —Formulate problem: States: amount of water in the buckets Operators: Fill bucket from source, empty bucket Find solution: sequence of operators that bring you from current state to the goal state

11 Example: Romania 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, e.g., Arad, Sibiu, Fagaras, Bucharest

12 Example: Romania

13 Problem types Deterministic, fully observable  single-state problem
Agent knows exactly which state it will be in; solution is a sequence Non-observable  conformant problem Agent may have no idea where it is; solution (if any) is a sequence Nondeterministic and/or partially observable  contingency problem percepts provide new information about current state solution is a contingent plan or a policy often interleave search, execution Unknown state space  exploration problem (“online")

14 Example: vacuum world Single-state, start in #5. Solution??

15 Example: vacuum world Single-state, start in #5. Solution?? [Right; Suck] Conformant, start in {1; 2; 3; 4; 5; 6; 7; 8} e.g., Right goes to {2; 4; 6; 8}. Solution??

16 Example: vacuum world Single-state, start in #5. Solution??
[Right; Suck] Conformant, start in {1; 2; 3; 4; 5; 6; 7; 8} e.g., Right goes to {2; 4; 6; 8}. Solution?? [Right; Suck; Left; Suck] Contingency, start in #5 Murphy's Law: Suck can dirty a clean carpet Local sensing: dirt, location only. Solution?? [Right; if dirt then Suck]

17 Problem Formulation A search problem consists of:
A state space A successor function A start state and a goal test A solution is a sequence of actions (a plan) which transforms the start state to a goal state

18 Single-state problem formulation
A problem is defined by four items: initial state e.g., “at Arad" successor function S(x) = set of action-state pairs e.g., S(Arad) = { (Arad  Zerind;Zerindi) … } goal test, can be explicit, e.g., x = “at Bucharest" implicit, e.g., NoDirt(x) path cost (additive) e.g., sum of distances, number of actions executed, etc. c(x, a, y) is the step cost, assumed to be >= 0 A solution is a sequence of actions leading from the initial state to a goal state

19 Selecting a 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., “Arad  Zerind" represents a complex set of possible routes, detours, rest stops, etc. For guaranteed realizability, any real state “in Arad" must get to some real state “in Zerind" (Abstract) solution = set of real paths that are solutions in the real world Each abstract action should be \easier" than the original problem!

20 Example: vacuum world state space graph
Actions?? Goal test?? Path cost??

21 Example: vacuum world state space graph
States?? integer dirt and robot locations (ignore dirt amounts etc.) Actions?? Left, Right, Suck, NoOp Goal test?? no dirt Path cost?? 1 per action (0 for NoOp)

22 Example: The 8-puzzle States?? Actions?? Goal test?? Path cost??

23 Example: The 8-puzzle States?? integer locations of tiles (ignore intermediate positions) Actions?? move blank left, right, up, down (ignore unjamming etc.) Goal test?? = goal state (given) Path cost?? 1 per move

24 Example: The 8-puzzle Why search algorithms?
8-puzzle has 362,880 states 15-puzzle has 10^12 states 24-puzzle has 10^25 states So, we need a principled way to look for a solution in these huge search spaces…

25 Example: robotic assembly
states?? real-valued coordinates of robot joint angles parts of the object to be assembled actions?? continuous motions of robot joints goal test?? complete assembly with no robot included! path cost?? time to execute

26 Search trees A search tree:
This is a “what if” tree of plans and outcomes Start state at the root node Children correspond to successors Nodes labeled with states, correspond to PLANS to those states For most problems, can never build the whole tree So, have to find ways to use only the important parts!

27 Tree search algorithms
Basic idea: offline, simulated exploration of state space by generating successors of already-explored states (a.k.a. expanding states) function TREE-SEARCH(problem, strategy) returns a solution, or failure initialize the frontier using the initial state of problem loop do if the frontier is empty then return failure choose a leaf node for expansion according to strategy if the node contains a goal state then return the corresponding solution expand the chosen node, adding the resulting nodes to the tree end

28 Tree search example

29 Tree search example

30 Tree search example

31 Implementation: states vs. nodes
A state is a (representation of) a physical configuration A node is a 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! The Expand function creates new nodes, filling in the various fields and using the SuccessorFn of the problem to create the corresponding states.

32 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 failure node  Remove-Front(fringe) if Goal-Test(problem,State(node)) then return node fringe  InsertAll(Expand(node, problem), fringe) function Expand( node, problem) returns a set of nodes successors  the empty set for each action, result in 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

33 Evaluation of 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 number of 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 infinity)

34 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

35 Breadth-first search Expand shallowest unexpanded node Implementation:
fringe is a FIFO queue, i.e., new successors go at end

36 Breadth-first search Expand shallowest unexpanded node Implementation:
fringe is a FIFO queue, i.e., new successors go at end

37 Breadth-first search Expand shallowest unexpanded node Implementation:
fringe is a FIFO queue, i.e., new successors go at end

38 Breadth-first search Expand shallowest unexpanded node Implementation:
fringe is a FIFO queue, i.e., new successors go at end

39 Properties of breadth-first search
Complete?? Yes (if b is finite) Time?? 1 + b + b2 + b3 + … + bd + b(bd-1) = O(b1d+), i.e., exp. in d Space?? O(bd+1) (keeps every node in memory) Optimal?? Yes (if cost = 1 per step); not optimal in general Space is the big problem; can easily generate nodes at 100MB/sec so 24hrs = 8640GB. — Search algorithms are commonly evaluated according to the following four criteria: ◦ Completeness: does it always find a solution if one exists? ◦ Time complexity: how long does it take as function of num. of nodes? ◦ Space complexity: how much memory does it require? ◦ Optimality: does it guarantee the least-cost solution? — Time and space complexity are measured in terms of: ◦ b – max branching factor of the search tree ◦ d – depth of the least-cost solution ◦ m – max depth of the search tree (may be infinity)

40 Uniform-cost search Expand least-cost unexpanded node Implementation:
fringe = queue ordered by path cost, lowest first Equivalent to breadth-first if step costs all equal Complete?? Yes, if step cost ≥ ϵ Time?? # of nodes with g ≤ cost of optimal solution, where C* is the cost of the optimal solution Space?? # of nodes with g ≤ cost of optimal solution, Optimal?? Yes -- nodes expanded in increasing order of g(n)

41 Romania with step costs in km

42 Uniform-cost search

43 Uniform-cost search

44 Uniform-cost search

45 Depth-first Search Expand deepest unexpanded node Implementation:
fringe = LIFO queue, i.e., put successors at front

46 Depth-first Search Expand deepest unexpanded node Implementation:
fringe = LIFO queue, i.e., put successors at front

47 Depth-first Search Expand deepest unexpanded node Implementation:
fringe = LIFO queue, i.e., put successors at front

48 Depth-first Search Expand deepest unexpanded node Implementation:
fringe = LIFO queue, i.e., put successors at front

49 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 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

50 Depth-limited search = depth-first search with depth limit l, i.e., nodes at depth l have no successors Recursive implementation: function Depth-Limited-Search( problem, limit) returns soln/fail/cutoff Recursive-DLS(Make-Node(Initial-State[problem]), problem, limit) function Recursive-DLS(node, problem, limit) returns soln/fail/cutoff cutoff-occurred  false if Goal-Test(problem, State[node]) then return node else if Depth[node] = limit then return cutoff else for each successor in Expand(node, problem) do result Recursive-DLS(successor, problem, limit) if result = cutoff then cutoff-occurred? true else if result != failure then return result if cutoff-occurred? then return cutoff else return failure

51 Iterative deepening search
function Iterative-Deepening-Search( problem) returns a solution inputs: problem, a problem for depth 0 to 1 do result  Depth-Limited-Search( problem, depth) if result !== cutoff then return result end

52 Iterative deepening search l = 0

53 Iterative deepening search l = 1

54 Iterative deepening search l = 2

55 Iterative deepening search l = 3

56 Properties of iterative deepening search
Complete?? Yes Time?? (d + 1)b0 + db1 + (d -1)b2 + : : : + bd = O(bd) Space?? O(bd) Optimal?? Yes, if step cost = 1 Can be modified to explore uniform-cost tree Numerical comparison for b = 10 and d = 5, solution at far right leaf: N(IDS) = ; ; ; 000 = 123; 450 N(BFS) = ; ; ; ; 990 = 1; 111; 100 IDS does better because other nodes at depth d are not expanded BFS can be modified to apply goal test when a node is generated

57 Bi-Directional Search
Both search forward from initial state, and backwards from goal. Stop when the two searches meet in the middle.  Problem: how do we search backwards from goal?? predecessor of node n = all nodes that have n as successor this may not always be easy to compute! if several goal states, apply predecessor function to them just as we applied successor (only works well if goals are explicitly known; may be difficult if goals only characterized implicitly).

58 Bi-Directional Search
Problem: how do we search backwards from goal?? (cont.) ◦ … ◦ for bidirectional search to work well, there must be an efficient way to check whether a given node belongs to the other search tree. select a given search algorithm for each half.

59 Bi-Directional Search
Queue 1 : path only containing the root Queue 2 : path only containing the goal While both queues are not empty and both queues do not share a state Do remove their first paths create their new paths (to all children); reject their new paths with loops; add their new paths to back; IF QUEUE1 and QUEUE2 share a state Then success Else failure

60 Bi-Directional Search
Completeness: Yes, Time complexity: *O(b d/2) = O(b d/2) Space complexity: O(b d/2) Optimality: Yes  To avoid one by one comparison, we need a hash table of size O(b d/2) If hash table is used, the cost of comparison is O(1)

61 Bi-Directional Search

62 Bi-Directional Search
— Bidirectional search merits: ◦ Big difference for problems with branching factor b in both directions – A solution of length d will be found in O(2bd/2) = O(bd/2) – For b = 10 and d = 6, only 2,222 nodes are needed instead of 1,111,111 for breadth-first search

63 Bi-Directional Search
— Bidirectional search issues ◦ Predecessors of a node need to be generated – Difficult when operators are not reversible ◦ What to do if there is no explicit list of goal states? ◦ For each node: check if it appeared in the other search – Needs a hash table of O(bd/2) ◦ What is the best search strategy for the two searches?

64 Comparison

65 Repeated states Failure to detect repeated states can turn a linear problem into an exponential one!

66 Graph Search

67 Graph Search In BFS we shouldn’t bother expanding the filled-out nodes (why?)

68 Summary Problem formulation usually requires abstracting away real-world details to define a state space that can feasibly be explored Variety of uninformed search strategies Iterative deepening search uses only linear space and not much more time than other uninformed algorithms Graph search can be exponentially more efficient than tree search


Download ppt "Problem solving and search"

Similar presentations


Ads by Google