Presentation is loading. Please wait.

Presentation is loading. Please wait.

Solving Problems by Searching

Similar presentations


Presentation on theme: "Solving Problems by Searching"— Presentation transcript:

1 Solving Problems by Searching
CMPT 420 / CMPG 720

2 Outline Problem-solving agents Example problems
Basic search algorithms

3 Problem-Solving Agents
Intelligent agents are supposed to maximize their performance measure. If the agent can adopt a goal and aim at satisfying it.

4 Example: Traveling in Romania
On holiday in Romania; currently in Arad. Flight leaves tomorrow from Bucharest

5 Problem-Solving Agents
Goal formulation, based on the current situation and the agent’s performance measure, is the first step in problem solving. Problem formulation is the process of deciding what actions and states to consider, given a goal. The process of looking for a sequence of actions that reaches the goal is search. Execution phase: once a solution is found, the actions it recommended can be carried out. “formulate, search , execute” design

6 Example: Traveling in Romania
Formulate goal: be in Bucharest Formulate problem: states: various cities action: drive between cities Find solution: sequence of cities: e.g., Arad, Sibiu, Fagaras, Bucharest

7 Example: Romania

8 Problem Formulation A problem is defined by five components.
Initial state e.g., “at Arad” Actions (s)  {a1, a2, a3, … } e.g., {Go(Sibiu), Go(Timisoara), Go(Zerind)} Transition model: Result (s,a)  s’ e.g., Result(In(Arad), Go(Timisoara)) = In(Timisoara) Goal test (s)  T/F e.g., “at Bucharest” Path cost (sss)  n (additive) sum of cost of individual steps, e.g., number of miles traveled, number of minutes to get to destination

9 Problem Formulation A solution is a sequence of actions from initial to goal state. Optimal solution has the lowest path cost.

10 Example: Vacuum World states? initial state? actions?
transition model? goal test? path cost?

11 states? location and dirt, 2*22=8, n*2n
initial state? actions? transition model? goal test? path cost?

12 states? location and dirt, 2*22=8, n*2n
initial state? any state actions? transition model? goal test? path cost?

13 states? location and dirt, 2*22=8, n*2n
initial state? any state actions? Left, Right, Suck transition model? goal test? path cost?

14 states? location and dirt, 2*22=8, n*2n
initial state? any state actions? Left, Right, Suck transition model? goal test? no dirt at all locations path cost? 1 per action

15 Example: The 8-Puzzle Online 8-puzzle game:

16 Example: The 8-Puzzle states? initial state? actions?
transition model? goal test? path cost?

17 initial state? any state (mixed-up) actions?
states? A state description specifies the location of the eight tiles and the blank one. initial state? any state (mixed-up) actions? naive answer: move piece at square (x1,x2) to square (y1,y2): lots of operations movement of the blank space: Left, Right, Up, Down

18 states? A state description specifies the location of the eight tiles and the blank one.
initial state? any state (mixed-up) actions? movement of the blank space: Left, Right, Up, Down transition model? goal test? path cost?

19 states? A state description specifies the location of the eight tiles and the blank one.
initial state? any state (mixed-up) actions? movement of the blank space: Left, Right, Up, Down transition model? (s,a)s’ goal test? path cost?

20 Example: 8-puzzle 1 2 3 4 5 6 7 8

21 states? A state description specifies the location of the eight tiles and the blank one.
initial state? any state (mixed-up) actions? movement of the blank space: Left, Right, Up, Down transition model? (s,a)s’ goal test? path cost?

22 states? A state description specifies the location of the eight tiles and the blank one.
initial state? any state (mixed-up) actions? movement of the blank space: Left, Right, Up, Down transition model? (s,a)s’ goal test? goal state (given) path cost?

23 states? A state description specifies the location of the eight tiles and the blank one.
initial state? any state (mixed-up) actions? movement of the blank space: Left, Right, Up, Down transition model? (s,a)s’ goal test? goal state (given) path cost? 1 per move

24 Example: The 8-Puzzle Eight puzzle is from a family of “sliding –block puzzles” (n2-1)-puzzle

25 15-Puzzle Sam Loyd, who called himself “America’s greatest puzzler”
offered $1,000 of his own money to the first person who would solve the following problem:

26

27 (n2-1)-puzzle NP Complete
8 puzzle has 9! = 362,880 states (0.36 sec with 10 million states/sec) 15 puzzle has approx. 1.3*1012 states (6 days) 24 puzzle has approx. 1*1025 states (12 billion years)

28 Example: 8-Queens Place 8 queens in a chessboard such that no queen can attack another queen: no two queens are in the same row, column, or diagonal. A solution Not a solution

29 The 8-Queens Problem states? initial state? actions? transition model?
goal test? path cost?

30 states? initial state? actions? transition model? goal test?
Incremental formulation vs. Complete state formulation states? initial state? actions? transition model? goal test? path cost?

31 states? Any arrangement of 0 to 8 queens initial state? actions?
Incremental formulation vs. Complete state formulation states? Any arrangement of 0 to 8 queens initial state? actions? transition model? goal test? path cost?

32 states? Any arrangement of 0 to 8 queens
Incremental formulation vs. Complete state formulation states? Any arrangement of 0 to 8 queens initial state? No queens on the board actions? transition model? goal test? path cost?

33 states? Any arrangement of 0 to 8 queens
Incremental formulation vs. Complete state formulation states? Any arrangement of 0 to 8 queens initial state? No queens on the board actions? Add a queen to any empty square transition model? goal test? path cost?

34 states? Any arrangement of 0 to 8 queens
Incremental formulation vs. Complete state formulation states? Any arrangement of 0 to 8 queens initial state? No queens on the board actions? Add a queen to any empty square transition model? Return the board with a queen added goal test? path cost?

35 states? Any arrangement of 0 to 8 queens
Incremental formulation vs. Complete state formulation states? Any arrangement of 0 to 8 queens initial state? No queens on the board actions? Add a queen to any empty square transition model? Return the board with a queen added goal test? 8 queens, none attacked path cost?

36 states? Any arrangement of 0 to 8 queens
Incremental formulation vs. Complete state formulation states? Any arrangement of 0 to 8 queens initial state? No queens on the board actions? Add a queen to any empty square transition model? Return the board with a queen added goal test? 8 queens, none attacked path cost? no interest because only the final state counts

37 The 8-Queens Problem

38 The 8-Queens Problem (N-Queens?) 64*63*…*57 ~= 1.8*1014 Ouch!!

39 The 8-Queens Problem (N-Queens?)
64*63*…*57 ~= 1.8*1014 Ouch!! Formulation #2 (better): states: All possible arrangement of n queens, one per column in the leftmost n columns, with no queen attacking another. (0<=n<=8) actions: Add a queen to any square in the leftmost empty column such that it is not attacked by any other queen. 2057 sequences to investigate

40 Donald Knuth (1964): starting with the number 4, a sequence of factorial, square root, and floor operation will reach any desired positive integer. states? Positive numbers initial state? 4 actions? Apply factorial, square root, or floor operation

41 transition model? definition of the operations
goal test? desired positive integer path cost? number of operations How large a number might be generated to reach the goal! 620,448,401,733,239,439,360,000

42 Real-World Problems Route-finding problem Touring problems
e.g., visit every city in the Romania example at least once, starting and ending in Bucharest. Traveling salesman problem (TSP) each city must be visited exactly once shortest tour Robot Navigation VLSI layout ...

43 Searching For Solutions
Having formulated some problems…how do we solve them? Assumptions in basic search The world is static ƒ The world is discreteƒ The world is fully-observable

44 Searching For Solutions
Having formulated some problems…how do we solve them? Search through a state space Use a search tree that is generated with an initial state and successor functions that define the state space

45 Example: 8-puzzle 1 2 3 4 5 6 7 8

46 Tree Search Algorithms
search tree: initial state as the root, the branches as actions and the nodes as states. We expand the current state and generate a new set of states. parent node, child nodes leaf node: a node with no children (frontier) search strategy: how to choose which state to expand next repeated state, redundant paths

47 Example: Romania

48 Tree Search Example The initial state

49 Tree Search Example After expanding Arad

50 Tree Search Example After expanding Sibiu

51 Graph Search Algorithm
explored set (closed list): remembers every expanded node Newly generated nodes that are in the explored set are discarded. The frontier separates the explored region and the unexplored region.

52 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 state, parent node, action, path cost g(x), depth

53 Data Structure For each node n, n.State n.Parent
n.Action: parent generated the node n.Path-Cost

54 Data Structure Frontier: queue Explored set: array, list, etc..
FIFO, LIFO, priority Empty? (queue) : T/F Pop (queue) Push (queue) Explored set: array, list, etc..

55 Comparing Uninformed Search Strategies
Completeness Will a solution always be found if one exists? Time How long does it take to find the solution? Often represented as the number of nodes searched Space How much memory is needed to perform the search? Often represented as the maximum number of nodes stored at once Optimal Will the optimal (least cost) solution be found?

56 Comparing Uninformed Search Strategies
Time and space complexity are measured in b – maximum branching factor of the search tree m – maximum depth of the state space d – depth of the least cost solution

57 Uninformed Search Strategies
Uninformed search strategies use only the information available in the problem definition. Also known as blind searching Depth-limited search Iterative deepening search

58 Example: Romania

59 Romania with step costs in km


Download ppt "Solving Problems by Searching"

Similar presentations


Ads by Google