# Artificial Intelligence: Problem Solving and Search

AI and Robotics

Jul 17, 2012 (5 years and 10 months ago)

394 views

ArtiﬁcialIntelligence
ProblemSolvingandSearch
Chapter3ofRussell&Norvig.
ArtiﬁcialIntelligence–p.1/89
Example:Romania
Problem
FlightleavestomorrowfromBucharest.Findashort
routetodrivetoBucharest.
Formulateproblem
:
states
:variouscities
actions
:drivebetweencities
solution
Fagaras,Bucharest
ArtiﬁcialIntelligence–p.2/89
Example:Romania
Giurgiu
Urziceni
Hirsova
Eforie
Neamt
Zerind
Timisoara
Lugoj
Dobreta
Craiova
Sibiu
Fagaras
Pitesti
Vaslui
Iasi
Rimnicu Vilcea
Bucharest
71
75
118
111
70
75
120
151
140
99
80
97
101
211
138
146
85
90
98
142
92
87
86
ArtiﬁcialIntelligence–p.3/89
Problemtypes
Deterministic,fullyobservable
=⇒
single-stateproblem
Agentknowsexactlywhichstateitwillbein;solution
isasequence
Non-observable
=⇒
conformantproblem
Agentmayhavenoideawhereitis;solution(ifany)
isasequence
Nondeterministicand/orpartiallyobservable
=⇒
contingencyproblem
perceptsprovide
new
solutionisa
tree
or
policy
often
interleave
search,execution
Unknownstatespace
=⇒
explorationproblem
(“online”)
ArtiﬁcialIntelligence–p.4/89
ProblemSolving
Wewillstartbyconsideringthesimplercasesinwhichthe
followingholds.
Theagent’sworld(environment)isrepresentablebya discretesetofstates
.
Theagent’sactionsarerepresentablebya
discretesetof
operators
.
Theworldis
static
and
deterministic
.
ArtiﬁcialIntelligence–p.5/89
Example:VacuumWorld
Single-state
,
startin#5.
Solution
??
.
12
34
56
78
ArtiﬁcialIntelligence–p.6/89
Example:VacuumWorld
Single-state
,startin#5.
Solution
??
[Right,Suck]
Conformant
,startin
{1,2,3,4,5,6,7,8}
e.g.,Rightgoesto
{2,4,6,8}.
Solution
??
12
34
56
78
ArtiﬁcialIntelligence–p.7/89
Example:VacuumWorld
Single-state
,startin#5.
Solution
??
[Right,Suck]
Conformant
,startin
{1,2,3,4,5,6,7,8}
e.g.,Rightgoesto{2,4,6,8}.
Solution
??
[Right,Suck,Left,Suck]
Contingency
,startin#5
Murphy’sLaw:can
12
34
56
78
ArtiﬁcialIntelligence–p.8/89
Example:VacuumWorld
Single-state
,startin#5.
Solution
??
[Right,Suck]
Conformant
,startin
{1,2,3,4,5,6,7,8}
e.g.,Rightgoesto{2,4,6,8}.
Solution
??
[Right,Suck,Left,Suck]
Contingency
,startin#5
Murphy’sLaw:can
12
34
56
78
ArtiﬁcialIntelligence–p.9/89
Single-stateproblemformulation
A
problem
isdeﬁnedbyfouritems:
initialstate
successorfunction
S(x)=setofaction–statepairs
goaltest
,canbe
explicit
,e.g.,x=“atBucharest”
implicit
,e.g.,NoDirt(x)
pathcost
actionsexecuted,etc.Usuallygivenasc(x,a,y),the
stepcost
fromxtoybyactiona,assumedtobe≥0.
A
solution
initialstatetoagoalstate
ArtiﬁcialIntelligence–p.10/89
SelectingaStateSpace
Realworldisabsurdlycomplex⇒statespacemustbe
abstracted
forproblemsolving
(Abstract)state=setofrealstates
(Abstract)action=complexcombinationofrealactions
possibleroutes,detours,reststops,etc.
Forguaranteedrealizability,
any
mustgetto
some
realstate“inZerind”.
Eachabstractactionshouldbe“easier”thanthe
originalproblem!
(Abstract)solution=setofrealpathsthataresolutions
intherealworld
ArtiﬁcialIntelligence–p.11/89
Statespacegraphofvacuumworld
R L
S
S
SS
R L
R L
R L
S
S
S
S
L
L
L
L
R
R
R
R
states
??
actions
??
goaltest
??
pathcost
??
ArtiﬁcialIntelligence–p.12/89
Statespacegraphofvacuumworld
R L
S
S
SS
R L
R L
R L
S
S
S
S
L
L
L
L
R
R
R
R
states
??
:integerdirtandrobotlocations(ignoredirt
amounts
)
actions
??
:Left,Right,Suck,NoOp
goaltest
??
:nodirt
pathcost
??
:1peraction(0forNoOp)
ArtiﬁcialIntelligence–p.13/89
FormulatingProblemasaGraph
Inthegraph
eachnoderepresentsapossible
state
;
anodeisdesignatedasthe
initialstate
;
oneormorenodesrepresent
goalstates
,statesinwhich
theagent’sgoalisconsideredaccomplished.
eachedgerepresentsa
statetransition
causedbya
speciﬁcagentaction;
associatedtoeachedgeisthe
cost
ofperformingthat
transition.
ArtiﬁcialIntelligence–p.14/89
SearchGraph
Howdowereachagoalstate?
4
3
3
5
7
4
2
5
4
2
B
F
A
S
G
C
D
initial state
goal states
E
Theremaybeseveralpossibleways.Ornone!
Factorstoconsider:
costofﬁndingapath;
costoftraversingapath.
ArtiﬁcialIntelligence–p.15/89
ProblemSolvingasSearch
Searchspace
:setofstatesreachablefromaninitialstateS
0
viaa(possiblyempty/ﬁnite/inﬁnite)sequenceofstate
transitions.
Toachievetheproblem’sgoal
search
thespacefora(possiblyoptimal)sequenceof
transitionsstartingfromS
0
execute
(inorder)theactionsassociatedtoeach
transitionintheidentiﬁedsequence.
Dependingonthefeaturesoftheagent’sworldthetwosteps
abovecanbeinterleaved.
ArtiﬁcialIntelligence–p.16/89
ProblemSolvingasSearch
Reducetheoriginalproblemtoasearchproblem.
Asolutionforthesearchproblemisapathinitial
state–goalstate.
Thesolutionfortheoriginalproblemiseither
thesequenceofactionsassociatedwiththepathor
thedescriptionofthegoalstate.
ArtiﬁcialIntelligence–p.17/89
Example:The8-puzzle
217
6
83
45
Itcanbegeneralizedto15-puzzle,24-puzzle,or
(n
2
−1)-puzzleforn≥6.
ArtiﬁcialIntelligence–p.18/89
Example:The8-puzzle
GofromstateStostateG.
(G)
(S)
283
164
75
123
6
457
8
R
L
L
R
DU
DU
L
L
R
R
DDU
U
164
75283
83
164
57
83
14
756
83
164
75
83
16
754
83
1
756
4
3
14
756
8
83
4
756
1
83
64
571
2
22
22
222
ArtiﬁcialIntelligence–p.19/89
Example:The8-puzzle
States:
conﬁgurationsoftiles
Operators:
moveonetileUp/Down/Left/Right
Thereare9!=362,880possiblestates(allpermutations
of{⊓⊔,1,2,3,4,5,6,7,8}).
Thereare16!possiblestatesfor15-puzzle.
Notallstatesaredirectlyreachablefromagivenstate.
(Infact,exactlyhalfofthemarereachablefromagiven
state.)
Howcananartiﬁcialagentrepresentthestatesandthestate
spaceforthisproblem?
ArtiﬁcialIntelligence–p.20/89
ProblemFormulation
1.Chooseanappropriatedatastructuretorepresentthe
worldstates.
2.Deﬁneeachoperatorasaprecondition/effectspair
wherethe
precondition
holdsexactlyinthestatestheoperator
appliesto,
effects
describehowastatechangesintoa
successorstatebytheapplicationoftheoperator.
3.Specifyaninitialstate.
reachedstateisagoalstate).
ArtiﬁcialIntelligence–p.21/89
Formulatingthe8-puzzleProblem
States:
eachrepresentedbya3×3arrayofnumbersin
[0...8],wherevalue0isfortheemptycell.
217
6
83
45
becomesA=
283
164
705
ArtiﬁcialIntelligence–p.22/89
Formulatingthe8-puzzleProblem
Operators:
24operatorsoftheform
Op
(r,c,d)
wherer,c∈{1,2,3},d∈{L,R,U,D}.
Op
(r,c,d)
movestheemptyspaceatposition(r,c)in
thedirectiond.
283
164
705
Op
(3,2,L)
=⇒
283
164
075
ArtiﬁcialIntelligence–p.23/89
PreconditionsandEffects
Example:Op
(3,2,R)
283
164
705
Op
(3,2,R)
=⇒
283
164
750
Preconditions:
A[3,2]=0
Effects:
(
A[3,2]←A[3,3]
A[3,3]←0
Wehave24operatorsinthisproblemformulation...
20toomany!
ArtiﬁcialIntelligence–p.24/89
ABetterFormulation
States:
eachrepresentedbyapair(A,(i,j))where:
Aisa3×3arrayofnumbersin[0...8]
(i,j)isthepositionoftheemptyspace(0)inthearray.
217
6
83
45
becomes(
283
164
705
,(3,2))
ArtiﬁcialIntelligence–p.25/89
ABetterFormulation
Operators:
4operatorsoftheform
Op
d
where
d∈{L,R,U,D}.
Op
d
movestheemptyspaceinthedirectiond.
283
164
705
Op
L
=⇒
283
164
075
ArtiﬁcialIntelligence–p.26/89
PreconditionsandEffects
Example:Op
L
(
283
164
705
,(3,2))
Op
L
=⇒(
283
164
075
(3,1))
Let(r
0
,c
0
)bethepositionof0inA.
Preconditions:
c
0
>1
Effects:

A[r
0
,c
0
]←A[r
0
,c
0
−1]
A[r
0
,c
0
−1]←0
(r
0
,c
0
)←(r
0
,c
0
−1)
ArtiﬁcialIntelligence–p.27/89
Halfstatesarenotreachable?
Canthisbedone?
1
2
3
4
5
6
7
8
anysteps
=⇒
1
2
3
4
5
6
8
7
\$1,000awardforanyonewhocandoit!
ArtiﬁcialIntelligence–p.28/89
Halfstatesarenotreachable?
a
1
a
2
a
3
a
4
a
5
a
6
a
7
a
8
a
9
Letthe8-puzzleberepresentedby(a
1
,a
2
,a
3
,a
4
,a
5
,a
6
,a
7
,a
8
,a
9
).Wesay
(a
i
,a
j
)isaninversionifneithera
i
nora
j
isblank,i<janda
i
>a
j
.
1
2
3
4
5
6
7
8
1
2
3
4
5
6
8
7
Theﬁrstonehas0inversionsandthesecondhas1.
Claim:#ofinversionsmodulotworemainsthesameaftereachmove.
ArtiﬁcialIntelligence–p.29/89
TheWaterJugsProblem
3gl
4gl
Getexactly2gallonsofwaterintothe4gljug.
ArtiﬁcialIntelligence–p.30/89
TheWaterJugsProblem
States:
Determinedbytheamountofwaterineachjug.
StateRepresentation:
Tworeal-valuedvariables,J
3
,J
4
,
indicatingtheamountofwaterinthetwojugs,withthe
constraints:
0≤J
3
≤3,0≤J
4
≤4
InitialStateDescription
J
3
=0,J
4
=0
GoalStateDescription:
J
4
=2⇐nonexhaustivedescription
ArtiﬁcialIntelligence–p.31/89
TheWaterJugsProblem:Operators
F4:ﬁlljug4fromthepump.
precond:J
4
<4effect:J

4
=4
E4:emptyjug4ontheground.
precond:J
4
>0effect:J

4
=0
E4-3:pourwaterfromjug4intojug3untiljug3isfull.
precond:J
3
<3,effect:J

3
=3,
J
4
≥3−J
3
J

4
=J
4
−(3−J
3
)
P3-4:pourwaterfromjug3intojug4untiljug4isfull.
precond:J
4
<4,effect:J

4
=4,
J
3
≥4−J
4
J

3
=J
3
−(4−J
4
)
E3-4:pourwaterfromjug3intojug4untiljug3isempty.
precond:J
3
+J
4
<4,effect:J

4
=J
3
+J
4
,
J
3
>0J

3
=0
...
ArtiﬁcialIntelligence–p.32/89
TheWaterJugsProblem
J_3 = 2 J_4 = 4
J_3 = 2 J_4 = 0
J_3 = 0 J_4 = 2
J_3 = 0 J_4 = 4
J_3 = 3 J_4 = 0
J_3 = 0 J_4 = 0
J_3 = 3 J_4 = 4
J_3 = 0 J_4 = 4
J_3 = 0 J_4 = 3
J_3 = 3 J_4 = 3
J_3 = 3 J_4 = 1
. . .. . .. . .
. . .
F3
E3-4
F3P4-3
F4
E3-4F4
F3
P3-4
E4
J_3 = 0 J_4 = 0
J_4 = 2
ProblemSearch Graph
ArtiﬁcialIntelligence–p.33/89
Real-WorldSearchProblems
RouteFinding
(computernetworks,airlinetravelplanningsystem,...)
TravellingSalesmanOptimizationProblem
(packagedelivery,automaticdrills,...)
LayoutProblems
(VLSIlayout,furniturelayout,packaging,...)
AssemblySequencing
(assemblyofelectricmotors,...)
(manufacturing,timetables,...)
ArtiﬁcialIntelligence–p.34/89
ProblemSolution
reachagoalstatefromtheinitialstate:
n-puzzle
route-ﬁndingproblem
assemblysequencing
goalstateitself:
8-queenproblem
schedulingproblems
layoutproblems
ArtiﬁcialIntelligence–p.35/89
MoreonGraphs
Agraphisasetofnotesandedges(arcs)betweenthem.
C
S
A
G
E
B
D
F
Agraphisdirectedifanedgecanbetraversedonlyina
speciﬁeddirection.
Whenanedgeisdirectedfromn
i
ton
j
itisunivocallyidentiﬁedbythepair(n
i
,n
j
)
n
i
isaparent(orpredecessor)ofn
j
n
j
isachild(orsuccessor)ofn
i
ArtiﬁcialIntelligence–p.36/89
DirectedGraphs
C
S
A
G
E
B
D
F
Apath,oflengthk≥0,isasequence
h(n
1
,n
2
),(n
2
,n
3
),...,(n
k
,n
k+1
)iofksuccessiveedges.
a
Ex:hi,h(S,D)i,h(S,D),(D,E),(E,B)i
For1≤i<j≤k+1,
N
i
isaancestorofN
j
;N
j
i
.
Agraphiscyclicifithasapathstartingfromandending
intothesamenode.Ex:h(A,D),(D,E),(E,A)i
a
Notethatapathoflengthk>0containsk+1nodes.
ArtiﬁcialIntelligence–p.37/89
FromSearchGraphstoSearchTrees
Thesetofallpossiblepathsofagraphcanberepresented
asatree.
haveatmostoneparent.
Arootofatreeisanodewithnoparents.
Aleafisanodewithnochildren.
Thebranchingfactorofanodeisthenumberofits
children.
Graphscanbeturnedintotreesbyduplicatingnodesand
breakingcyclicpaths,ifany.
ArtiﬁcialIntelligence–p.38/89
FromGraphstoTrees
Tounravelagraphintoatreechoosearootnodeandtrace
everypathfromthatnodeuntilyoureachaleafnodeora
G
S
A
B
D
D
E
F
S
A
B
F
C
G
A
A
D
G
E
G
C
E
D
. . .
depth 4
depth 2
depth 1
depth 0 depth 3
mustrememberwhichnodeshavebeenvisited
anodemaygetduplicatedseveraltimesinthetree
thetreehasinﬁnitepathsonlyifthegraphhasinﬁnitenon-cyclicpaths.
ArtiﬁcialIntelligence–p.39/89
TreeSearchAlgorithms
Basicidea:ofﬂine,simulatedexplorationofstatespacebygenerating
expanding
states)
functionTREE-SEARCH(problem,strategy)returnsasolution,orfailure
initializethesearchtreeusingtheinitialstateofproblem
loopdo
iftherearenocandidatesforexpansionthenreturnfailure
choosealeafnodeforexpansionaccordingtostrategy
ifthenodecontainsagoalstatethenreturnthesolution
end
ArtiﬁcialIntelligence–p.40/89
TreeSearchExample
Rimnicu Vilcea
Lugoj
Zerind
Sibiu
Fagaras
Timisoara
ArtiﬁcialIntelligence–p.41/89
Treesearchexample
Rimnicu Vilcea
Lugoj
Fagaras
Zerind
Sibiu
Timisoara
ArtiﬁcialIntelligence–p.42/89
TreeSearchExample
Lugoj
Rimnicu Vilcea
Zerind
Sibiu
Fagaras
Timisoara
ArtiﬁcialIntelligence–p.43/89
Implementation:statesvs.nodes
A
state
isa(representationof)aphysicalconﬁguration
A
node
includes
parent
,
children
,
depth
,
pathcost
g(x)
States
donothaveparents,children,depth,orpathcost!
1
23
45 6
7
8
1
23
45 6
7
8
StateNode
depth = 6 g = 6
state
parent, action
The
E
XPANDfunctioncreatesnewnodes,ﬁllinginthevarious
ﬁeldsandusingthe
S
UCCESSOR
F
Noftheproblemtocreate
thecorrespondingstates.
ArtiﬁcialIntelligence–p.44/89
SearchStrategies
Astrategyisdeﬁnedbypickingthe
orderofnode
expansion
.Strategiesareevaluatedalongthefollowing
dimensions:
completeness
—doesitalwaysﬁndasolutionifone
exists?
timecomplexity
—numberofnodes
generated/expanded
spacecomplexity
—maximumnumberofnodesin
memory
optimality
—doesitalwaysﬁndaleast-costsolution?
Timeandspacecomplexityaremeasuredintermsof
b—maximumbranchingfactorofthesearchtree
d—depthoftheleast-costsolution
m—maximumdepthofthestatespace(maybe∞)
ArtiﬁcialIntelligence–p.45/89
UninformedSearchStrategies
Uninformed
strategiesuseonlytheinformationavailable
intheproblemdeﬁnition
Uniform-costsearch
Depth-ﬁrstsearch
Depth-limitedsearch
Iterativedeepeningsearch
ArtiﬁcialIntelligence–p.46/89
Expandshallowestunexpandednode
Implementation
:
fringe
isaFIFOqueue,i.e.,new
successorsgoatend
A
B
C
D
E
F
G
ArtiﬁcialIntelligence–p.47/89
Expandshallowestunexpandednode
Implementation
:
fringe
isaFIFOqueue,i.e.,new
successorsgoatend
A
B
C
D
E
F
G
ArtiﬁcialIntelligence–p.48/89
Expandshallowestunexpandednode
Implementation
:
fringe
isaFIFOqueue,i.e.,new
successorsgoatend
A
B
C
D
E
F
G
ArtiﬁcialIntelligence–p.49/89
Expandshallowestunexpandednode
Implementation
:
fringe
isaFIFOqueue,i.e.,new
successorsgoatend
A
B
C
D
E
F
G
ArtiﬁcialIntelligence–p.50/89
Complete
??
ArtiﬁcialIntelligence–p.51/89
Complete
??
Yes(ifbisﬁnite)
Time
??
ArtiﬁcialIntelligence–p.52/89
Complete
??
Yes(ifbisﬁnite)
Time
??
1+b+b
2
+b
3
+...+b
d
+b(b
d
−1)=O(b
d+1
),i.e.,
exp.ind
Space
??
ArtiﬁcialIntelligence–p.53/89
Complete
??
Yes(ifbisﬁnite)
Time
??
1+b+b
2
+b
3
+...+b
d
+b(b
d
−1)=O(b
d+1
),i.e.,
exp.ind
Space
??
O(b
d+1
)(keepseverynodeinmemory)
Optimal
??
ArtiﬁcialIntelligence–p.54/89
Complete
??
Yes(ifbisﬁnite)
Time
??
1+b+b
2
+b
3
+...+b
d
+b(b
d
−1)=O(b
d+1
),i.e.,
exp.ind
Space
??
O(b
d+1
)(keepseverynodeinmemory)
Optimal
??
Yes(ifcost=1perstep);notoptimalingeneral
Space
??
ArtiﬁcialIntelligence–p.55/89
Complete
??
Yes(ifbisﬁnite)
Time
??
1+b+b
2
+b
3
+...+b
d
+b(b
d
−1)=O(b
d+1
),i.e.,
exp.ind
Space
??
O(b
d+1
)(keepseverynodeinmemory)
Optimal
??
Yes(ifcost=1perstep);notoptimalingeneral
Space
??
Itisthebigproblem;caneasilygeneratenodesat
10MB/secso24hrs=860GB.
ArtiﬁcialIntelligence–p.56/89
Uniform-CostSearch
Expandleast-costunexpandednode
Implementation
:
fringe
=queueorderedbypathcost
Complete
??
Yes,ifstepcost≥ǫ
Time
??
#ofnodeswithg≤costofoptimalsolution,
O(b
⌈C
∗/ǫ⌉
)whereC

isthecostoftheoptimalsolution
Space
??
#ofnodeswithg≤costofoptimalsolution,
O(b
⌈C
∗/ǫ⌉
)
Optimal
??
Yes—nodesexpandedinincreasingorderofg(n)
ArtiﬁcialIntelligence–p.57/89
Depth-FirstSearch
Expanddeepestunexpandednode
Implementation
:
fringe
=LIFOqueue,i.e.,putsuccessorsat
front
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
ArtiﬁcialIntelligence–p.58/89
Depth-FirstSearch
Expanddeepestunexpandednode
Implementation
:
fringe
=LIFOqueue,i.e.,putsuccessorsat
front
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
ArtiﬁcialIntelligence–p.59/89
Depth-FirstSearch
Expanddeepestunexpandednode
Implementation
:
fringe
=LIFOqueue,i.e.,putsuccessorsat
front
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
ArtiﬁcialIntelligence–p.60/89
Depth-FirstSearch
Expanddeepestunexpandednode
Implementation
:
fringe
=LIFOqueue,i.e.,putsuccessorsat
front
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
ArtiﬁcialIntelligence–p.61/89
Depth-FirstSearch
Expanddeepestunexpandednode
Implementation
:
fringe
=LIFOqueue,i.e.,putsuccessorsat
front
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
ArtiﬁcialIntelligence–p.62/89
Depth-FirstSearch
Expanddeepestunexpandednode
Implementation
:
fringe
=LIFOqueue,i.e.,putsuccessorsat
front
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
ArtiﬁcialIntelligence–p.63/89
Depth-FirstSearch
Expanddeepestunexpandednode
Implementation
:
fringe
=LIFOqueue,i.e.,putsuccessorsat
front
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
ArtiﬁcialIntelligence–p.64/89
Depth-FirstSearch
Expanddeepestunexpandednode
Implementation
:
fringe
=LIFOqueue,i.e.,putsuccessorsat
front
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
ArtiﬁcialIntelligence–p.65/89
Depth-FirstSearch
Expanddeepestunexpandednode
Implementation
:
fringe
=LIFOqueue,i.e.,putsuccessorsat
front
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
ArtiﬁcialIntelligence–p.66/89
Depth-FirstSearch
Expanddeepestunexpandednode
Implementation
:
fringe
=LIFOqueue,i.e.,putsuccessorsat
front
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
ArtiﬁcialIntelligence–p.67/89
Depth-FirstSearch
Expanddeepestunexpandednode
Implementation
:
fringe
=LIFOqueue,i.e.,putsuccessorsat
front
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
ArtiﬁcialIntelligence–p.68/89
Depth-FirstSearch
Expanddeepestunexpandednode
Implementation
:
fringe
=LIFOqueue,i.e.,putsuccessorsat
front
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
ArtiﬁcialIntelligence–p.69/89
Propertiesofdepth-ﬁrstsearch
Complete
??
ArtiﬁcialIntelligence–p.70/89
Propertiesofdepth-ﬁrstsearch
Complete
??
No:failsininﬁnite-depthspaces,spaceswith
loopsModifytoavoidrepeatedstatesalongpath⇒
completeinﬁnitespaces
Time
??
ArtiﬁcialIntelligence–p.71/89
Propertiesofdepth-ﬁrstsearch
Complete
??
No:failsininﬁnite-depthspaces,spaceswith
loopsModifytoavoidrepeatedstatesalongpath⇒
completeinﬁnitespaces
Time
??
O(b
m
):terribleifmismuchlargerthandbutif
Space
??
ArtiﬁcialIntelligence–p.72/89
Propertiesofdepth-ﬁrstsearch
Complete
??
No:failsininﬁnite-depthspaces,spaceswith
loopsModifytoavoidrepeatedstatesalongpath⇒
completeinﬁnitespaces
Time
??
O(b
m
):terribleifmismuchlargerthandbutif
Space
??
O(bm),i.e.,linearspace!
Optimal
??
ArtiﬁcialIntelligence–p.73/89
Propertiesofdepth-ﬁrstsearch
Complete
??
No:failsininﬁnite-depthspaces,spaceswith
loopsModifytoavoidrepeatedstatesalongpath⇒
completeinﬁnitespaces
Time
??
O(b
m
):terribleifmismuchlargerthandbutif
Space
??
O(bm),i.e.,linearspace!
Optimal
??
No
ArtiﬁcialIntelligence–p.74/89
Depth-LimitedSearch
=depth-ﬁrstsearchwithdepthlimitl,i.e.,nodesatdepthl
havenosuccessors functionDepth-Limited-Search(problem,limit)returnsoln/fail/cutoff
returnRecursive-DLS(Make-Node(Initial-State(problem)),problem,limit)
endfunction
functionRecursive-DLS(node,problem,limit)returnsoln/fail/cutoff
cutoff-occurred:=false;
if(Goal-State(problem,State(node)))thenreturnnode;
elseif(Depth(node)==limit)thenreturncutoff;
elseforeachsuccessorinExpand(node,problem)do
result:=Recursive-DLS(successor,problem,limit)
if(result==cutoff)thencutoff-occurred:=true;
elseif(result!=fail)thenreturnresult;
endfor
if(cutoff-occurred)thenreturncutoff;elsereturnfail;
endfunction
ArtiﬁcialIntelligence–p.75/89
IterativeDeepeningSearch
functionIterative-Deepening-Search(problem)returnsoln
fordepthfrom0toMAX-INTdo
result:=Depth-Limited-Search(problem,depth)
if(result!=cutoff)thenreturnresult
endfor
endfunction
ArtiﬁcialIntelligence–p.76/89
Iterativedeepeningsearchl=0
Limit = 0
A
A
ArtiﬁcialIntelligence–p.77/89
Iterativedeepeningsearchl=1
Limit = 1
A
B
C
A
B
C
A
B
C
A
B
C
ArtiﬁcialIntelligence–p.78/89
Iterativedeepeningsearchl=2
Limit = 2
A
B
C
D
E
F
G
A
B
C
D
E
F
G
A
B
C
D
E
F
G
A
B
C
D
E
F
G
A
B
C
D
E
F
G
A
B
C
D
E
F
G
A
B
C
D
E
F
G
A
B
C
D
E
F
G
ArtiﬁcialIntelligence–p.79/89
Iterativedeepeningsearchl=3
Limit = 3
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
A
B
C
D
E
F
G
H
J
K
L
M
N
O
I
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
ArtiﬁcialIntelligence–p.80/89
Propertiesofiterativedeepeningsearch
Complete
??
ArtiﬁcialIntelligence–p.81/89
Propertiesofiterativedeepeningsearch
Complete
??
Yes
Time
??
ArtiﬁcialIntelligence–p.82/89
Propertiesofiterativedeepeningsearch
Complete
??
Yes
Time
??
(d+1)b
0
+db
1
+(d−1)b
2
+...+b
d
=O(b
d
)
Space
??
ArtiﬁcialIntelligence–p.83/89
Propertiesofiterativedeepeningsearch
Complete
??
Yes
Time
??
(d+1)b
0
+db
1
+(d−1)b
2
+...+b
d
=O(b
d
)
Space
??
O(bd)
Optimal
??
ArtiﬁcialIntelligence–p.84/89
Propertiesofiterativedeepeningsearch
Complete
??
Yes
Time
??
(d+1)b
0
+db
1
+(d−1)b
2
+...+b
d
=O(b
d
)
Space
??
O(bd)
Optimal
??
Yes,ifstepcost=1Canbemodiﬁedtoexplore
uniform-costtree
Numericalcomparisonforb=10andd=5,solutionatfarright:
N(IDS)=50+400+3,000+20,000+100,000=123,450
N(BFS)=10+100+1,000+10,000+100,000+999,990=1,111,100
ArtiﬁcialIntelligence–p.85/89
SummaryofAlgorithms
Criterion
FirstCostFirstLimitedDeepening
Complete?
Yes

Yes

NoYes,ifl≥dYes
Time
b
d+1
b
⌈C

/ǫ⌉
b
m
b
l
b
d
Space
b
d+1
b
⌈C

/ǫ⌉
bmblbd
Optimal?
Yes

Yes

NoNoYes
ArtiﬁcialIntelligence–p.86/89
Repeatedstates
Failuretodetectrepeatedstatescanturnalinearproblem
intoanexponentialone!
A B
C D
A
BB
CCCC
ArtiﬁcialIntelligence–p.87/89
Summary
Problemformulationusuallyrequiresabstractingaway
real-worlddetailstodeﬁneastatespacethatcan
feasiblybeexplored
Varietyofuninformedsearchstrategies
Iterativedeepeningsearchusesonlylinearspaceand
notmuchmoretimethanotheruninformedalgorithms
ArtiﬁcialIntelligence–p.88/89
Example:Romania
Foragivenstrategy,whatistheorderofnodestobegenerated(orstored),andexpanded?
Withorwithoutcheckingduplicatednodes?
Giurgiu
Urziceni
Hirsova
Eforie
Neamt
Zerind
Timisoara
Lugoj
Dobreta
Craiova
Sibiu
Fagaras
Pitesti
Vaslui
Iasi
Rimnicu Vilcea
Bucharest
71
75
118
111
70
75
120
151
140
99
80
97
101
211
138
146
85
90
98
142
92
87
86