september 26, 2012introduction to artificial intelligence lecture 7: search in state spaces i 1...

28
September 26, 2012 Introduction to Artificial Intelligence Lecture 7: Search in 1 After our “Haskell in a Nutshell” excursion, let us move on to Search in State Spaces

Upload: shon-cameron

Post on 16-Dec-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: September 26, 2012Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I 1 After our “Haskell in a Nutshell” excursion, let us move

Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I

1September 26, 2012

After our“Haskell in a Nutshell”

excursion,

let us move on to

Search in State Spaces

Page 2: September 26, 2012Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I 1 After our “Haskell in a Nutshell” excursion, let us move

Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I

2September 26, 2012

Search in State Spaces

• Many problems in Artificial Intelligence can be mapped onto searches in particular state spaces.

• This concept is especially useful if the system (our “world”) can be defined as having a finite number of states, including an initial state and one or more goal states.

• Optimally, there are a finite number of actions that we can take, and there are well-defined state transitions that only depend on our current state and current action.

Page 3: September 26, 2012Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I 1 After our “Haskell in a Nutshell” excursion, let us move

Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I

3September 26, 2012

Search in State Spaces• To some extent, it is also possible to account for

state changes that the algorithm itself does not initiate.

• For example, a chess playing program can consider its opponent’s future moves.

• However, it is necessary that the set of such actions and their consequences are well-defined.

• While computers are able to play chess at a very high level, it is impossible these days to build a robot that, for instance, is capable of reliably carrying out everyday tasks such as going to a supermarket to buy groceries.

Page 4: September 26, 2012Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I 1 After our “Haskell in a Nutshell” excursion, let us move

Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I

4September 26, 2012

Search in State Spaces

Let us consider an easy task in a very simple world with our robot being the only actor in it:• The world contains a floor and three toy blocks labeled A, B, and C.• The robot can move a block (with no other block on top of it) onto the floor or on top of another block.• These actions are modeled by instances of a schema, move(x, y).• Instances of the schema are called operators.

Page 5: September 26, 2012Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I 1 After our “Haskell in a Nutshell” excursion, let us move

Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I

5September 26, 2012

Search in State Spaces

• The robot’s task is to stack the toy blocks so that A is on top of B, B is on top of C, and C is on the floor.

• For us it is clear what steps have to be taken to solve the task.

• The robot has to use its world model to find a solution.

• Let us take a look at the effects that the robot’s actions exert on its world.

Page 6: September 26, 2012Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I 1 After our “Haskell in a Nutshell” excursion, let us move

Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I

6September 26, 2012

Search in State Spaces

Effects of moving a block (illustration and list-structure iconic model notation)

Page 7: September 26, 2012Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I 1 After our “Haskell in a Nutshell” excursion, let us move

Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I

7September 26, 2012

Search in State Spaces

• In order to solve the task efficiently, the robot should “look ahead”, that is, simulate possible actions and their outcomes.

• Then, the robot can carry out a sequence of actions that, according to the robot’s prediction, solves the problem.

• A useful structure for such a simulation of alternative sequences of action is a directed graph.

• Such a graph is called a state-space graph.

Page 8: September 26, 2012Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I 1 After our “Haskell in a Nutshell” excursion, let us move

Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I

8September 26, 2012

State-Space Graphs

Page 9: September 26, 2012Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I 1 After our “Haskell in a Nutshell” excursion, let us move

Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I

9September 26, 2012

State-Space Graphs• To solve a particular problem, the robot has to find

a path in the graph from a start node (representing the initial state) to a goal node (representing a goal state).

• The resulting path indicates a sequence of actions that solves the problem.

• The sequence of operators along a path to a goal is called a plan.

• Searching for such a sequence is called planning.• Predicting a sequence of world states from a

sequence of actions is called projecting.

Page 10: September 26, 2012Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I 1 After our “Haskell in a Nutshell” excursion, let us move

Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I

10September 26, 2012

State-Space Graphs• There are various methods for searching state

spaces.• One possibility is breadth-first search:

– Mark the start node with a 0.– Mark all adjacent nodes with 1.– Mark all unmarked nodes adjacent to nodes

with a 1 with the number 2, and so on, until you arrive at a goal node.

– Finally, trace a path back from the goal to the start along a sequence of decreasing numbers.

Page 11: September 26, 2012Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I 1 After our “Haskell in a Nutshell” excursion, let us move

Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I

11September 26, 2012

Decision Trees

A decision tree is a special case of a state-space graph.

It is a rooted tree in which each internal node corresponds to a decision, with a subtree at these nodes for each possible outcome of the decision.

Decision trees can be used to model problems in which a series of decisions leads to a solution.

The possible solutions of the problem correspond to the paths from the root to the leaves of the decision tree.

Page 12: September 26, 2012Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I 1 After our “Haskell in a Nutshell” excursion, let us move

Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I

12September 26, 2012

Decision Trees

Example: The n-queens problem

How can we place n queens on an nn chessboard so that no two queens can capture each other?

QQ

x

x

x

x

x

x

xx

x

xx

x

x

x

xx

x

x

x

xx

x

x

x

x

x

x

A queen can move any number of squares horizontally, vertically, and diagonally.

Here, the possible target squares of the queen Q are marked with an x.

Page 13: September 26, 2012Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I 1 After our “Haskell in a Nutshell” excursion, let us move

Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I

13September 26, 2012

Decision TreesLet us consider the 4-queens problem.

Question: How many possible configurations of 44 chessboards containing 4 queens are there?

Answer: There are 16!/(12!4!) = (13141516)/(234) = 13754 = 1820 possible configurations.

Shall we simply try them out one by one until we encounter a solution?

No, it is generally useful to think about a search problem more carefully and discover constraints on the problem’s solutions.

Such constraints can dramatically reduce the size of the relevant state space.

Page 14: September 26, 2012Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I 1 After our “Haskell in a Nutshell” excursion, let us move

Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I

14September 26, 2012

Decision TreesObviously, in any solution of the n-queens problem, there must be exactly one queen in each column of the board.

Otherwise, the two queens in the same column could capture each other.

Therefore, we can describe the solution of this problem as a sequence of n decisions:

Decision 1: Place a queen in the first column.Decision 2: Place a queen in the second column.…Decision n: Place a queen in the n-th column.

This way, “only” 256 configurations need to be tested.

Page 15: September 26, 2012Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I 1 After our “Haskell in a Nutshell” excursion, let us move

Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I

15September 26, 2012

Backtracking in Decision Trees

• There are problems that require us to perform an exhaustive search of all possible sequences of decisions in order to find the solution.

• We can solve such problems by constructing the complete decision tree and then find a path from its root to a leave that corresponds to a solution of the problem (breadth-first search often requires the construction of an almost complete decision tree).

• In many cases, the efficiency of this procedure can be dramatically increased by a technique called backtracking (depth-first search with “sanity checks”).

Page 16: September 26, 2012Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I 1 After our “Haskell in a Nutshell” excursion, let us move

Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I

16September 26, 2012

Backtracking in Decision Trees

Idea: Start at the root of the decision tree and move downwards, that is, make a sequence of decisions, until you either reach a solution or you enter a situation from where no solution can be reached by any further sequence of decisions.

In the latter case, backtrack to the parent of the current node and take a different path downwards from there. If all paths from this node have already been explored, backtrack to its parent.

Continue this procedure until you find a solution or establish that no solution exists (there are no more paths to try out).

Page 17: September 26, 2012Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I 1 After our “Haskell in a Nutshell” excursion, let us move

Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I

17September 26, 2012

Backtracking in Decision Trees

Q

Q

Q

Q

Q

Q

Q

Q

Q

Q

Q

Q

Q

Q

Q

Q

Q

Q

place 1st queen

place 2nd queen

place 3rd queen

place 4th queen

empty board

Page 18: September 26, 2012Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I 1 After our “Haskell in a Nutshell” excursion, let us move

Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I

18September 26, 2012

Breadth-First vs. Depth-FirstUninformed breadth-first search:• Requires the construction and storage of almost the

complete search tree.® Space complexity for search depth n is O(en).

• Is guaranteed to find the shortest path to a solution.

Uninformed depth-first search:• Requires the storage of only the current path and

the branches from this path that were already visited.

® Space complexity for search depth n is O(n).• May search unnecessarily deep for a shallow goal.

Page 19: September 26, 2012Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I 1 After our “Haskell in a Nutshell” excursion, let us move

Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I

19September 26, 2012

Iterative Deepening

Iterative deepening is an interesting combination of breadth-first and depth-first strategies:

• Space complexity for search depth n is O(n).

• Is guaranteed to find the shortest path to a solution without searching unnecessarily deep.

How does it work?

The idea is to successively apply depth-first searches with increasing depth bounds (maximum search depth).

Page 20: September 26, 2012Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I 1 After our “Haskell in a Nutshell” excursion, let us move

Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I

20September 26, 2012

Iterative Deepening

maximum search depth = 0 (only root is tested)

Page 21: September 26, 2012Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I 1 After our “Haskell in a Nutshell” excursion, let us move

Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I

21September 26, 2012

Iterative Deepening

maximum search depth = 1

Page 22: September 26, 2012Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I 1 After our “Haskell in a Nutshell” excursion, let us move

Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I

22September 26, 2012

Iterative Deepening

maximum search depth = 2

Page 23: September 26, 2012Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I 1 After our “Haskell in a Nutshell” excursion, let us move

Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I

23September 26, 2012

Iterative Deepening

maximum search depth = 3

Page 24: September 26, 2012Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I 1 After our “Haskell in a Nutshell” excursion, let us move

Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I

24September 26, 2012

Iterative Deepening

maximum search depth = 4

Page 25: September 26, 2012Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I 1 After our “Haskell in a Nutshell” excursion, let us move

Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I

25September 26, 2012

Iterative Deepening

But it seems that the time complexity of iterative deepening is much higher than that of breadth-first search!

Well, if we have a branching factor b and the shallowest goal at depth d, then the worst-case number of nodes to be expanded by breadth-first is:

1

1...1

12

b

bbbbN

dd

bf

Page 26: September 26, 2012Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I 1 After our “Haskell in a Nutshell” excursion, let us move

Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I

26September 26, 2012

Iterative Deepening

In order to determine the number of nodes expanded by iterative deepening, we have to look at depth-first search.

What is the worst-case number of nodes expanded by depth-first search for a branching factor b and a maximum search level j ?

1

1...1

12

b

bbbbN

jj

df

Page 27: September 26, 2012Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I 1 After our “Haskell in a Nutshell” excursion, let us move

Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I

27September 26, 2012

Iterative DeepeningTherefore, the worst-case number of nodes expanded by iterative deepening from depth 0 to depth d is:

d

j

j

id b

bN

0

1

1

1

d

j

d

j

jbbb 00

11

1

)1(1

1

1

1 1

db

bb

b

d

2

2

)1(

12

b

dbdbbN

d

id

Page 28: September 26, 2012Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I 1 After our “Haskell in a Nutshell” excursion, let us move

Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I

28September 26, 2012

Iterative DeepeningLet us now compare the numbers for breadth-first search and iterative deepening:

2

2

)1(

12

b

dbdbbN

d

id

1

1...1

12

b

bbbbN

dd

bf

For large d, you see that Nid/Nbf approaches b/(b – 1), which in turn approaches 1 for large b.

So for big trees (large b and d), iterative deepening does not expand many more nodes than does breadth-first search (about 11% for b = 10 and large d).