Artificial Intelligence: Problem Solving and Search

vinegarclothΤεχνίτη Νοημοσύνη και Ρομποτική

17 Ιουλ 2012 (πριν από 5 χρόνια και 3 μήνες)

351 εμφανίσεις

ArtificialIntelligence
ProblemSolvingandSearch
Readings:
Chapter3ofRussell&Norvig.
ArtificialIntelligence–p.1/89
Example:Romania
Problem
:OnholidayinRomania;currentlyinArad.
FlightleavestomorrowfromBucharest.Findashort
routetodrivetoBucharest.
Formulateproblem
:
states
:variouscities
actions
:drivebetweencities
solution
:sequenceofcities,e.g.,Arad,Sibiu,
Fagaras,Bucharest
ArtificialIntelligence–p.2/89
Example:Romania
Giurgiu
Urziceni
Hirsova
Eforie
Neamt
Oradea
Zerind
Arad
Timisoara
Lugoj
Mehadia
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
ArtificialIntelligence–p.3/89
Problemtypes
Deterministic,fullyobservable
=⇒
single-stateproblem
Agentknowsexactlywhichstateitwillbein;solution
isasequence
Non-observable
=⇒
conformantproblem
Agentmayhavenoideawhereitis;solution(ifany)
isasequence
Nondeterministicand/orpartiallyobservable
=⇒
contingencyproblem
perceptsprovide
new
informationaboutcurrentstate
solutionisa
tree
or
policy
often
interleave
search,execution
Unknownstatespace
=⇒
explorationproblem
(“online”)
ArtificialIntelligence–p.4/89
ProblemSolving
Wewillstartbyconsideringthesimplercasesinwhichthe
followingholds.
Theagent’sworld(environment)isrepresentablebya discretesetofstates
.
Theagent’sactionsarerepresentablebya
discretesetof
operators
.
Theworldis
static
and
deterministic
.
ArtificialIntelligence–p.5/89
Example:VacuumWorld
Single-state
,
startin#5.
Solution
??
.
12
34
56
78
ArtificialIntelligence–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
ArtificialIntelligence–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
ArtificialIntelligence–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
ArtificialIntelligence–p.9/89
Single-stateproblemformulation
A
problem
isdefinedbyfouritems:
initialstate
e.g.,“atArad”
successorfunction
S(x)=setofaction–statepairs
e.g.,S(Arad)={hArad→Zerind,Zerindi,...}
goaltest
,canbe
explicit
,e.g.,x=“atBucharest”
implicit
,e.g.,NoDirt(x)
pathcost
(additive)e.g.,sumofdistances,numberof
actionsexecuted,etc.Usuallygivenasc(x,a,y),the
stepcost
fromxtoybyactiona,assumedtobe≥0.
A
solution
isasequenceofactionsleadingfromthe
initialstatetoagoalstate
ArtificialIntelligence–p.10/89
SelectingaStateSpace
Realworldisabsurdlycomplex⇒statespacemustbe
abstracted
forproblemsolving
(Abstract)state=setofrealstates
(Abstract)action=complexcombinationofrealactions
e.g.,“Arad→Zerind”representsacomplexsetof
possibleroutes,detours,reststops,etc.
Forguaranteedrealizability,
any
realstate“inArad”
mustgetto
some
realstate“inZerind”.
Eachabstractactionshouldbe“easier”thanthe
originalproblem!
(Abstract)solution=setofrealpathsthataresolutions
intherealworld
ArtificialIntelligence–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
??
ArtificialIntelligence–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)
ArtificialIntelligence–p.13/89
FormulatingProblemasaGraph
Inthegraph
eachnoderepresentsapossible
state
;
anodeisdesignatedasthe
initialstate
;
oneormorenodesrepresent
goalstates
,statesinwhich
theagent’sgoalisconsideredaccomplished.
eachedgerepresentsa
statetransition
causedbya
specificagentaction;
associatedtoeachedgeisthe
cost
ofperformingthat
transition.
ArtificialIntelligence–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:
costoffindingapath;
costoftraversingapath.
ArtificialIntelligence–p.15/89
ProblemSolvingasSearch
Searchspace
:setofstatesreachablefromaninitialstateS
0
viaa(possiblyempty/finite/infinite)sequenceofstate
transitions.
Toachievetheproblem’sgoal
search
thespacefora(possiblyoptimal)sequenceof
transitionsstartingfromS
0
andleadingtoagoalstate;
execute
(inorder)theactionsassociatedtoeach
transitionintheidentifiedsequence.
Dependingonthefeaturesoftheagent’sworldthetwosteps
abovecanbeinterleaved.
ArtificialIntelligence–p.16/89
ProblemSolvingasSearch
Reducetheoriginalproblemtoasearchproblem.
Asolutionforthesearchproblemisapathinitial
state–goalstate.
Thesolutionfortheoriginalproblemiseither
thesequenceofactionsassociatedwiththepathor
thedescriptionofthegoalstate.
ArtificialIntelligence–p.17/89
Example:The8-puzzle
217
6
83
45
Itcanbegeneralizedto15-puzzle,24-puzzle,or
(n
2
−1)-puzzleforn≥6.
ArtificialIntelligence–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
ArtificialIntelligence–p.19/89
Example:The8-puzzle
States:
configurationsoftiles
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.)
Howcananartificialagentrepresentthestatesandthestate
spaceforthisproblem?
ArtificialIntelligence–p.20/89
ProblemFormulation
1.Chooseanappropriatedatastructuretorepresentthe
worldstates.
2.Defineeachoperatorasaprecondition/effectspair
wherethe
precondition
holdsexactlyinthestatestheoperator
appliesto,
effects
describehowastatechangesintoa
successorstatebytheapplicationoftheoperator.
3.Specifyaninitialstate.
4.Provideadescriptionofthegoal(usedtocheckifa
reachedstateisagoalstate).
ArtificialIntelligence–p.21/89
Formulatingthe8-puzzleProblem
States:
eachrepresentedbya3×3arrayofnumbersin
[0...8],wherevalue0isfortheemptycell.
217
6
83
45
becomesA=
283
164
705
ArtificialIntelligence–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
ArtificialIntelligence–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!
ArtificialIntelligence–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))
ArtificialIntelligence–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
ArtificialIntelligence–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)
ArtificialIntelligence–p.27/89
Halfstatesarenotreachable?
Canthisbedone?
1
2
3
4
5
6
7
8
anysteps
=⇒
1
2
3
4
5
6
8
7
$1,000awardforanyonewhocandoit!
ArtificialIntelligence–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
Thefirstonehas0inversionsandthesecondhas1.
Claim:#ofinversionsmodulotworemainsthesameaftereachmove.
ArtificialIntelligence–p.29/89
TheWaterJugsProblem
3gl
4gl
Getexactly2gallonsofwaterintothe4gljug.
ArtificialIntelligence–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
ArtificialIntelligence–p.31/89
TheWaterJugsProblem:Operators
F4:filljug4fromthepump.
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
...
ArtificialIntelligence–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
ArtificialIntelligence–p.33/89
Real-WorldSearchProblems
RouteFinding
(computernetworks,airlinetravelplanningsystem,...)
TravellingSalesmanOptimizationProblem
(packagedelivery,automaticdrills,...)
LayoutProblems
(VLSIlayout,furniturelayout,packaging,...)
AssemblySequencing
(assemblyofelectricmotors,...)
TaskScheduling
(manufacturing,timetables,...)
ArtificialIntelligence–p.34/89
ProblemSolution
Problemswhosesolutionisadescriptionofhowto
reachagoalstatefromtheinitialstate:
n-puzzle
route-findingproblem
assemblysequencing
Problemswhosesolutionissimplyadescriptionofthe
goalstateitself:
8-queenproblem
schedulingproblems
layoutproblems
ArtificialIntelligence–p.35/89
MoreonGraphs
Agraphisasetofnotesandedges(arcs)betweenthem.
C
S
A
G
E
B
D
F
Agraphisdirectedifanedgecanbetraversedonlyina
specifieddirection.
Whenanedgeisdirectedfromn
i
ton
j
itisunivocallyidentifiedbythepair(n
i
,n
j
)
n
i
isaparent(orpredecessor)ofn
j
n
j
isachild(orsuccessor)ofn
i
ArtificialIntelligence–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
isadescendantofN
i
.
Agraphiscyclicifithasapathstartingfromandending
intothesamenode.Ex:h(A,D),(D,E),(E,A)i
a
Notethatapathoflengthk>0containsk+1nodes.
ArtificialIntelligence–p.37/89
FromSearchGraphstoSearchTrees
Thesetofallpossiblepathsofagraphcanberepresented
asatree.
Atreeisadirectedacyclicgraphallofwhosenodes
haveatmostoneparent.
Arootofatreeisanodewithnoparents.
Aleafisanodewithnochildren.
Thebranchingfactorofanodeisthenumberofits
children.
Graphscanbeturnedintotreesbyduplicatingnodesand
breakingcyclicpaths,ifany.
ArtificialIntelligence–p.38/89
FromGraphstoTrees
Tounravelagraphintoatreechoosearootnodeandtrace
everypathfromthatnodeuntilyoureachaleafnodeora
nodealreadyinthatpath.
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
thetreehasinfinitepathsonlyifthegraphhasinfinitenon-cyclicpaths.
ArtificialIntelligence–p.39/89
TreeSearchAlgorithms
Basicidea:offline,simulatedexplorationofstatespacebygenerating
successorsofalready-exploredstates(a.k.a.
expanding
states)
functionTREE-SEARCH(problem,strategy)returnsasolution,orfailure
initializethesearchtreeusingtheinitialstateofproblem
loopdo
iftherearenocandidatesforexpansionthenreturnfailure
choosealeafnodeforexpansionaccordingtostrategy
ifthenodecontainsagoalstatethenreturnthesolution
elseexpandthenodeandaddtheresultingnodestothesearchtree
end
ArtificialIntelligence–p.40/89
TreeSearchExample
Rimnicu Vilcea
Lugoj
Zerind
Sibiu
Arad
Fagaras
Oradea
Timisoara
Arad
Arad
Oradea
Arad
ArtificialIntelligence–p.41/89
Treesearchexample
Rimnicu Vilcea
Lugoj
Arad
Fagaras
Oradea
Arad
Arad
Oradea
Zerind
Arad
Sibiu
Timisoara
ArtificialIntelligence–p.42/89
TreeSearchExample
Lugoj
Arad
Arad
Oradea
Rimnicu Vilcea
Zerind
Arad
Sibiu
Arad
Fagaras
Oradea
Timisoara
ArtificialIntelligence–p.43/89
Implementation:statesvs.nodes
A
state
isa(representationof)aphysicalconfiguration
A
node
isadatastructureconstitutingpartofasearchtree
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,fillinginthevarious
fieldsandusingthe
S
UCCESSOR
F
Noftheproblemtocreate
thecorrespondingstates.
ArtificialIntelligence–p.44/89
SearchStrategies
Astrategyisdefinedbypickingthe
orderofnode
expansion
.Strategiesareevaluatedalongthefollowing
dimensions:
completeness
—doesitalwaysfindasolutionifone
exists?
timecomplexity
—numberofnodes
generated/expanded
spacecomplexity
—maximumnumberofnodesin
memory
optimality
—doesitalwaysfindaleast-costsolution?
Timeandspacecomplexityaremeasuredintermsof
b—maximumbranchingfactorofthesearchtree
d—depthoftheleast-costsolution
m—maximumdepthofthestatespace(maybe∞)
ArtificialIntelligence–p.45/89
UninformedSearchStrategies
Uninformed
strategiesuseonlytheinformationavailable
intheproblemdefinition
Breadth-firstsearch
Uniform-costsearch
Depth-firstsearch
Depth-limitedsearch
Iterativedeepeningsearch
ArtificialIntelligence–p.46/89
Breadth-FirstSearch
Expandshallowestunexpandednode
Implementation
:
fringe
isaFIFOqueue,i.e.,new
successorsgoatend
A
B
C
D
E
F
G
ArtificialIntelligence–p.47/89
Breadth-FirstSearch
Expandshallowestunexpandednode
Implementation
:
fringe
isaFIFOqueue,i.e.,new
successorsgoatend
A
B
C
D
E
F
G
ArtificialIntelligence–p.48/89
Breadth-FirstSearch
Expandshallowestunexpandednode
Implementation
:
fringe
isaFIFOqueue,i.e.,new
successorsgoatend
A
B
C
D
E
F
G
ArtificialIntelligence–p.49/89
Breadth-FirstSearch
Expandshallowestunexpandednode
Implementation
:
fringe
isaFIFOqueue,i.e.,new
successorsgoatend
A
B
C
D
E
F
G
ArtificialIntelligence–p.50/89
PropertiesofBreadth-FirstSearch
Complete
??
ArtificialIntelligence–p.51/89
PropertiesofBreadth-FirstSearch
Complete
??
Yes(ifbisfinite)
Time
??
ArtificialIntelligence–p.52/89
PropertiesofBreadth-FirstSearch
Complete
??
Yes(ifbisfinite)
Time
??
1+b+b
2
+b
3
+...+b
d
+b(b
d
−1)=O(b
d+1
),i.e.,
exp.ind
Space
??
ArtificialIntelligence–p.53/89
PropertiesofBreadth-FirstSearch
Complete
??
Yes(ifbisfinite)
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
??
ArtificialIntelligence–p.54/89
PropertiesofBreadth-FirstSearch
Complete
??
Yes(ifbisfinite)
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
??
ArtificialIntelligence–p.55/89
PropertiesofBreadth-FirstSearch
Complete
??
Yes(ifbisfinite)
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.
ArtificialIntelligence–p.56/89
Uniform-CostSearch
Expandleast-costunexpandednode
Implementation
:
fringe
=queueorderedbypathcost
Equivalenttobreadth-firstifstepcostsallequal
Complete
??
Yes,ifstepcost≥ǫ
Time
??
#ofnodeswithg≤costofoptimalsolution,
O(b
⌈C
∗/ǫ⌉
)whereC

isthecostoftheoptimalsolution
Space
??
#ofnodeswithg≤costofoptimalsolution,
O(b
⌈C
∗/ǫ⌉
)
Optimal
??
Yes—nodesexpandedinincreasingorderofg(n)
ArtificialIntelligence–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
ArtificialIntelligence–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
ArtificialIntelligence–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
ArtificialIntelligence–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
ArtificialIntelligence–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
ArtificialIntelligence–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
ArtificialIntelligence–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
ArtificialIntelligence–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
ArtificialIntelligence–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
ArtificialIntelligence–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
ArtificialIntelligence–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
ArtificialIntelligence–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
ArtificialIntelligence–p.69/89
Propertiesofdepth-firstsearch
Complete
??
ArtificialIntelligence–p.70/89
Propertiesofdepth-firstsearch
Complete
??
No:failsininfinite-depthspaces,spaceswith
loopsModifytoavoidrepeatedstatesalongpath⇒
completeinfinitespaces
Time
??
ArtificialIntelligence–p.71/89
Propertiesofdepth-firstsearch
Complete
??
No:failsininfinite-depthspaces,spaceswith
loopsModifytoavoidrepeatedstatesalongpath⇒
completeinfinitespaces
Time
??
O(b
m
):terribleifmismuchlargerthandbutif
solutionsaredense,maybemuchfasterthanbreadth-first
Space
??
ArtificialIntelligence–p.72/89
Propertiesofdepth-firstsearch
Complete
??
No:failsininfinite-depthspaces,spaceswith
loopsModifytoavoidrepeatedstatesalongpath⇒
completeinfinitespaces
Time
??
O(b
m
):terribleifmismuchlargerthandbutif
solutionsaredense,maybemuchfasterthanbreadth-first
Space
??
O(bm),i.e.,linearspace!
Optimal
??
ArtificialIntelligence–p.73/89
Propertiesofdepth-firstsearch
Complete
??
No:failsininfinite-depthspaces,spaceswith
loopsModifytoavoidrepeatedstatesalongpath⇒
completeinfinitespaces
Time
??
O(b
m
):terribleifmismuchlargerthandbutif
solutionsaredense,maybemuchfasterthanbreadth-first
Space
??
O(bm),i.e.,linearspace!
Optimal
??
No
ArtificialIntelligence–p.74/89
Depth-LimitedSearch
=depth-firstsearchwithdepthlimitl,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
ArtificialIntelligence–p.75/89
IterativeDeepeningSearch
functionIterative-Deepening-Search(problem)returnsoln
fordepthfrom0toMAX-INTdo
result:=Depth-Limited-Search(problem,depth)
if(result!=cutoff)thenreturnresult
endfor
endfunction
ArtificialIntelligence–p.76/89
Iterativedeepeningsearchl=0
Limit = 0
A
A
ArtificialIntelligence–p.77/89
Iterativedeepeningsearchl=1
Limit = 1
A
B
C
A
B
C
A
B
C
A
B
C
ArtificialIntelligence–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
ArtificialIntelligence–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
ArtificialIntelligence–p.80/89
Propertiesofiterativedeepeningsearch
Complete
??
ArtificialIntelligence–p.81/89
Propertiesofiterativedeepeningsearch
Complete
??
Yes
Time
??
ArtificialIntelligence–p.82/89
Propertiesofiterativedeepeningsearch
Complete
??
Yes
Time
??
(d+1)b
0
+db
1
+(d−1)b
2
+...+b
d
=O(b
d
)
Space
??
ArtificialIntelligence–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
??
ArtificialIntelligence–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=1Canbemodifiedtoexplore
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
ArtificialIntelligence–p.85/89
SummaryofAlgorithms
Criterion
Breadth-Uniform-Depth-Depth-Iterative
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
ArtificialIntelligence–p.86/89
Repeatedstates
Failuretodetectrepeatedstatescanturnalinearproblem
intoanexponentialone!
A B
C D
A
BB
CCCC
ArtificialIntelligence–p.87/89
Summary
Problemformulationusuallyrequiresabstractingaway
real-worlddetailstodefineastatespacethatcan
feasiblybeexplored
Varietyofuninformedsearchstrategies
Iterativedeepeningsearchusesonlylinearspaceand
notmuchmoretimethanotheruninformedalgorithms
ArtificialIntelligence–p.88/89
Example:Romania
Foragivenstrategy,whatistheorderofnodestobegenerated(orstored),andexpanded?
Withorwithoutcheckingduplicatednodes?
Giurgiu
Urziceni
Hirsova
Eforie
Neamt
Oradea
Zerind
Arad
Timisoara
Lugoj
Mehadia
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
Breadth-first
Depth-first
Uniform-cost
Depth-limited
Iterative-deepening
ArtificialIntelligence–p.89/89