66
Princess Nora University Artificial Intelligence Chapter (3) Solving problems by searching 1

Princess Nora University Artificial Intelligence

  • Upload
    honey

  • View
    44

  • Download
    3

Embed Size (px)

DESCRIPTION

Princess Nora University Artificial Intelligence. Chapter (3) Solving problems by searching. Out Line :. Problem-solving agents Problem types Problem formulation Example problems Basic search algorithms. Solving problems by searching. - PowerPoint PPT Presentation

Citation preview

Page 1: Princess Nora University Artificial Intelligence

1

Princess Nora University

Artificial Intelligence

Chapter (3)Solving problems

by searching

Page 2: Princess Nora University Artificial Intelligence

2

Out Line :

• Problem-solving agents• Problem types• Problem formulation• Example problems• Basic search algorithms

Page 3: Princess Nora University Artificial Intelligence

Solving problems by searching

• In which we look at how an agent can decide what to do by systematically considering the outcomes of various sequences of actions that it might take.

• Basic Search Algorithm Many AI problems can be posed as search If goal found=>success; else, failure

3

Page 4: Princess Nora University Artificial Intelligence

4

Why Search? Not just city route search

– Many AI problems can be posed as search Planning :

– Vertices : World states; Edges: Actions Game-playing:

– Vertices: Board configurations; Edges: Moves

Speech Recognition:– Vertices: Phonemes; Edges: Phone

transitions

Page 5: Princess Nora University Artificial Intelligence

Problem-solving agents

5

Page 6: Princess Nora University Artificial Intelligence

Example:

• On holiday in Riyadh.• Flight leaves tomorrow from Riyadh• Formulate goal :

– be after two days in Paris• Formulate problem:

– States : various cities– Actions : drive between cities

• Find solution :– sequence of cities, e.g., Riyadh, Jeddah,

London, Paris6

Page 7: Princess Nora University Artificial Intelligence

7

Example: Romania

Page 8: Princess Nora University Artificial Intelligence

Problem types• Deterministic, fully observable single-

state problem– Agent knows exactly which state it will be in; solution

is a sequence• Non-observable sensorless problem

(conformant problem)– Agent may have no idea where it is; solution is a

sequence• Nondeterministic and/or partially

observable contingency problem– percepts provide new information about current state– Solution is tree, branch chosen based on percepts– Must use sensors during execution

• Unknown state space exploration problem 8

Page 9: Princess Nora University Artificial Intelligence

Single-state problem formulation

A problem is defined by 4 items:

1. initial state e.g., "at Arad“

2. actions or successor function S(x) = set of action–state pairs

e.g., S(Arad) = {<Arad Zerind, Zerind>, … }

9

Page 10: Princess Nora University Artificial Intelligence

Single-state problem formulation

3. goal test, can beexplicit, e.g., x = "at Bucharest"implicit, e.g., Checkmate(x)

4. path cost (additive) sequence of actions leading from one state to another

e.g., sum of distances, number of actions executed, etc.C (x, a, y) is the step cost, assumed to be ≥ 0

State space: all states reachable from the initial state by any sequence action

A solution is a sequence of actions leading from the initial state to a goal state

10

Page 11: Princess Nora University Artificial Intelligence

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 reliability, 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

11

Page 12: Princess Nora University Artificial Intelligence

Vacuum world state space graph

• States ? dirt and robot location • actions? Left, Right, Suck• goal test ? no dirt at all locations• path cost? 1 per action 12

Page 13: Princess Nora University Artificial Intelligence

Example: The 8-puzzle

• states? locations of tiles • actions? move blank left, right, up, down • goal test? = goal state (given)• path cost? 1 per move•

[Note: optimal solution of n-Puzzle family is NP-hard] 13

Page 14: Princess Nora University Artificial Intelligence

Tree search algorithms

• Basic idea:– offline, simulated exploration of state space

by generating successors of already-explored states (expanding states)

14

Page 15: Princess Nora University Artificial Intelligence

Tree search example

15

Page 16: Princess Nora University Artificial Intelligence

16

Implementation: general tree search

Page 17: Princess Nora University Artificial Intelligence

17

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

• The Expand function creates new nodes, filling in the various fields and using the SuccessorFn of the problem to create the corresponding states.

Page 18: Princess Nora University Artificial Intelligence

18

Search strategies• A search 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– 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 ∞)

Page 19: Princess Nora University Artificial Intelligence

Uninformed search strategies

• Uninformed search 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

19

Page 20: Princess Nora University Artificial Intelligence

Breadth-first search

• Expand shallowest unexpanded node• Implementation:

– fringe is a FIFO queue, i.e., new successors go at end

Application1: Given the following state space (tree search), give the sequence of visited nodes when using BFS (assume that the node O is the goal state)

20

Page 21: Princess Nora University Artificial Intelligence

21

Breadth First Search :

A

B C ED

F G H I J

K L

O

M N

Page 22: Princess Nora University Artificial Intelligence

22

Breadth First Search A,

B,C,D,E, F,G,H,I,J,

K,L, M,N, Goal state: OA

B C EDF G H I J

K L

O

M N

Page 23: Princess Nora University Artificial Intelligence

23

Breadth First Search The returned solution is the sequence of operators in

the path:A, B, G, L, OA

B C EDF G H I J

K L

O

M N

Page 24: Princess Nora University Artificial Intelligence

24

Basic Search Algorithms Uninformed Search

Uniform Cost Search (UCS)

Page 25: Princess Nora University Artificial Intelligence

Properties of breadth-first search

• Complete? Yes ( if b is finite)• Time? b+b2+b3+… +bd + b(bd-1) =

O(bd+1)• Space? 1+b+b2+b3+… +bd + b(bd-1) =

O(bd+1) O(bd+1) (keeps every node in memory)

• Optimal? Yes (if cost = 1 per step)

• Space is the bigger problem (more than time)

25

Page 26: Princess Nora University Artificial Intelligence

26

Uniform Cost Search (UCS)

Expand the cheapest node. Where the cost is the path cost g(n).

Implémentations: Enqueue nodes in order of cost g(n). QUEUING-FN:- insert in order of increasing path cost.Enqueue new node at the appropriate position in the queue so that we dequeue the cheapest node.

Page 27: Princess Nora University Artificial Intelligence

27

Uniform Cost Search (UCS)

25

1 7

4 5

[5] [2]

[9][3]

[7] [8]

1 4

[9][6]

[x] = g(n)

path cost of node n

Goal state

Page 28: Princess Nora University Artificial Intelligence

28

Uniform Cost Search (UCS)

25

[5] [2]

Page 29: Princess Nora University Artificial Intelligence

29

Uniform Cost Search (UCS)

25

1 7

[5] [2]

[9][3]

Page 30: Princess Nora University Artificial Intelligence

30

Uniform Cost Search (UCS)

25

1 7

4 5

[5] [2]

[9][3]

[7] [8]

Page 31: Princess Nora University Artificial Intelligence

31

Uniform Cost Search (UCS)

25

1 7

4 5

[5] [2]

[9][3]

[7] [8]

1 4

[9][6]

Page 32: Princess Nora University Artificial Intelligence

32

Uniform Cost Search (UCS)

25

1 7

4 5

[5] [2]

[9][3]

[7] [8]

1 4

[9]

Goal state path cost g(n)=[6]

Page 33: Princess Nora University Artificial Intelligence

33

Uniform Cost Search (UCS)

25

1 7

4 5

[5] [2]

[9][3]

[7] [8]

1 4

[9][6]

Page 34: Princess Nora University Artificial Intelligence

34

Uniform Cost Search (UCS)

Complete? Yes

Time? O(bd)

Space? : O(bd), note that every node in the fringe keep in the queue.

Optimal? Yes

Page 35: Princess Nora University Artificial Intelligence

Depth-first search

• Expand deepest unexpanded node• Implementation:

– fringe = LIFO queue, i.e., put successors at front

35

Page 36: Princess Nora University Artificial Intelligence

36

Depth First Search (DFS)Given the following state space (tree search), give the sequence of visited nodes when using DFS (assume that the nodeO is the goal state):

AB C ED

F G H I J

K L

O

M N

Page 37: Princess Nora University Artificial Intelligence

37

Depth First Search A,

AB C ED

Page 38: Princess Nora University Artificial Intelligence

38

Depth First Search A,B,

AB C ED

F G

Page 39: Princess Nora University Artificial Intelligence

39

Depth First Search A,B,F,

AB C ED

F G

Page 40: Princess Nora University Artificial Intelligence

40

Depth First Search A,B,F,

G,

AB C ED

F G

K L

Page 41: Princess Nora University Artificial Intelligence

41

Depth First Search A,B,F,

G,K,

AB C ED

F G

K L

Page 42: Princess Nora University Artificial Intelligence

42

Depth First Search A,B,F,

G,K, L,

AB C ED

F G

K L

O

Page 43: Princess Nora University Artificial Intelligence

43

Depth First Search A,B,F,

G,K, L, O: Goal State

AB C ED

F G

K L

O

Page 44: Princess Nora University Artificial Intelligence

44

Depth First SearchThe returned solution is the sequence of operators in the path:

A, B, G, L, O

AB C ED

F G

K L

O

Page 45: Princess Nora University Artificial Intelligence

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 45

Page 46: Princess Nora University Artificial Intelligence

Depth-limited search

= depth-first search with depth limit l,

i.e., nodes at depth l have no successors

46

Page 47: Princess Nora University Artificial Intelligence

47

Depth-Limited Search (DLS)

Given the following state space (tree search), give the sequence of visited nodes when using DLS (Limit = 2):

AB C ED

F G H I J

K L

O

M N

Limit = 0

Limit = 1

Limit = 2

Page 48: Princess Nora University Artificial Intelligence

48

Depth-Limited Search (DLS)

A,

AB C ED

Limit = 2

Page 49: Princess Nora University Artificial Intelligence

49

Depth-Limited Search (DLS)

A,B,

AB C ED

F G

Limit = 2

Page 50: Princess Nora University Artificial Intelligence

50

Depth-Limited Search (DLS)

A,B,F,

AB C ED

F G

Limit = 2

Page 51: Princess Nora University Artificial Intelligence

51

Depth-Limited Search (DLS)

A,B,F, G,

AB C ED

F G

Limit = 2

Page 52: Princess Nora University Artificial Intelligence

52

Depth-Limited Search (DLS)

A,B,F, G, C,

AB C ED

F G H

Limit = 2

Page 53: Princess Nora University Artificial Intelligence

53

Depth-Limited Search (DLS)

A,B,F, G,

C,H,

AB C ED

F G H

Limit = 2

Page 54: Princess Nora University Artificial Intelligence

54

Depth-Limited Search (DLS)

A,B,F, G,

C,H, D,A

B C EDF G H I J

Limit = 2

Page 55: Princess Nora University Artificial Intelligence

55

Depth-Limited Search (DLS)

A,B,F, G,

C,H, D,IA

B C EDF G H I J

Limit = 2

Page 56: Princess Nora University Artificial Intelligence

56

Depth-Limited Search (DLS)

A,B,F, G,

C,H, D,I

J,AB C ED

F G H I JLimit = 2

Page 57: Princess Nora University Artificial Intelligence

57

Depth-Limited Search (DLS) A,B,F,

G, C,H,

D,I J, E

AB C ED

F G H I J

Limit = 2

Page 58: Princess Nora University Artificial Intelligence

58

Depth-Limited Search (DLS)

A,B,F, G,

C,H, D,I

J, E, Failure

AB C ED

F G H I J

Limit = 2

Page 59: Princess Nora University Artificial Intelligence

59

Depth-Limited Search (DLS)

DLS algorithm returns Failure (no solution) The reason is that the goal is beyond the limit (Limit

=2): the goal depth is (d=4)

AB C ED

F G H I J

K L

O

M NLimit = 2

Page 60: Princess Nora University Artificial Intelligence

60

Depth-Limited Search (DLS)

Complete? Yes if there is a goal state at a depth less than L

Time? O(bL), where L is the cutoff.

Space? : O(bL), where L is the cutoff

Optimal? NO

Page 61: Princess Nora University Artificial Intelligence

61

Iterative Deepening Search (IDS)

Iterative deepening search (IDS) applies DLS repeatedly with increasing depth. It terminates when a solution is found or no solutions exists.

Page 62: Princess Nora University Artificial Intelligence

62

Iterative deepening search• Number of nodes generated in a depth-limited search to

depth d with branching factor b: NDLS = b0 + b1 + b2 + … + bd-2 + bd-1 + bd

• Number of nodes generated in an iterative deepening search to depth d with branching factor b:

NIDS = d b0 + (d-1)b1 + … + 3bd-2 +2bd-1 + 1bd

For b = 10, d = 6,•• NDLS = 1 + 10 + 100 + 1,000 + 10,000 + 100,000 = 111,111

–– NIDS = 6 + 50 + 400 + 3,000 + 20,000 + 100,000 = 123,456–

• Overhead = (123,456 - 111,111)/111,111 = 11%

Page 63: Princess Nora University Artificial Intelligence

63

Properties of iterative deepening search• Complete? Yes• Time? d b1 + (d-1)b2 + … + bd =

O(bd)• Space? O(bd)• Optimal? Yes, if step cost = 1

Page 64: Princess Nora University Artificial Intelligence

64

Bi-directional Search (BDS) Start searching from both the

initial state and the goal state, meet in the middle.

• Complete? Yes• Optimal? Yes• Time Complexity: O(bd/2),

where d is the depth of the solution.

• Space Complexity: O(bd/2), where d is the depth of the solution.

Page 65: Princess Nora University Artificial Intelligence

65

Comparison of search algorithms

b: Branching factord: Depth of solutionm: Maximum depth

l : Depth Limit

Page 66: Princess Nora University Artificial Intelligence

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 needs only linear space and not much more time than other uninformed algorithms

66