Presentation is loading. Please wait.

Presentation is loading. Please wait.

Searching. COSC 159 - Fundamentals of AI2 Overview Problem-solving agents Example Problems Searching Measuring performance Search strategies Partial Information.

Similar presentations


Presentation on theme: "Searching. COSC 159 - Fundamentals of AI2 Overview Problem-solving agents Example Problems Searching Measuring performance Search strategies Partial Information."— Presentation transcript:

1 Searching

2 COSC 159 - Fundamentals of AI2 Overview Problem-solving agents Example Problems Searching Measuring performance Search strategies Partial Information

3 COSC 159 - Fundamentals of AI3 Problem Solving Agents Goal-based agent Agent Sensors Actuators Environment Percepts Actions What the world is like now What action I should do now Goals What my actions do How the world evolves State What will it be like if I do action A

4 COSC 159 - Fundamentals of AI4 Problem Solving World is made of up discrete states A state is the set of characteristics for the world at a given point in time Actions change the world from one state to another. S1 S2 S3 S4 Left Forward Right

5 COSC 159 - Fundamentals of AI5 Problem Solving Steps Goal formulation Determine state or a set of states that will satisfy the agent’s goal Problem formulation Determine actions and states to consider Search Consider possible sequences of actions from current state Return a solution, a sequence of actions that reaches a goal state In general, would like the best sequence of actions w.r.t. the agent’s performance measure.

6 COSC 159 - Fundamentals of AI6 Problem Solving Agent Program Figure 3.1 page 61

7 COSC 159 - Fundamentals of AI7 Example, Route Finding Consider a system like MapQuest Provide instructions for driving from one location to another Agent perspective Agent simulates driving and identifies best route given performance measure (time, distance, interstates, etc.)

8 COSC 159 - Fundamentals of AI8 Example, Route Finding Agent TypePerformance Measure EnvironmentActuatorsSensors Route Finder Shortest distance, shortest time, most interstate miles and shortest time, etc. Map with roads, speed limits, etc. (Simulated) accelerator, steering, etc. (Simulated) Speedometer, odometer, road identifier, etc.

9 COSC 159 - Fundamentals of AI9 Example, Route Finding

10 COSC 159 - Fundamentals of AI10 Example, Route Finding What are the states of the world? The location of the agent, i.e. the Romanian cities What goal does the agent formulate? To be in Bucharest What is the performance measure? Shortest distance

11 COSC 159 - Fundamentals of AI11 Example, Route Finding What is the problem formulation? States to consider are those between Arad and Bucharest Actions, go to a specific city Must be adjacent to city agent is located in. Search Try all possible paths between Arad and Bucharest Select shortest path

12 COSC 159 - Fundamentals of AI12 Formal Definition of Problems An initial state that the agent starts in. A description of possible actions for the agent from a given state. A successor function, which maps a state to a set of (action, state) pairs A goal test, which determines if a state is a goal state A path cost, which assigns numeric cost to a given path. Optimal solution is one that has the least path cost amongst all solutions

13 COSC 159 - Fundamentals of AI13 Formal Definition for Example Initial state In(Arad) Successor function Maps state to adjacent cities {,, } Goal test state is In(Bucharest) Path cost Sum of distances along driving path

14 COSC 159 - Fundamentals of AI14 Modeling Problems in Java public interface Problem { /** The initial problem state */ public State getInitialState(); /** A function that returns a mapping of actions to * a state given a state. */ public Map successor(State state); /** Return whether or not the state is a goal state */ public boolean goalState(State state); /** Determine the cost of a path */ public Number pathCost(SearchNode node); }

15 COSC 159 - Fundamentals of AI15 When is search a good idea? Static World doesn’t change as agent thinks Observable Assumes initial state is known Discrete Must enumerate courses of action Deterministic Must be able to predict the results of actions

16 COSC 159 - Fundamentals of AI16 More Problems The 8-puzzle

17 COSC 159 - Fundamentals of AI17 Problem Formulation State Location of each tile Could be represented with an ordered list 012 345 678 Position numbers [7,2,4,5,0,6,8,3,1] Keep track of blank location

18 COSC 159 - Fundamentals of AI18 Problem Formulation Initial state Any state can be the initial state Any permutation of 0 through 8 Goal test State = [1,2,3,4,5,6,7,8,0] Path cost Each step costs 1, so total number of steps

19 COSC 159 - Fundamentals of AI19 Problem Formulation Successor function View the blank as movable, so any state reachable by moving blank left, right, up, or down [7,2,4,5,0,6,8,3,1] [7,2,4,0,5,6,8,3,1][7,2,4,5,6,0,8,3,1][7,0,4,5,2,6,8,3,1][7,2,4,5,3,6,8,0,1] L R U D

20 COSC 159 - Fundamentals of AI20 Successor Function b = position of blank; successors = {}; // empty set if (b-1 % 3 != 2) { create new state by swapping state[b] and state[b-1]; add new state to successors; } if (b+1 % 3 != 0) { create new state by swapping state[b] and state[b+1]; add new state to successors; } if (b-3 >= 0) { create new state by swapping state[b] and state[b-3]; add new state to successors; } if (b+3 < 9) { create new state by swapping state[b] and state[b+3]; add new state to successors; } return successors;

21 COSC 159 - Fundamentals of AI21 More Problems The phasor measurement unit (PMU) problem Consider power system graphs (PSGs) Busses (nodes) Lines (edges) PMUs observe characteristics of a PSG for monitoring Place the fewest number of PMUs on a PSG

22 COSC 159 - Fundamentals of AI22 How A PMU Observes a PSG Any bus with a PMU is observed Any line incident with a bus containing a PMU is observed Any bus incident with an observed line is observed Any line between two observed busses is observed If all the lines incident with an observed bus are observed, save one, then all of the lines incident to that bus are observed. These all follow from physical laws.

23 COSC 159 - Fundamentals of AI23 Problem Formulation State Locations of PMUs and which parts of PSG are observed Initial state No PMUs and nothing observed Successor function States obtained by placing a PMU on a node without a PMU Goal test The entire PSG is observed Path cost The number of PMUs placed

24 COSC 159 - Fundamentals of AI24 Searching Problem solving involves searching through the state space The state space is organized with a state tree Start with initial state, then apply successor function repeatedly More generally, we have a search graph, as states can be reached by different paths –8-puzzle: Consider moving blank left and then right

25 COSC 159 - Fundamentals of AI25 Search Nodes Nodes are a data structure with 5 components Action: right Depth: 6 Path-Cost: 6 Parent-Node State

26 COSC 159 - Fundamentals of AI26 Search Nodes public class SearchNode { private SearchNode parent; private State state; private Action action; private int depth; private Number cost; // Include any necessary constructors, access, setter // and other methods needed by the node class. }

27 COSC 159 - Fundamentals of AI27 Tree Search Expand Goal test? Fringe - set of states to be expanded

28 COSC 159 - Fundamentals of AI28 Tree Search A search strategy determines the order in which nodes are expanded Figure 3.8 page 71

29 COSC 159 - Fundamentals of AI29 Organizing the Fringe The fringe is implemented using a queue Actually a priority queue Operations MakeQueue(element, …); // create queue containing elements Empty?(queue); // return true if queue is empty First(queue); // return first element, but leave queued RemoveFirst(queue); // return first element, dequeue Insert(element,queue); // insert in ordered location into queue InsertAll(elements, queue); // insert multiple elements.

30 COSC 159 - Fundamentals of AI30 Tree Search Figure 3.9 page 72

31 COSC 159 - Fundamentals of AI31 Tree Search in Java public class TreeSearch { private PriorityQueue fringe; private Problem problem; /** * Construct a tree search object for the specified problem. */ public TreeSearch(Problem problem, PriorityQueue fringe) { this.problem = problem; this.fringe = fringe; /* Create the root of the search tree */ SearchNode root = new SearchNode(null, // parent problem.getInitialState(), // state null, // action 0, // depth null); // cost fringe.add(root); }

32 COSC 159 - Fundamentals of AI32 Tree Search in Java /** * Carry out the search, returning a collection of * actions to perform. */ public Collection execute() { while (!fringe.isEmpty()) { SearchNode node = fringe.removeFirst(); if (problem.goalState(node)) { return solution(node); } expand(node); } return null; // throw exception instead? }

33 COSC 159 - Fundamentals of AI33 Tree Search in Java /** * Expand the current search node. */ public void expand(SearchNode node) { Map successors; successors = problem.successor(node.getState()); for (Iterator iter = successors.keySet().iterator(); iter.hasNext(); ) { Action act = (Action) iter.next(); State state = (State) successors.get(act); SearchNode newNode = new Node(node, state, act, node.getDepth() + 1); problem.pathCost(newNode); fringe.add(newNode); }

34 COSC 159 - Fundamentals of AI34 Tree Search in Java /** * Return a sequence of actions for the agent to take. */ public Collection solution(SearchNode node) { LinkedList actions = new LinkedList(); while (node != null) { actions.addFirst(node.getAction()); node = node.getParent(); } return actions; }

35 COSC 159 - Fundamentals of AI35 Measuring Problem Solving Performance Completeness Is the algorithm guaranteed to find a solution? Optimality Does the strategy find an optimal solution? Time complexity How long does it take to find a solution? Space complexity How much memory is needed to perform the search?

36 COSC 159 - Fundamentals of AI36 Complexity and Big-Oh Read Appendix A. T(n) is the complexity of an algorithm. O(f(n)) is defined by T(n) is O(f(n)) if T(n) n 0 What this means is that the growth in time (or space) complexity is bounded above by some constant times f(n).

37 COSC 159 - Fundamentals of AI37 Complexity and Big-Oh Example If T(n) = 2n + 2, then T(n) is O(n) using k = 3 and n 0 = 2. Use O() to say something about long term behavior of algorithms O(n) is always better than O(n 2 ) as n approaches infinity.

38 COSC 159 - Fundamentals of AI38 Complexity and Search What is n for search strategies? Usually a measure of the search tree/graph size Search tree size is measured by b, the branching factor, the maximum number of successors of any node d, the depth of the shallowest goal node m, the maximum length of any path

39 COSC 159 - Fundamentals of AI39 Complexity Time complexity is in terms of the number of nodes expanded Space complexity is in terms of the maximum number of nodes stored in memory

40 COSC 159 - Fundamentals of AI40 Cost Search cost, which is generally time complexity but may also include space complexity Total cost, which is the search cost plus the path cost of the solution

41 COSC 159 - Fundamentals of AI41 Search Strategy An uninformed strategy is given no information other than the problem definition. The algorithms are given no insight into the structure of the problem All non-goal states are equal Informed strategies take advantage of additional a priori knowledge of the problem Identify more promising non-goal states. Heuristics, pruning, …

42 COSC 159 - Fundamentals of AI42 Uninformed Search Strategies Breadth-first search Uniform-cost search Depth-first search Depth-limited search Iterative deepening search Bidirectional search

43 COSC 159 - Fundamentals of AI43 Breadth First Search Fringe is organized in FIFO queue 1 234 56 1 2

44 COSC 159 - Fundamentals of AI44 Breadth First Search Complete? Yes Optimal? Finds shallowest goal node. Only if step costs are all the same Time complexity? O(b d+1 ) Space complexity? O(b d+1 )

45 COSC 159 - Fundamentals of AI45 Uniform Cost Search Order fringe by increasing path cost A S 140T 118Z 75 O 141A 150 A Z 75

46 COSC 159 - Fundamentals of AI46 Uniform Cost Search Complete? Yes, if each step costs is at least e > 0 Optimal? Yes, as above Time complexity? O(b c ), where C is cost of optimal solution c = ceil(C/e) c could be larger than d! Space complexity? O(b c )

47 COSC 159 - Fundamentals of AI47 Depth First Search Fringe organized in descending order of depth (i.e. deepest node first) A S 140T 118Z 75 R 220F 239 A S140

48 COSC 159 - Fundamentals of AI48 Depth First Search Complete? No. Optimal? No. Time complexity? O(b m ) Space complexity? O(bm)

49 COSC 159 - Fundamentals of AI49 Depth First Search Can reduce memory using backtracking Store only one successor at a time Go back if path fails and generate next successor Feasible if actions can be easily undone Good for problems with large state descriptions.

50 COSC 159 - Fundamentals of AI50 Depth-limited search Organize as depth first, but limit the depth in the tree searched to level l Depth-first is when l is infinity Complete? Only if l >= d Optimal Only if l = d Time O(b l ) Space O(bl)

51 COSC 159 - Fundamentals of AI51 Iterative Deepening Search Execute depth limited search for l = 1, 2, 3, … Complete? Yes Optimal Yes, if step costs the same Time Complexity?

52 COSC 159 - Fundamentals of AI52 Time Complexity of IDS Derived on the board. N(IDS) = (d)b + (d-1)b 2 + …+(1)b d N(BFS) = b + b 2 + … + b d + (b d+1 -b) Time complexity O(b d ) Space complexity O(bd)

53 COSC 159 - Fundamentals of AI53 Bidirectional Search Search both forward and backward Need to have a predecessor function Complete Yes, if BFS used Optimal Yes, with identical step costs and BFS used Time O(b d/2 ) Space O(b d/2 )

54 COSC 159 - Fundamentals of AI54 Repeated States Repeated states can turn a linear problem into an exponential one!

55 COSC 159 - Fundamentals of AI55 Graph Search States are open (not visited) or closed (visited)

56 COSC 159 - Fundamentals of AI56 Graph Search Uses more memory Proportional to size of state space DFS and IDS no longer linear space Implement closed list with hash table Could lose optimality Could arrive at a state by a more expensive path Particularly a problem with IDS

57 COSC 159 - Fundamentals of AI57 Partial Information Sensorless problems Agent doesn’t know initial state Each action could lead to several possible successor states Contingency problems Partially observable environments Nondeterministic actions Exploration States and actions are unknown

58 COSC 159 - Fundamentals of AI58 Sensorless Problems The initial state of the agent is completely unknown One of several possible states Agent knows available actions, but can’t see results. Can we still design an agent that performs rationally?

59 COSC 159 - Fundamentals of AI59 View sets of states as a single world state. Senseless Monkey Down

60 COSC 159 - Fundamentals of AI60 Exercise (in class) Draw the complete state diagram for the senseless monkey. Ignore sleep action.

61 COSC 159 - Fundamentals of AI61 Answer D U E U E E E E U U U U D D D D D E U,E D,E D D U,E U

62 COSC 159 - Fundamentals of AI62 Sensorless Problems A set of states in the sensorless problem is a goal state if every state in the set is a goal state In general, if the original state space has S states, the sensorless state space has 2 S possible states (power set). Not all may be reachable though.

63 COSC 159 - Fundamentals of AI63 Contingency Problems Information is gained from sensors after acting Example: Lawn environment. Mower doesn’t know locations of all obstacles. Formulate action sequences like [Counter, if (Obstacle) then Counter else Forward, …] Handled with planning (Chapter 12).

64 COSC 159 - Fundamentals of AI64 Summary Represent problems in search spaces Nodes represent physical states Edges represent actions taken Problems have 4 components Initial state Description of actions (successor function) Goal Test Path cost (e.g., via step cost per action)

65 COSC 159 - Fundamentals of AI65 Summary Search strategies defined by the order fringe nodes are expanded Priority queue In general, iterative deepening is best approach However, should study characteristics of each problem to select best strategy Sensorless problems can be solved by mapping to sets of physical states


Download ppt "Searching. COSC 159 - Fundamentals of AI2 Overview Problem-solving agents Example Problems Searching Measuring performance Search strategies Partial Information."

Similar presentations


Ads by Google