Artificial Intelligence Problem solving by searching CSC 361 Prof. Mohamed Batouche Computer Science Department CCIS – King Saud University Riyadh, Saudi Arabia [email protected].

Download Report

Transcript Artificial Intelligence Problem solving by searching CSC 361 Prof. Mohamed Batouche Computer Science Department CCIS – King Saud University Riyadh, Saudi Arabia [email protected].

Artificial Intelligence
Problem solving by searching
CSC 361
Prof. Mohamed Batouche
Computer Science Department
CCIS – King Saud University
Riyadh, Saudi Arabia
[email protected]
Problem Solving by Searching
Search Methods :
Uninformed (Blind) search
Solution of Tutorial II
Search Methods

Consider the River Problem:
A farmer wishes to carry a wolf, a duck and corn across a river, from the south to the
north shore. The farmer is the proud owner of a small rowing boat called Bounty
which he feels is easily up to the job. Unfortunately the boat is only large enough to
carry at most the farmer and one other item. Worse again, if left unattended the wolf
will eat the duck and the duck will eat the corn.
River
boat
Farmer, Wolf,
Duck and Corn
How can the farmer safely transport the wolf, the duck and the corn to the opposite
shore? Solve this problem using BFS. Do not expand repeated stated.
3
Search Methods

Problem formulation:





State representation: location of farmer and items in both sides of river
[items in South shore / items in North shore] : (FWDC/-, FD/WC, C/FWD …)
Initial State: farmer, wolf, duck and corn in the south shore
FWDC/-
Goal State: farmer, duck and corn in the north shore
-/FWDC
Operators: the farmer takes in the boat at most one item from one side to
the other side
(F-Takes-W, F-Takes-D, F-Takes-C, F-Takes-Self [himself only])
Path cost: the number of crossings
4
Search Methods
F WD C
WD C
D C
F
W
F W
F
F W
C
WD
D
F
C
C
F WD C
D
W
F
F
C
C
C
D
W
F WD
F W
WD
C
F
D
F
D C
F W
W
D C
F WD
D C
C
F W
D C
D
F WD
F W
F
D
W
WD
C
F WD
C
F
F
C
F W
C
D
C
F W
C
D
W
C
F
D C
D C
W
D
F W
C
F WD C
5
Blind Search Search

Problem 2:
Given the following state space (tree search), give the sequence of
visited nodes when using BFS, DFS, and IDS.
Initial state
A
B
C
D
E
F
Goal state
G H
I
J
K
L
M N
O
P
Q
S
T
U V
W X
Y
Z
R
6
Blind Search Algorithms
BFS
We
Node
The
then
B
search
isbacktrack
expanded
then moves
to
then
expand
to
removed
thenode
firstfrom
C,
nodethe
queue.
and
in the
theThe
queue.
process
revealed
Press
continues.
nodes
space Press
to
arecontinue.
added
spaceto the
END of the queue. Press space.
B
G H
C
I
A
Node
This
We begin
node
A is removed
is
with
then
our
expanded
from
initialthe
state:
to
queue.
reveal
the Each
node
further
revealed
labeled(unexpanded)
A.
node
Press
is added
spacenodes.
to continue
the Press
END space
of the
queue. Press space to continue the search.
D
J
K
E
L
F
M N
O
P
Node L is located and the search returns
a solution. Press space to end.
Q
R
S
T
U
Press space to continue
begin thethe
search
search
Size of Queue: 010
987651
Queue: A
B,J,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
Empty
K,
G,
C,
F,
M,
D,
E,
H,K,
I,
L,
J,
G,
L,
H,
F,
D,
E,
M,
I,
N,L,
K,
G,
J,
M,
H,
I,
F,
E,
O,
N,
M,
K,
L,
J,
G,
H,
I,
FN,
P,
O,
K,
M,
J,
L,
N,
H
I,O,
Q,
P,
K,
L,
JM,
O,
N,
P,
Q,
R,M,
LP,
O,
N,
Q,
S,
R,Q,
N
O,
P,
T,
R,
S,R
Q
U
P
S
T
Nodes expanded: 11
9876543210
10
CurrentFINISHED
Action: Backtracking
Expanding
SEARCH
Current level: 210n/a
BREADTH-FIRST SEARCH PATTERN
8
Blind Search Algorithms
DFS
The process
Node
search
B is expanded
then
nowmoves
continues
andtoremoved
the
until
first
the
from
node
in the
the
goal
queue.
state
queue.
isRevealed
achieved.
Press space
nodes
Press
toare
continue
space.
added to
the FRONT of the queue. Press space.
B
A
C
D
G H
I
J
K
Q
S
T
U
R
Node
We
This
begin
node
A is with
removed
is then
ourexpanded
initial
from the
state:
to
queue.
reveal
the node
Each
labeled A.
further
revealed
(unexpanded)
node
Press
is space
addednodes.
totocontinue
the Press
FRONT
space.
of
the queue. Press space to continue.
E
L
F
Node L is located and the search
returns a solution. Press space to
end.
Press space to continue
begin thethe
search
search
Size of Queue: 034561
Queue: A
T,
B,J,
G,
Q,
H,
R,
C,
I,
S,
J,
D,
K,
U,
L,
Empty
D,
J,
C,
E,
D,
L,
H,D,
C,
D,
E,
F
E,
D,
D,
C,E,
E,
FF
E,
E,
D,FFF
F
E, F
Nodes expanded: 14
9876543210
10
11
12
13
CurrentFINISHED
Action: Backtracking
Expanding
SEARCH
DEPTH-FIRST SEARCH PATTERN
Current level: 2130n/a
10
Blind Search Algorithms
IDS
A
We
Node
begin
A iswith
thenour
expanded
initial state:
and removed
the node
labeled
from the
A. queue.
This node
Press
is added
space. to the
queue. Press space to continue
As this is the 0th iteration of the search, we cannot search past any level greater than
zero. This iteration now ends, and we begin the 1st iteration.
Press space to begin the search
Size of Queue: 01
Queue: A
Empty
Nodes expanded: 10
Current Action: Expanding
Current level: 0n/a
ITERATIVE DEEPENING SEARCH PATTERN (0th ITERATION)
12
We
Node
The
now
B
search
isback
expanded
now
track
moves
to
and
expand
removed
to level
node
one
from
C,
of and
the
queue.
the
theprocess
node
Press
set.
continues.
space.
Press space
Presstospace.
continue
B
C
A
D
Node
We again
A is expanded,
begin withthen
our removed
initial state:
from
the
the
node
queue,
labeled
andA.the
Note
revealed
that the
nodes
1st iteration
are
added
carriestoon
thefrom
frontthe
. Press
0th, and
space.
therefore the
‘nodes expanded’ value is already set to 1.
Press space to continue
E
F
As this is the 1st iteration of the search, we cannot search past any level greater than
level one. This iteration now ends, and we begin a 2nd iteration.
Press space to continue
begin thethe
search
search
Size of Queue: 012345
Queue: A
B, F
C,
D,
E,
F
Empty
C,
D, F
E,
D,
E, F
E, F
Nodes expanded: 7654321
Current Action: Expanding
Backtracking
Current level: 10n/a
ITERATIVE DEEPENING SEARCH PATTERN (1st ITERATION)
13
Node
The
search
Bexpanding
ismove
expanded
then
and
tothe
level
of
We
After
now
to moves
level
node
two
G
we
ofrevealed
backtrack
theone
node
the
nodes
node
added
set.
Press
to
the
space
front
of
to the
continue
queue.
set.
to expand
Press
space
node
to
H.continue.
The process
then
Press
spaceuntil
to continue.
continues
goal state. Press space
B
A
C
G H
I
D
J
K
Node
We
Again,
again
Awe
is begin
removed
expand
with
node
from
ourAthe
initial
to reveal
queue
state:
the
and
the node
level
each
revealed
one labeled
nodes.
node
Press
A. is
Note
added
space.
thattothe
the2nd
front of
iteration
the
queue.carries
Press on
space.
from the 1st, and
therefore the ‘nodes expanded’ value is
already set to 7 (1+6). Press space to
E
F
continue the search
L
Node L is located on the second level and the search returns a solution
on its second iteration. Press space to end.
Press space to continue the search
Size of Queue: 034561
Queue: A
B,J,
G,
H,
C,
I,
J,
D,
K,
L,
Empty
D,
C,
E,
D,
H,D,
C,
L,
E,
F
D,
E,
D,
C,E,
FF
E,
E,
D,FF
F
E, F
Nodes expanded: 16
987
10
11
12
13
14
15
CurrentSEARCH
Action: Backtracking
Expanding
FINISHED
Current level: 210n/a
ITERATIVE DEEPENING SEARCH PATTERN (2nd ITERATION)
14
Blind Search Algorithms
UCS
Consider the following problem…
A
10
1
5
S
5
B
G
5
15
C
We wish to find the shortest route from node S to node G; that is, node S is the initial
state and node G is the goal state. In terms of path cost, we can clearly see that the
route SBG is the cheapest route. However, if we let breadth-first search loose on the
problem it will find the non-optimal path SAG, assuming that A is the first node to be
expanded at level 1. Solve this problem using UCS …
16
Once
Node
We
Node
We
now
node
Astart
is
Sexpand
removed
isBwith
removed
has our
the
been
from
node
initial
from
expanded
the
atstate
the
queue
thequeue
front
and
it isand
expand
removed
and
ofthe
the
the
revealed
queue,
it…
revealed
from node
the
node
nodes
queue
A.
(node
Press
are
and
G)
added
space
the
is added
revealed
to
tothe
continue.
toqueue.
the
node
queue.
The
The
(node
queue
queue
G) isisis
then
added.
again
sorted
The
sorted
on
queue
on
pathpath
iscost.
again
cost.
Nodes
sorted
Note,
with
on
wepath
cheaper
havecost.
now
path
Note,
found
costnode
ahave
goal
Gpriority.In
state
now appears
but do
this
not
incase
recognise
the
the
queue
queue
it
twice,
as
will
it once
is
benot
Node
as
at G
the
A10(1),
front
andnode
once
of the
Bas(5),
queue.
G11followed
. AsNode
G10 by
is
B at
isnode
the cheaper
front
C (15).
of Press
the
node.
queue,
space.
Presswe
space.
now
proceed to goal state. Press space.
A
1
5
S
10
5
B
15
C
G
The goal state is achieved and the
path S-B-G is returned. In relation to
path cost, UCS has found the optimal
route. Press space to end.
Press space to begin the search
Size of Queue: 031
Queue: A,
S 10G
B,
G
Empty
B,
,G
11C
,11C, C15
Nodes expanded: 3210
CurrentFINISHED
Current
action: Waiting….
action:
Backtracking
Expanding
SEARCH
Current level: 210n/a
UNIFORM COST SEARCH PATTERN
17