Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive...

56
Artificial Intelligence Search Problem

Transcript of Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive...

Page 1: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Artificial Intelligence

Search Problem

Page 2: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Search Problem

Search is a problem-solving technique to explores

successive stages in problem-solving process.

Page 3: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

A simple example: traveling on a graph

A

BC

F

D E3 4 4

3

92

2

start stategoal state

Page 4: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Search treestate = A ,

cost = 0

state = B ,cost = 3

state = D ,cost = 3

state = C ,cost = 5

state = F ,cost = 12

state = A ,cost = 7

goal state!

search tree nodes and states are not the same thing!

Page 5: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Full search treestate = A ,

cost = 0

state = B ,cost = 3

state = D ,cost = 3

state = C ,cost = 5

state = F ,cost = 12

state = A ,cost = 7

goal state!

state = E ,cost = 7

state = F ,cost = 11

goal state!

state = B ,cost = 10

state = D ,cost = 10...

...

Page 6: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Problem types

• Deterministic, fully observable single-state problem– Solution is a sequence of states

• Non-observable sensorless problem – Problem-solving may have no idea where it is;

solution is a sequence

• Nondeterministic and/or partially observable

Unknown state space

Page 7: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Algorithm types

• There are two kinds of search algorithm –Complete• guaranteed to find solution or prove there is

none

– Incomplete• may not find a solution even when it exists• often more efficient (or there would be no

point)

Page 8: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Example: the 8-puzzle.Given: a board situation for the 8-puzzle:

11 33 88

22 77

55 44 66

11 22 33

5566774488

Problem: find a sequence of moves that transform this board situation in a desired goal situation:

Page 9: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

State Space representation

In the space representation of a problem, the

nodes of a graph correspond to partial

problem solution states and arcs correspond

to steps (action) in a problem-solving process

Page 10: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Key concepts in search

• Set of states that we can be in– Including an initial state…– … and goal states (equivalently, a goal test)

• For every state, a set of actions that we can take– Each action results in a new state– Given a state, produces all states that can be reached from it

• Cost function that determines the cost of each action (or path = sequence of actions)

• Solution: path from initial state to a goal state– Optimal solution: solution with minimal cost

Page 11: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

( NewYork )( NewYork )

( NewYork,( NewYork, Boston )Boston )

( NewYork,( NewYork, Miami )Miami )

( NewYork,( NewYork, Dallas )Dallas )

( NewYork,( NewYork, Frisco )Frisco )

( NewYork,( NewYork, Boston,Boston, Miami )Miami )

( NewYork,( NewYork, Frisco,Frisco, Miami )Miami )

250250 12001200 1500150029002900

00

250250 12001200 15001500 29002900

14501450 33003300

17001700 62006200

Keep track of Keep track of accumulated costsaccumulated costs in each state if you want in each state if you wantto be sure to get the best path.to be sure to get the best path.

Page 12: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Example: Route Finding

• Initial state– City journey starts in

• Operators– Driving from city to city

• Goal test– Is current location the

destination city?

Liverpool

London

Nottingham

Leeds

Birmingham

Manchester

Page 13: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

State space representation (salesman)• State:– the list of cities that are already visited

• Ex.: ( NewYork, Boston )• Initial state:

• Ex.: ( NewYork )• Rules:– add 1 city to the list that is not yet a member– add the first city if you already have 5 members

• Goal criterion:– first and last city are equal

Page 14: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Example: The 8-puzzle

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

Page 15: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

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• path cost?: time to execute••••

Page 16: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

123

84

765

13

746

582

143

76

582

143

786

52

143

76

582

13

746

582

13

746

582

43

176

582

143

576

82

Page 17: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Example: Chess• Problem: develop a program that plays chess

1122334455667788

A B C D E F G A B C D E F G HH

1. A way to represent board situations Ex.:

List:List:(( king_black, 8, C),(( king_black, 8, C), ( knight_black, 7, B),( knight_black, 7, B), ( pawn_black, 7, G),( pawn_black, 7, G), ( pawn_black, 5, F),( pawn_black, 5, F), ( pawn_white, 2, H),( pawn_white, 2, H), ( king_white, 1, E))( king_white, 1, E))

Page 18: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Chess

Move 1Move 1

Move 2Move 2

Move 3Move 3

search treesearch tree~15~15

~ (15)~ (15)22

~ (15)~ (15)33

Need Need very efficient searchvery efficient search techniques to find good techniques to find goodpaths in such combinatorial trees.paths in such combinatorial trees.

Page 19: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

independence of states:Ex.: Blocks world problem.• Initially: C is on A and B is on the table.• Rules: to move any free block to another or to the table• Goal: A is on B and B is on C.

AACC

BBGoalGoal:: A A onon B B andand B B onon C C

AACC

BBGoalGoal:: A A onon B B

AACC

BBGoalGoal:: B B onon C C

AND-OR-tree?AND-OR-tree?

ANDAND

Page 20: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Search in State Spaces

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

Page 21: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Avoiding Repeated States

• In increasing order of effectiveness in reducing size of state space and with increasing computational costs:1. Do not return to the state you just came from. 2. Do not create paths with cycles in them. 3. Do not generate any state that was ever created

before. • Net effect depends on frequency of “loops” in state

space.

Page 22: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Forward versus backward reasoning:Initial statesInitial states

Goal statesGoal states

Forward reasoning (or Data-driven): from initial states to goal states.

Page 23: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Forward versus backward reasoning:Initial statesInitial states

Goal statesGoal states

Backward reasoning (or backward chaining / goal-driven ): from goal states to initial states.

Page 24: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Data-Driven search• It is called forward chaining

• The problem solver begins with the given facts

and a set of legal moves or rules for changing

state to arrive to the goal.

Page 25: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Goal-Driven Search• Take the goal that we want to solve and see

what rules or legal moves could be used to

generate this goal.

• So we move backward.

Page 26: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Search Implementation

• In both types of moving search, we must find

the path from start state to a goal.

• We use goal-driven search if

– The goal is given in the problem

– There exist a large number of rules

– Problem data are not given

Page 27: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Search Implementation

• The data-driven search is used if

– All or most data are given

– There are a large number of potential goals

– It is difficult to form a goal

Page 28: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Criteria:

• Sometimes: no way to start from the goal states– because there are too many (Ex.: chess)– because you can’t (easily) formulate the rules

in 2 directions.

11 33 88

22 77

55 44 66

11 22 33

5566774488

In this case: even the same rules !!In this case: even the same rules !!

Sometimes equivalent:

Page 29: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Classical Search Strategies

• Breadth-first search• Depth-first search• Bidirectional search• Depth-bounded depth first search– like depth first but set limit on depth of search in

tree• Iterative Deepening search– use depth-bounded search but iteratively increase

limit

Page 30: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Breadth-first search:

• Move downwards, level by level, until goal is reached.

SS

AA DD

BB DD AA EE

CC EE EE BB BB FF

DD FF BB FF CC EE AA CC GG

GG

GGGG FFCC

It explores the space in a level-by-level fashion.

Page 31: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Breadth-first search• BFS is complete: if a solution exists, one will

be found• Expand shallowest unexpanded node– fringe is a FIFO queue, i.e., new successors go at

end

• Implementation:

Page 32: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Breadth-first search

• Expand shallowest unexpanded node– fringe is a FIFO queue, i.e., new successors go at

end

•Implementation:

Page 33: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Breadth-first search

• Expand shallowest unexpanded node– fringe is a FIFO queue, i.e., new successors go at

end

•Implementation:

Page 34: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Breadth-first search

• Expand shallowest unexpanded node– fringe is a FIFO queue, i.e., new successors go at

end

•Implementation:

Page 35: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Depth-First Order

• When a state is examined, all of its children and

their descendants are examined before any of its

siblings.

• Not complete (might cycle through nongoal states)

• Depth- First order goes deeper whenever this is

possible.

Page 36: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Depth-first search= Chronological backtracking

• Select a child – convention: left-to-right

• Repeatedly go to next child, as long as possible.

• Return to left-over alternatives (higher-up) only when needed.

BB

CC EE

DD FF

GG

SS

AA

Page 37: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Depth-first search

• Expand deepest unexpanded node– fringe = LIFO queue, i.e., put successors at front

•Implementation:

Page 38: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Depth-first search

• Expand deepest unexpanded node– fringe = LIFO queue, i.e., put successors at front

•Implementation:

Page 39: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Depth-first search

• Expand deepest unexpanded node– fringe = LIFO queue, i.e., put successors at front

•Implementation:

Page 40: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Depth-first search

• Expand deepest unexpanded node– fringe = LIFO queue, i.e., put successors at front

•Implementation:

Page 41: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Depth-first search

• Expand deepest unexpanded node– fringe = LIFO queue, i.e., put successors at front

•Implementation:

Page 42: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Depth-first search

• Expand deepest unexpanded node– fringe = LIFO queue, i.e., put successors at front

•Implementation:

Page 43: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Depth-first search

• Expand deepest unexpanded node– fringe = LIFO queue, i.e., put successors at front

•Implementation:

Page 44: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Depth-first search

• Expand deepest unexpanded node– fringe = LIFO queue, i.e., put successors at front

•Implementation:

Page 45: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Depth-first search

• Expand deepest unexpanded node– fringe = LIFO queue, i.e., put successors at front

•Implementation:

Page 46: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Depth-first search

• Expand deepest unexpanded node– fringe = LIFO queue, i.e., put successors at front

•Implementation:

Page 47: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Depth-first search

• Expand deepest unexpanded node– fringe = LIFO queue, i.e., put successors at front

•Implementation:

Page 48: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Depth-first search

• Expand deepest unexpanded node– fringe = LIFO queue, i.e., put successors at front

•Implementation:

Page 49: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

A

C D E FB

G H I J K L M N O P

Q R S T U V W X Y Z

The example node set

Initial state

Goal state

A

L

Press space to see a BFS of the example node set

Page 50: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

A

C D E FB

G H I J K L

Q R S T U

A

B C D

We begin with our initial state: the node labeled A. Press space

to continue

This node is then expanded to reveal further (unexpanded)

nodes. Press space

Node A is removed from the queue. Each revealed node is

added to the END of the queue. Press space to continue the

search.

The search then moves to the first node in the queue. Press

space to continue.

Node B is expanded then removed from the queue. The

revealed nodes are added to the END of the queue. Press space.

Size of Queue: 0

Nodes expanded: 0

Current Action: Current level: n/a

Queue: EmptyQueue: ASize of Queue: 1

Nodes expanded: 1

Queue: B, C, D, E, F

Press space to begin the search

Size of Queue: 5

Current level: 0Current Action: Expanding

Queue: C, D, E, F, G, HSize of Queue: 6

Nodes expanded: 2

Current level: 1

We then backtrack to expand node C, and the process

continues. Press space

Current Action: Backtracking

Current level: 0Current level: 1

Queue: D, E, F, G, H, I, JSize of Queue: 7

Nodes expanded: 3

Current Action: ExpandingCurrent Action: Backtracking

Current level: 0Current level: 1

Queue: E, F, G, H, I, J, K, LSize of Queue: 8

Nodes expanded: 4

Current Action: ExpandingCurrent Action: Backtracking

Current level: 0Current level: 1Current Action: Expanding

NM

Queue: F, G, H, I, J, K, L, M, NSize of Queue: 9

Nodes expanded: 5

E

Current Action: Backtracking

Current level: 0Current Action: Expanding Current level: 1

O P

Queue: G, H, I, J, K, L, M, N, O, PSize of Queue: 10Nodes

expanded: 6

F

Current Action: Backtracking

Current level: 0Current level: 1Current level: 2Current Action: Expanding

Queue: H, I, J, K, L, M, N, O, P, Q

Nodes expanded: 7

G

Current Action: Backtracking

Current level: 1Current Action: Expanding

Queue: I, J, K, L, M, N, O, P, Q, R

Nodes expanded: 8

H

Current Action: Backtracking

Current level: 2Current level: 1Current level: 0Current level: 1Current level: 2Current Action: Expanding

Queue: J, K, L, M, N, O, P, Q, R, S

Nodes expanded: 9

I

Current Action: Backtracking

Current level: 1Current level: 2Current Action: Expanding

Queue: K, L, M, N, O, P, Q, R, S, T

Nodes expanded: 10

J

Current Action: Backtracking

Current level: 1Current level: 0Current level: 1Current level: 2Current Action: Expanding

Queue: L, M, N, O, P, Q, R, S, T, U

Nodes expanded: 11

K

Current Action: Backtracking

Current level: 1

LLLL

Node L is located and the search returns a solution.

Press space to end.

FINISHED SEARCH

Queue: EmptySize of Queue: 0

Current level: 2

BREADTH-FIRST SEARCH PATTERN

L

Press space to continue the searchPress space to continue the searchPress space to continue the searchPress space to continue the searchPress space to continue the searchPress space to continue the searchPress space to continue the searchPress space to continue the searchPress space to continue the search

Page 51: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Aside: Internet Search

• Typically human search will be “incomplete”, • E.g. finding information on the internet before

google, etc– look at a few web pages,– if no success then give up

Page 52: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Example

• Determine whether data-driven or goal-driven and depth-first or breadth-first would be preferable for solving each of the following– Diagnosing mechanical problems in an automobile– You have met a person who claims to be your

distant cousin, with a common ancestor named John. You like to verify her claim

– A theorem prover for plane geometry

Page 53: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

• A program for examining sonar readings and interpreting them

• An expert system that will help a human

classify plants by species, genus,etc.

Example

Page 54: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Any path, versus shortest path, versus best path:

Ex.: Traveling salesperson problem:

• Find a sequence of cities ABCDEA such that the total distance is MINIMAL.

BostonBoston

MiamiMiami

NewYorkNewYork

SanFranciscoSanFrancisco

DallasDallas

30003000

250250

14501450

12001200 17001700

3300330029002900

15001500

16001600

17001700

Page 55: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

55

Bi-directional search• IF you are able to EXPLICITLY describe the GOAL state, AND you have

BOTH rules for FORWARD reasoning AND BACKWARD reasoning• Compute the tree both from the start-node and from a goal node,

until these meet.

GoalGoalStartStart

Page 56: Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem-solving process.

Example Search Problem• A genetics professor– Wants to name her new baby boy– Using only the letters D,N & A

• Search through possible strings (states)– D,DN,DNNA,NA,AND,DNAN, etc.– 3 operators: add D, N or A onto end of string– Initial state is an empty string

• Goal test– Look up state in a book of boys’ names, e.g. DAN