Searching Techniques AI
Searching Techniques AI
Search Algorithms
35.2Properties search A
agornthnsad to be
Completeness: vometr
sNpenienoe
partwular
nput. a
let one luton or
A search aleornthm
ssadto
an optunal bot
2 Optimality: e
ouonfu
(Ost. hrlow
Tme complexty he
complexity:
Tineand space
, TI andspacecompleay
3ue naamun tong
omne aken
b%
pacceared
a noda opte
A goodsearchalgorithm
akesless me o petornchecancb
operation. and spaceto do s work
Then perorm acion
e Uninformed
Search
Algorithms
AGURE 3.12Epsodic/
Non-episodic
Environment
4uninformed
search. alsoknoWn as a blundsearch
algorithm, Do h ddoai
35 Search goalstate
otherthan
to raverse
bowomorirhms.
or
che
visit
one provided
the nodes in
the machine
inheproblemdefnion.
the tree.
Theonly
oTaDon
moon be
he
soedou
blindy
Algorithms
Ong
efficientor ineficient.
tollows
che tecbnique
There can be multple
irrepecave af wteher
plansto reachthe goalsate
fom de ort
or sn
We hrvered chatarufical ischestudyof building
Intelhgence raional Theseagentsmake
agents. differ by the orderand/or length
Althese paths actions.
of
uSe of sorme or the ocher searchalgorthmsin he backgroundto achievetheir
tasks.For examnl hissection, we will read about depthfrstsearch.breadthfirsseanchand ora cos send
soTDE sn-player
gamesikealegames,Sudoku,
crossword,etc.,
use search algorithms
to deduce Each of thesealgorithms has thefollowng
orithms. nformanoo.
a
ponon n he
partculr me. graph,dhe startnodeS tothegoalnode G.
Problerm
A consistsef thefollowing:
searchproblem Strategy, thcpathfollowed
stating by the graph rechG. NT
1.Statespaces thesetof all posible thatcan be attained
states by an agent.
whichisa
Eringe.
state.
data structure
to storeallthepossible (nodechat
states a b
dhe current
2. Startstates the statefrom where thesearchingisdone.
3. Goaltestis functuonchatchecksifthecurrentsateisthegoalstateor no. Tree,thatdepictspathwhile
traversing
to thegoalnode. TR
4. Solationto asearchproblem (alsoknown as plan)thattransformsthe
is sequenceof actions
a
Solution
plan,thatspecifiesthesequenceof nodes from S to G.
l
using
searchalgorithms.
3.5.1
Typesof SearchAlgorithms Depth First
3.6.1 Search(DFS)
Inthisscarchalgorithm, the tree istraversedfrom therootnode The keywlbe searched theeaf
Fhereare iuny but,inthssectuon,we
earchalgorsthns will sixofthemosspopularly
discuss usedone.
For bettet
undertarndrg.
we will them undertwo heading-informed
categorize and unnformed
node of aparticular If
branch. thekey is notfound, then thesearchprocesbackrckst,the posetfiom
s
a
howi n ty 3.13 where the otherbranch was leftunexplored. Thisprocess repeatedfor charoherbranchcherunt
he key isfound or the entire tree iscompletely raversed.
Depin searohreah
first
seafe
In Fg 3.14, visualze
we can dearly che workingof aDPS algorith.
Here,
easch
nodeA andthenravenes n odes B.D and H.Now, H istheleaf
(node, hepath,
Lo eplore
the root
branch.NodesE and are thus l we
teta Solution: node
toreachnodeB to traverseits unexplored
to follow branch
the unexplored
travered.
Now,
nodeE.As a
,
'deepet
he node of the E bratrh
of
thepath s retraced
node, so again,
node
andthen it s foundthatallnodes inbranches
B have
beentraced
of
visited So,
t
explorng heotheruntraced branch the roott node.Here,
by
of
move further
will node
e
ThoughtheDFS algorsthm iscompleteifthesearchtree isfinite
and a solution it
exsts, Consider
Example:
optimal inreaching
as thenumber of steps thesolution, inreaching
or the costspent itshigh.
Advantages
1.Ituscslesmemorysitstoresonlythe nodeson thepathfromtheroot
nodetothecurrent no
2. It
takeslestimeto rachthegoalnode/statea comparedto theBFSalgorithm.
solution.
2. incertaincases,the algorithm
my getstuckinan infinite (DLS)
SearchAlgorithm
nodesinthe tree.A posible
deoth.1fcheideal
solutionto this
loopwhile
goingdeepscatchíng
ío
problemisto choosean appropriatevalue
s d,and thechosencut-offislesthan d. thenalgorithm
cut-off
ofcuro
DLS
Depth-Limited
3.6.2
s sinilarto the DFS algorithn wh an addonof pedeermode z a
T s
fzis.
Bat,Í
the limitations thenfnite
of pathinthe DFS, k DLS. he
the chosen cutoffs more than d,theeECUtion timeincrezses. veTCOTTe
3. Conplexity
of thealgorithm is
treated2sit a leafnode (or a node wh no uOcesoS DOdes;
depends on the numberof paths
ist ermúnated i n cas
y ofthe thset
4. DPS cannot checkduphcate nodes TheDLS algorithm
Thsiskaoro nnd
does nothaearvsolunon
r
1.Firs, ifthepToblen ass
Example:Explore
the path thatwill
be expilored
usngtheDES algorithm not have ay soluionwta 2 es de
to reach nodeG fromS
2. Second, iftheproblemdoes
failure
cut-off
isfound
when thesolution
3. Third,
DES CreatesthesameSet
For cxample,inthe tree
flve!
Fe3.15.
givenin
pte2 cbr to chr c tmge
nodes as breadthfirst H wiB notbe
d
nodesEEGand
of
method,different Dot go to level3.Therefore.
orde.
142 CAPTER3
Machin
Thus,che DLS Search u the solution
algornthm s complete ispresent
wthinthe
amat. Whaletme compleaty of DLS algonthms ob). spacecomplexitys specifed
O(bxe).
depthbmut and d s thedepehot the tree
wherelat
Level0
Level 1
Level2
1.It
san ncompletealgorhm swe may not be able to getthesolution
everytimewe do the
ifthesolution
search(even due to limtconstraint).
exists,
2. Ifmulnple
solunons
ofa problemexist,thenDLS may notbe able
to findtheoptimal
solution.
In ocherWords, thealgorithm s not optmalevenif
(>d.
Exarmple:
Travere
thegrventreeto searchnode H using
DLS withpredefined
limit
as 2.
Lmit=
2 Depth
FIGURE3.16Breadth-frst
search
limited
Search
Solution:We tartwithNode A atlevel0.
Thesearchproceshencontunus to cxplorenodes B,C,D, and E ar level
1
Now, we go to level2 and explorethe childnodes of node B.
backtracksdoneto level1 When H is not found chere, a
3.17,
In Fig. BFSalgorithm a random initial
selects node(alsoknown
kn assourcenode
orroot
insucha way thatall
and traversesthecgraphlayer-wise thenodes and their
respective node
children
and explored.
are visited Here, nodes
a
Exploringa nodemeans explorngtheadjacent nodes(childnodes)of thesclectednod.
Advantages
1. BES will
finda solutionif exists.
it
G
multiple then BES will
solutions, givethe minimalsolution
2. Ifagven problem has requiring
least
numberof steps.
issimple
ofthe BFS algorithm
3. The architecture and robust.
4. Itconstructs throughthenodes
path of traversing
theshortest of thegraphso thatthe grank
be traversed numberofiterations.
inthe smallest inthe path = the depth solution number of nodesinlvel
theshallowest
of
nodes
Thealgorithmn loop.
doesnotgetstuckinan infinite n BFS algorithm,
a
5. the sourcenode, traversethe graph and trace the
Usingnode
as
A
Considerthe graph.
Example: using a queue.
algorithm
Disadvantages workingof the
Queue
lotof memorysp2ce
1. Sinceeach levelof nodeissaved for creatingthe nextone, itconsumesa a
Spacerequirementtostorenodes isexponential.
the bottom or atthe end.
2. tIt
akes
less
timeif
the solutionisfaraway from the root node-at cb its
'a'& insert
Print nodesintothequeuei
child
nodes. a:
Print
depends on thenumberof
3. Itscomplexity the queue
nodesinto
usinga FIFO queue.Ttis a complete algorithm, thatis,itfinds
Printb:
el
d c Print itschild
'b'& insert
TheBFS algorithm isimplemented or ifall
if t hereisno cost
Thealgorithmnisoptimal,ifstepcost = 1(thati s, either
its nodesintothe queue
a solutionifitexits.
M oreover,it
has both timeand space complexity givenby,O(b). Here,b isthe Printc: glfe d & insert
'c'
Print child
factor
branching andd isthedepthofthe tree.
+ ...
+ |glfePrint'd' insertitschild
&
case isb+ b² + ba
Printd:
intheworst
b
S, node D be traversedfollowed
will
alreadyvisited.
CAPTER3
Searchlgorithn
eaith-ist Psecdocodie CostSearchUCS)
sore node Uniform
ssed
npcT: s as 3.6.4algrorithm
aoe
e
S (G, s) scenara,
the aigorirm
cemguteste
Such a
ie? De ee. node
thegoal
node to n
Sortingsdone
srs
Then
ommg
sid scadocodesshe
ods or
Dotmode of
Thesechtnods
tegn Gk ssserette
vsted ROGngsSo
n e
au
inF
fSshe
iI8,
pOde G hsa bige
oGse
sartnodeamd
o
here
go
D
sehenoeAsepiced
bGsrni
iolomed Thoug B
e s
cost osre
Ifvoe ak wdrlsq e UCS BFS
is egesishe e
fhepath cost al ot
Craulers
inSearch
Engines
BFS grims sediarmng ebpags cachweb pags coesided
pplicznior z:
mOte mzgagn The zgucn mS Sng on hesouce page foloshe nkxatet
d
GPS Navigation
Systems 12
GPS sseBFS gorchoind eghbouing
locaioms
FIGURE3.18Uniformcostsearn
Pathforan Unweighted
FindtheShortest Graph gorithn wh ie
dpa compen n
isa conpleteandoptimal
The UCS lgorithm
For m eghed parh an be eayalcalaed
gaph theshortest
unberof etgesBFS hgo hnan do chisby esingaminimum
bychoosng2pathwithche
om
number ofnodessarting
ls Oe,
complexity where & is
the costand c ishe opinal
kowest
cost
e souneode Sartetherbrezdri-firs
eahor depch-firt
rersal
methodsan be sed Advantages
erysatt
the
br considering CO lex
Broadcasting
n coputernerworksda s broken down nto mll
packes befoeransision arosste
.
L. Ittndsan opimal
S.
UCSsComplete
UCSis
solution
and
are finite
onlyifstates
onlyitthereisno negae
optimal cost
is
tther ao loopwach erowegh
G
3.6.5 combinesthe featuresof DES
algorithm and BFS algorthrns
to find
Uniformcostsearch out
rativedeepeningcan be usedtoimplement
he DLS algorithm.
iterat that
limit IDDFS doe so by gradually
The depth
Level0 the best the until
limit thegoal isfound.
increasing performsdepth-first
1,
searchto level startsovet, executes a compete
depch-frx
The algorithm continues unilthe solutionisfound It nevercreates a node untlal
2 and ower odes
to level stackof nodes.
Level1 search Itonlysavesa
are generated. benefittedfastsearch techniqueof BFS algorithm
by and memory effiencythe
IDDES gets
f
o
algorithm. iswidely
Thisalgorithmn used whenscarch
space islarge,
2nd depch the
of
search
Level2 depth-first known.
node isnot
goal
of
G 3. IDDES isan
Level
4
goalnode.
reachthe
takesmore ime
2. It
to
(exponential)
when the BFS fais.
fails
3. The algorithm
searchalgorithn.
depth-first
Example:Traversethe givenreeusingtheiterativedeepening
5
node A at level
iteration,
Inthe first
Solution: O isexplored.
Solution
For a better
clarity,
we can drzwan Inthethird
iteration,nodesD. E,F andG aretraversed.
equivalent
searchtree forthe graph.
parhwiththe least
Cumulative
costischosen.
Using
UCS,te node H isreached.
Inthefourthiteration,
depthfirst
deepening
Iterative search
LevelO
1
Level2
5 5
ve'3
150 CHAPTER 3 Artificially
lnteligent
Machine 31)
a solutionat depthd.The
ends when it
Thealgorithm finds findsthesmallestpath from thesource node to the goal
node. Thus, bidirecaonal
nodes createddisb and at depthd-1isbd-1.
at depth In The algorithm
searchgraphwithtwo smaller sub graphs-one starting
from intial
number of IDDFS,we single or startnode
space
isO(b)and its DFS search)andthe otherstarting
of IDDESalgorithm pertor replaces (termed as forward from goal node towardsthesource
Timecomplexity
goalnodebackwardsearch).
anddepth
factor of "limited search
whereb ishe branching
isO(bd),
complexity keep depth tothe as
terminateswhen thetwo graphsintersect.
nd (known process Bidirectional
searchcan be
thetree isd. increasing
limited node search distancefrom sourceto goaland vice versa. Heuristc
the depth this The estimate remaining
of
means
and demonstrate iteration.aftereveN bya heuristic
Example:Considerthe tree given below gruided pathfrom
thecurrentnode in the graphto the goalnode.
ofIDDEFS.
appication che shortest
finding below andapplybidirectional
search on it
toreach goal node
thegraph given
Consider
14
Depth = 0 Example:node0.
tromsource
9
Depth=1
12
H Depth= 2
10
Depth =3
node 14.
one from node 0 and the other from
simultaneously-,
Depth=4 searchesare executed
R
Two p
this oint, have found a pathfrom node 0 to 7 and from
Solution: 7.
at node At we
intersect
searches unnecessaryexploration.
Boththese thereby
successfully, avoiding
The tree can be visited
as: A BEFCGDH 14to 7.The searchprocessterminates
a
3.6.6
Bidirectional
Search Disadvantages
thegoalstate isclearly
known.
can be usedonlywhen
l.Thealgorithm
In a bidirectional
forward
search,
frominitial
searching
isdone from boththe directions
stateand backwardfrom goal statetill
simultaneously. searches It 2. Itisdificult
to implement. pointwhere
intersection
itcan
both meet to identifycommon deduce the
correctly
state. must berobustenoughto
a
The path frominitial ne algorithm loop.
may getstuckinan infinite
stateisconcatenated
with the inverse Otherwise,
terminate. the algorithm
pathfrom the goalstate.
Each searchisdoneonly up to
half
of the totalpath. to searchbackwards
throughall
states.
t. It
isverydifficult
152 CHAPTER3
Machine
Intelligent
Artificially
Approach?
When to UseBidirectional Search
Heuristic
H
situations:
searchcan be bestusedinthe following
B1-directional Pure
7.1
3.7 witha large
problems number problem-specfic
possiblestates, knowledgeneeds to
of
node and the goal nodeare uniqueand completely large the eficiencyof searchalgorithms.
Insucha situation, heuristicscarch algorithm
When starting
both the Tosolve
defined. to increase
When thebranching isexactlythe same inboth directions.
factor headded
well. formof heuristicsearchalgorithms
isthe sinmplest that expandsnodesbased on
pertorns search The algorithmmaintainstwo lists--OPEN
Heuristic h(n). and CLOSED. All nodes that
Example:Consider thegraphgiven theapplication
belowand demonstrate of value
fromStartforward searchfrom node2 and backwardsearchfromnode 11. bidirectional
se heuristic expanded are placedinthe CLOSED list,
cheir
while othersthat have not beenexpanded
been
Do BFS frombothdirections. already list
have
Inthe backwardsearch
Intheforwardsearchprocess,nodes 1,6 and 8 are çxplored. are intheOPEN nodes vith
iteration,
thelowest
heuristic are expanded, Then,
value the heuristic
function
each
proCes,
On nodesandthey are placed theopen list
child according heuristic
to their value.The
7 Butno intersection
isexplored. nodeisencountered. mod to che
applied are savedand the longer ones are disposed.The processcontinuesunita goal stateIs
is paths
shorter
found. we willdiscuss
twoimportantinformed
search algorithms
-bestfirstsearch
Inthissection,
search)and A* searchalgorithm.
(greedy
algorithm
SearchAlgorithm(GreedySearch)
6 3.7.2Beest-First search
combines depth-first
searchalgorithm
Greedybest-first and alwaysselects
the path Heuristic evaluation
10 search algorithms
-first
12 13 and breadth- heuristic
It usesthe function functionscalculatethe
atthat moment.
whichappears best the most promising Cost of optimal path
Nextexplorenode 3 while searchat each step to choose between twostates.
doinga forwardsearch and node 3 while and best-first isthe one that isclosest
to rhe
doinga backward searh node
Here,we find nodeas node3, so the algorithmterminates
intersecting node.The mostpromisng
and the path is-
2 ->1>} is by the
implemented
algorithm
greedybestfirst
Goal node. The
->7-> 11.
queue.
priority
3.7 Informed
SearchAlgorithms searchalgorithm
Bestfirst
steps:
Disadvantages
bestfirst
scenarios, searchcan behaveas an unguided
1. In some worst-case
can getstuckina loop. depth-first
2. Like searchalgorithm
DFS, bestfirst search
isnotan
searchalgorithm algorithm.
optimal
3. Bestfirst
3
Example:Consider it
thetree givenbelowandtraverse usinggreedy best-first
search 12
algoritm. 6
1%
10
Tableshowsthe heuristic
estimates:
Node hn) Node lh(n) Node h(n)
CLOSED list inthe
and place itssuccessors OPEN ist. Open IA B
ts
Open [A,B],Closed[S] OPEN
fronm the
B
Remove
list.
1:Sinceh(n)fornodeB islessthan that of nodeA, expandB and placeitinCLOSED
Iteration inthe OPEN C,.BI
G],Closed(S,A,
successors
and put its
NowonlynodeA isinthe OPEN list.
Open [A], Closed[S,B] Open E,D, H, placeit
as ithas minimum h(n),
inCLOSED list
Demove H from the PEN ist success.
returns
Iteration of nodeB and placethem inthe OPEN list.
2:Generatesuccessors Open (E, A],Closed of nodeH, thealgorithm
inthe OPEN list.Since Iisthe successor
secessors H
[S,B]. [S,A , C,B,
E,D, G, Closed
I, J],
Since
nodeF hasthelowestheuristic
valueamong all we will
nodesintheOPEN list, expandnode Open
Cost of A*Algorithm
FIGURE3.19Calculating
156 CHAPTER 3
Machine
Intelligent
Artificially
as the costto
as well
usessearchheuristic
TheA* searchalgorithm, reachthe
allgeneratednodesinthe memory. This makes it difficultto use
a number known as a number.
fitness node. more memory as itkeeps
the costsgives Sumf It uses
bo 3.. problems.
At each pointinthe searchspace,nodehavingthe minimum f(n)is forlarge-scale returnsthe path whichoccurred
expanded. algorithm first, s scarchingallother paths.
and ignores
found.Thesteps of this
algorithm The A*
terminateswhen the goal node is cantherefore
be algort At times,
ofA* algorithm depends on thequality
of heuristic.
4.
below.
given The efficiency
summarzed 5.
of
isemptythen returnfailure
and stop. Notethan
Step2: If
the OPEN list
Stäte h(n)
Fromthe OPEN choosethenode having minimum valueof f(n).
list, Ifthis
Step 3: node is
the
2 5
node,then return and
success stop. goa
A
the nodeselected Put the node in
inStep 3 and generateitssuccessors.
Step 4: Expand theclosed
b
4
c heck ifit
is presentinthe OPEN CLOSED list.
Ifitisnot
For eachsuccessor,
or
ineither
present 2
hen
computeitsf(n)andplaceitintoOpen list. 10
6
Step 5: Else ifthesuccessornode is alreadyin OPEN or CLOSED list,
then attachit
totheback
pointer gn')
the lowest
reflecting value.
G.
fn)of node A =
S.
A
we
of
(a) Branching the costto reachnode
G
h(n) = 0 and
G has
(b) Costat everyaction isfixed. 4.Similarly,
node
of
Treration2:
condition foronly
isconsistency A*graph-search. B is and the cost to reach node is
2 . fln)of node
(b) Consistency: Thesecondrequired ofnode
bín) 4
to reach node
C from node S Therefore.
alwaysfindthe least the cost
nodeC hash(n)=2
searchwill costpath. and
Ifthe heuristic is
function then
admissible, A* tree
Similarlv,
algorithmdependson heuristic
function,
C=2. 10)}
Thetimecomplexity
3. TimeComplexity: of A*search
7),(S-->G,
expandedis exponentialto the depth of d.
solution So, the time A->C,4),(S-->A-->B,
{(S-->
and the number of nodes
whereb isthe branching
isO(b^d),
complexity factor.
10
The space complexity isO(b^d).
of A*searchalgorithm
4.. Space Complexity:
Advantages
1. Itisbetterthanallothersearchalgorithms.
isoptimaland complete.
2. A* search algorithm
3. Thealgorithm verycomplexproblems.
can be used to solve
path efficiently.
theshortest
find
is maps
4. It used by many games and web-based to
Disadvantages
approximation.
1.Itmay pathsince
not alwaysproducetheshortest itisbased on heuristics
and
Artifhcialy
inteligent
Machine
SincenodeC
Iteration3: comparedto othernodes,we will
has lessf(n)as
fromnode S is5. expand
h(n) node is6 and the cost to reach node node
A* VsAO*
D
of D
Therefore,
nodeG node S fln) 3.7.4.1AO* algorithms informedsearchtechnsque and
nodeG hash(n)
Similarly, = 0and the costto reach from is of
6.Therefore,
nodeD
are
use heustcvaluesto
A*and olve dhe
G= 2. Both
guranteesolution,
both the algorithms
11), onlyA* guarantees
{(S-->A-->C--->G, 6),(S-->A->C--->D, (S-->A-->B, 7).(S-->G, problen. an opumal
sohunon. B
10)} Although cheshortestpath withthe lowestcOst.Thc AO algorthm dosnotahwysprode
will we mcan
4: Since G isthe goalnode,the algorithm
returnsuccessand
terminate This isbecause AO* doesnot explorealithesolution
pachsonce n fndsa oluon
Iteration opdnmal,
solution.
gving
J
withcost6. h ft
pathas,S--->A--->C--->G anoptimal thetreegivenbelowandapplytheAO* algorthmon L
Consider
che graph givenbelowand traverseitfrom node S to
Example:Consider G using A* Example:
algorithm.
Step 5
10
Shortest
path= 11 D
10
a
is6 + 4 = 10
and thecostto reachC is2 + 10= 12.Undoubtedly,
nodeA isprocessed No
further. Remember isthe heuristic or theestimatedvalueof the node and G(n)
where, H(n)
(S-->C,12)}
A, 8),(S-->B. 10),
(S--> (n) + H (n),
(F(o)= value,
G
node is foundto be reachedfrom A
Inthenextiteration, witha totalcost of3 + 10= 13.
theactual costor edge
is D or B-Ctogether.The costof both the paths
e
the S -> B pathto reachG, we get totalcost= (6 + 5).Therefore. 11 Step 1:Fron node
Now, traversing as,
calculated
{(S-->A ->G, 13), (-->B-->G,11), (S-->C,12)} 1+10 = 11and
F(A to D)=
Thefinalpath to G from S isthus,S-->B-->Gwitha costof 11. F(A to B and C)
=1+1 +6 +12 = 20 has a lovwercostthan
as it
path B-C
node to traverse
choosenodeD as the next
will
We from node D iscalculated
H-I. Now thecost of H-I
3.7.4
AO* Algorithm withonlyone
are left
choice
Step2:From D,we
inwhich problemisbroken down probleminto
AO* algorithm isbased on problem decomposition a
as
milkt The
ogether. denotesAND condition. E and E
nodes can be reached-
eat bread or havefruitsand arc
are two
Step1:From B.there
and =7+ 1=8
F(B-)
Want havebreakfast? F(B-E)=5+1 = 6 movesto node
J.
to
the algorithm
ofthepath B-E.
valuefromE s 2.
than that
ismore
costfromFB-E) value5.So. the
newheurisic
otep 2:Since heuristic
2,whichisless
than
Eat bread Eat somefruits Drinka glass
of milk = 1 +1=
F(E-])
FIGURE3.20AND-OR graph
3
160 CHAPTER
as
algorithm
bestrouteout of possible
thispath. We have just
explore shown thispathto demonstrate
the weaknessofthe available routes.
AO* the
TheAO* does notgive performanceinallthecases.
optimal algorithm and select
of HilIClimbing
3.7.4.2
Algorithm Features
3.8.1
algorithm is:a
variant of andtest
generate
TheAO* algorithm climbing
hill
maintains like
two lists theA* algorithm. che following
whichworksin
The manner: HeuristicC
searchalgorithm
The OPEN list
contains
the nodes thathavebeen traversedhave notbeen may not fndtheoptimal
markedas solvah, algorithm
unsolvable. possible solutions. solutionto the problem
all
Step1:Generating
TheCLOSE list butgivesa good solution
contains
nodesthat havealreadybeen processed. them to see ifitisthe expected
Testing
solution. ina reasonabletime.
Step2:
Stepsinthe Algorithm: isfound,the algorithmterminates
else
goes
the solution
If
Step 3:
Step 1:Put theinitial/ nodeinthe OPEN list.
starting 1.
to step
takesfeedbackfrom
algorithm the testprocedureand usesit
to generatethe
Step 2: Findthemostpromising
solution
treesay TO0. Thus,the climbing
hill
searchspace.
Step 3:Select
a node n thatisboth a next move inthe
member of TO as well inthe OPEN
as present ist. inthe statespace,the hill climbing algorithm usesthe greedyapproachto
Remow n At any point
from OPEN and placeitinCLOSE list. so that an opumal soluion
can be
t he costof function
mOVe the searchinthe direction
thatoptimizes
a heuristic
value whichincates
bow
Step 4: Ifn
isthe leafnode as well
as the goalnode,then label
n and allits
ancestors
as solved.the
obrainedat the end.To take such decisions,the algorithm uses
to the goal state.
the currentstateis
If
starting
node isnmarked as solved
thenreturnsuccessand ext. close
Elseifn isnot a solvable
node,thenmark n as unsolvable. If It
does not support backtracking inthe searchspace,as itdoenot remembercheprevious
thenreturnfailure
starting
node ismarked as unsolvable.
and exit. States.
Step5:Ifnisnot a leaf
node,thenexpandn.Enumerateall Rememberthe following:
its computetheirh(n)valus
successors,
and push them intoOPEN. + heuristics
1.Hillclimbing = generate-and-test
and a ralue.
Step 6:Returnto Step2. 2. A node of hill
climbing has two componentsstate
algorithm
good heuristicisavailable.
Step7:Exit. climbing
3. Hill ismostlyusedwhen
algorithm a
doesnotmaintain searchtree or graph. onlykeeps
and handlethe a
4. Thealgorithm
Advantages single currentstate.
thsalgorithm
of a geneic algorithm.Although
1.Itgivesoptimalsoluion. 3. cimbing
Hill isthe simplestimplementation
ones, it
executesf sterwhen comparedwithothergenetic
2. Itcan be used forbothOR thoroughthan the traditional
1s less
and AND graph when nodesare traversed
ina particular
order. algorithms.
16 CHAPTER3
Artificially
intelligent
Machine
Types
3.8.2 Climbing
of Hill isnothetterthan the beststate,thenmake beststateas the
Ifthe new state currentEate
we will of hill
variants
different
discuss algorithm
climbing (c) a solution
in theloop until isfound.
Inthissection, Continue
Hill
Climbing Hill
Climbing
Simple
3.8.2.1 Stochastic
thefirst 3.8.2.3 two variants, hill
the scholastic climbing
algorithm does not examineall
nodes and selects the
The algorithm examines theneighbouring previous
the
neighbouring
inthis beforedeciding which node to selectnext. Rather,itrandomly selects
The stepsperformed Unlike
the currentcost as the next node.
optimizes
node
algorithm wh can
nodes
whetherto move to that neighbour
and determines or to examne
neighbouringnode another
follows. in
ofimprovemnent that neighbour, Stepsto be performedin hill
scholastic
the
aneighbouring amount
on
the
Step 1: Evaluate initial Ifit
state. thenreturnsuccessand
isthe goalstate, depending below
terminate arelisted
stateas the current
initial state. the
climbing Ifit:
state. isthe oal state,
thenreturnsuccessand terminateche process.
Else,
make proce
the initial
stateisfound
thesolution or no newoperatorsare Step
1:
Evaluate
state the
initial
as currentstate.
Step 2: RepeatStep 2 until presentwhich make
state. canb Else, 2 until eitherthe solution stateisfoundor the currentstate
does not change.
appliedto the current Step
Repeat
this Step 2: beensetas the currentstate.
(a) Select statethat has not been set as the currentstate. Use to produce:
state
new state. a statethathas not
Selecta the neighbour
sates.
a
fnction tothe currentstateand generateall
(b) Evaluatethe new state. (a) successor function)a state the neighbouringstatesgenerated
from all
Apply probabilistic
If
(i) the current stateisthe goalstate,then returnsuccessand stop (b) select (or use a
Randomly thanthe currentstate.
t henset itas theCurrent better
(ii) tIf
he new stateis than
better the current state,
state
and in 2,b) and are
in
2 (c)is thenreturn
the goal state, success,elsemake it
the Currentstate and
selected
further.
processed
(c)
If
the state
the loop.
thenew stateisnot betterthan the currentstate,then continueinthe loas
If
(iii) continuewith
isfound.
a solution
for HilClimbina
StateSpaceDiagram
3.8.3 chatcan be attained
of the setof states
representation
Advantage 3.21)
(Fig. is graphical
a
(thef unctionthathas to
diagram function
of theobjective
íttakeslesstime.
The state-space
search algorithm withrespecttothevalue the values of obiectivefunction
on theX-axis,
the space isrepresented
state
La mavimized).
While the Y-axis.
stateare marked on (gobal
Disadvantages to a particular function has a maximum value
corresponding the objective
The bestsolution isthe statespace where global
the
find maximum and Jocalmaximum.
1. Solution
islessoptimal. is
to
algorithm
climbing
the hill
maNimum).Thegoal
of
2. It
doesnotguarantee
any solution
function Globalmaximum
Objective
3.8.2.2 Hill
Steepest-AscentClimbing
the node closest
nodes.Itthenselects to the solucon
The algorithm examinesallthe neighbouring
hill
steepest-ascent climbing
can be givenas follows: Localmaximum
stateas thenext node.Stepsto perform Shoulder local
"Flat" maximum
and terminatethe proces.
Step 1: the initial
Evaluate If
state. itisthegoalstate,
thenreturnsuccess
make initial
Else, stateas thecurrentstate.
statedoes notchange
stateisfoundor thecurrent
eitherthe solution
Step 2:Repeat Step2 until
maxmum) ifit entersany of the following goh while doing random walk Simulated annealing
s an algornthmwhch s both
We havt
a
scenarnoswhuchae dscuedbeiou.
Disadvantages duferent rypesot garme
a
agorthm s hatitmay terminate a Loal There
are
of chis Information
Howevehe sadancage
with Perfect
Panez
Games
a
open and transparent
re the
5 everyplayerhscompletenformonTheplavers
game and the move of the opponerEmes
ew
Search S.h of
the status suchamandde of
Adveraral
ina Imperfect Information
goas
conthcong nd objectvesThese enites partcipate
with
gme approach of eachplayer Games do nothaveanyinformation on the sKztusof theame Theyakeblind
game-hkesutuanonThesrategy
or Whdenormal msves
players
move Foreample,thegame situation search gams, and the outcomes. Eamplesof thegmes
depends on theopponents
a
single
entity, Ir
chese predicting
assumpaons
certain
incude.ic-tac-
whethera playerwould searchon the adversna
nd ntentof the opponent determnes otherhasa by mmaking and bridge.
blind.
or a mnmize ole While Maximizer. hasmore
thanone eitit battleship,
ake 2 mAzet role toe,
gtn,Mnimizer, on the other hand,makes best Games
maumizesthe
to imutche damage and minmizethe loss. Deterministic
efforrs in
are played ransparent manner. Al playerscan seethe moves
a the opponents nd
of
Zero-SumGames
Theseare purely competitivegames inwhich one player's gainiscompensatedbyanotherphyer'sloss.
M
w Thenet value of gainand lossi s
zero,thus,the name.
rhe gainor minimize the los, depending on the gamne situation, likely
strategy to be adoptedby the
We areopponents-Iwin,
you loose. oDponent and the players game plan. Thisscenarioispopularly known as embeddedthinking in
Heuristic
evaluation
function TABLE3.2
approximates
the cost at eachlevel
of the search tree,
reachingthe goalnode. before
Deterministic ChanceMoves
3.9.1
Game Scenarios Perfectinformation Chess,Checkers,
go,Othello Backgammon,
monopoly
Adversarialsearchexamines information
Imperfect war
the problemwhicharises
when an agentplansaheadof Battleships, tic-tac-toe. Bridge,
blind, poker, nuçlear
scrabble,
agentsthatare planning other
against
it.Itisapplied ina multi-agent
thataremodelled environment,
as a search
problemand use theheuristic like
ingames
evaluation
function.