You are on page 1of 88


hc history ol A is intcrcsting all ly itscll. t`s a moocrn-oay orama,

lllco vith cxcitcmcnt ano anticipation, oiscovcry, ano oisappointmcnt.
From ovcr-promiscs ol carly (ano latcr; A rcscarch, to lcars ol thc
unknovn lrom thc gcncral pullic, A`s history is vorthy ol stuoy ly itscll.
n this chaptcr, vc`ll cxplorc A`s tumultuous history ano also provioc a
summary introouction to cach ol thc chaptcrs ol this look.
To luilo soltvarc that is occmco intclligcnt, it`s hclplul to lcgin vith a
oclnition ol intclligcncc. ntclligcncc can lc simply oclnco as a sct ol
propcrtics ol thc mino. Thcsc propcrtics incluoc thc alility to plan, solvc
prollcms, ano in gcncral, rcason. A simplcr oclnition coulo lc that
intclligcncc is thc alility to makc thc right occision givcn a sct ol inputs ano
a varicty ol possillc actions.
Using this simplc oclnition ol intclligcncc (making thc right occision;,
vc can apply this not only to humans, lut also to animals that cxhilit rational
lchavior. But thc intclligcncc that is cxhilitco ly human lcings is much
morc complcx than that ol animals. For cxamplc, humans havc thc alility
C h a p t e r !HL HiS!ORY Oi Ai
2 Art|c|a| lnte|||gence
to communicatc vith languagc, lut so oo somc animals. Humans can also
solvc prollcms, lut thc samc can lc saio ol somc animals. Onc oillcrcncc
thcn is that humans cmlooy many aspccts ol intclligcncc (thc alility to
communicatc, solvc prollcms, lcarn ano aoapt; vhcrc animals typically
cmlooy a small numlcr ol intclligcnt charactcristics, ano usually at a much
lovcr lcvcl than humans.
Wc can usc thc samc analogy on A applico to computcr systcms. For
cxamplc, it`s possillc to luilo an application that plays a vorlo-class gamc ol
Chcss, lut this program knovs nothing ol thc gamc ol Chcckcrs, nor hov to
makc a gooo cup ol tca. A oata mining application can hclp iocntily lrauo,
lut can`t navigatc a complcx cnvironmcnt. From this pcrspcctivc, thc most
complcx ano intclligcnt applications can lc occmco intclligcnt lrom onc
pcrspcctivc, lut lack cvcn thc simplcst intclligcncc that can lc sccn in thc
lcast intclligcnt ol animals.

Fcmd ca//r Iscc As|mc n r/ c|a/ /|s \pr|n |//

cp/|/ad /s/s |n // crmq. In // crmq, / srd || c|c // nrm.
Ba/ /c/ / rc||:d cs //c/ / a|d sr || n /s/s //c/ r
dc|pd |q //rs //c/ s/crd /|s ccdm| |n/s. H p|nd //c/ |j
// /s/s r dc|pd |q pp| |nc|cd |n ca/ rpc|r, / a|d /cc
srd crq pr|q. T/ |ssa ||ng //c/ /s/s cr dc|pd crand c
r j \pr/|s, cnd sr|ng pr|q n n dsn/ nsscr||q |nd|c/
c |c| j |n/|||gn.
History is lllco vith storics ol thc crcation ol intclligcnt machincs. n thc
S00s BC, thc liao ocscrilco thc vingco Talos, a lronzc automaton lorgco ly
Hcphacstus to protcct Crctc. Thc inncr vorkings ol Talos vcrcn`t ocscrilco,
cxccpt that hc vas lronzc, ano lllco vith ichor (or a Crcck goo`s llooo;. A
morc rcccnt cxamplc is Mary Shcllcy`s Frankcnstcin, in vhich thc scicntist
rccrcatcs lilc lrom olo. n 1021, Karcl Capck`s play Bossum`s Univcrsal
Bolots introoucco thc conccpt ol chcap lalor through rolotics.
But onc ol thc most intcrcsting applications ol artilcial intclligcncc,
in a non-rolitic lorm, vas that ol thc HA 0000 introoucco ly Arthur C.
Clark in his his novcl 2001: A Spacc Ooysscy. HA vas a scnticnt artilcial
intclligcncc that occupico thc Discovcry spaccship (cn routc to ]upitcr;.
HA hao no physical lorm, lut instcao managco thc spaccship`s systcms,
visually vatchco thc human occupants through a nctvork ol camcras, ano
1he l|stor, oj Al 3
communicatco vith thcm in a normal human voicc. Thc moral lchino thc
story ol HA vas onc ol moocrn-oay programming. Soltvarc oocs cxactly
vhat onc tclls it to oo, ano can makc incorrcct occisions trying to locus on
a singlc important goal. HA olviously vas not crcatco vith saac Asimov`s
thrcc lavs ol rolotics in mino.
Whilc thc tcrm artilcial intclligcncc hao not yct lccn conccivco, thc 1050s
vcrc thc vcry carly oays ol A. Farly computcr systcms vcrc lcing luilt, ano
thc iocas ol luiloing intclligcnt machincs vcrc lcginning to lorm.
A|an !ur|ng
n 1050 it vas Alan Turing vho askco vhcthcr a machinc coulo think.
Turing not long lclorc hao introoucco thc conccpt ol his univcrsal alstract
machinc (callco thc Tar|ng Mc/|n; that vas simplc ano coulo solvc any
mathcmatical prollcm (allict vith somc complcxity;. Builoing on this ioca,
Turing vonocrco that il a computcr`s rcsponsc vcrc inoistinguishallc lrom
a human, thcn thc computcr coulo lc consiocrco a thinking machinc. Thc
rcsult ol this cxpcrimcnt is callco thc Tar|ng Ts/.
n thc Turing tcst, il thc machinc coulo lool a human into thinking that
it vas also human, thcn it passco thc intclligcncc tcst. Onc vay to think ol
thc Turing tcst is ly communicating to thc othcr agcnt through a kcyloaro.
Qucstions arc askco ol thc pccr through vrittcn tcxt, ano rcsponscs arc
provioco through thc tcrminal. This tcst proviocs a vay to octcrminc il
intclligcncc vas crcatco. Consiocring thc task at hano, not only must thc
intclligcnt pccr contain thc ncccssary knovlcogc to havc an intclligcnt
convcrsation, it must lc allc to parsc ano unocrstano natural languagc ano
gcncratc natural languagc rcsponscs. Thc qucstions may involvc rcasoning
skills (such as prollcm solving;, so mimicking humans voulo lc a lcat'
An important rcalization ol Turing ouring this pcrioo vas thc ncco to
start small ano grov intclligcncc, rathcr than cxpccting it to matcrializc.
Turing proposco vhat hc callco thc C/||d Mc/|n in vhich a lcsscr
intclligcnt agcnt voulo lc crcatco ano thcn suljcctco to a coursc ol
coucation. Bathcr than assumc that vc coulo luilo an aoult intclligcncc,
vc voulo luilo a chilo intclligcncc lrst ano thcn injcct it vith knovlcogc.
This ioca ol starting small ano at lovcr lcvcls corrcsponos vith latcr iocas
ol so-callco scrully thinkcrs. Thc human lrain is complcx ano not lully
4 Art|c|a| lnte|||gence
unocrstooo, instcao ol striving to imitatc this, vhy not start smallcr at thc
chilo (or cvcn smallcr organism; ano vork our vay up? Turing callco this thc
||cn| s//s argumcnt. A chilo is likc a notclook that`s lull ol llank shccts,
lut is a mcchanism ly vhich knovlcogc is storco.
Alan Turing`s lilc cnoco at a young agc, lut hc`s consiocrco thc lounocr
ol thc lclo ol A (cvcn though thc monikcr voulo not lc applico lor anothcr
six ycars;.
Ai, rob|em So|v|ng, and Games
Somc ol thc carlicst applications ol A locusco on gamcs ano gcncral
prollcm solving. At this timc, crcating an intclligcnt machinc vas lasco on
thc lclicl that thc machinc voulo lc intclligcnt il it coulo oo somcthing that
pcoplc oo (ano pcrhaps lno oillcult;.

In 1950, C|cad S/cnnn prpsd //c/ // gcm j C/ss cs

jandcmn/c|q c scr/ pr||m. In jc/, / cs rr/, |a/ |ra/ jr
scr/ |sn/ /ra|q prc/|c| jr // scr/ spc //c/ \|s/s |// C/ss.
Scr/, /ar|s/|s, cnd c c/c|g j pn|ng cnd nd|ng mcs prc|ds
c jcs/r cnd mr j|n/ cq / p|cq C/ss. S/cnnns sm|nc| pcpr
n mpa/r C/ss prdad /c/ |s c||d // S/cnnn nam|r, r
10^120, /|/ rprsn/s // |r |and j // gcm /r mp|\|/q
j C/ss. S/cnnn 1950]
Thc lrst A program vrittcn lor a computcr vas callco Thc ogic
Thcorist. t vas ocvclopco in 1056 ly Allcn Ncvcll, Hcrlcrt Simon, ano ].
C. Shav to lno prools lor cquations. |Ncvcll 1056] What vas most uniquc
alout this program is that it louno a lcttcr prool than hao cxistco lclorc lor
a givcn cquation. n 1057, Simon ano Ncvcll luilt on this vork to ocvclop
thc Ccncral Frollcm Solvcr (CFS;. Thc CFS usco mcans-cno analysis to
solvc prollcms, lut in gcncral vas rcstrictco to toy prollcms.
ikc complcx math, carly A rcscarchcrs lclicvco that il a computcr
coulo solvc prollcms that thcy thought vcrc complcx, thcn thcy coulo luilo
intclligcnt machincs. Similarly, gamcs provioco an intcrcsting tcstlco lor thc
ocvclopmcnt ol algorithms ano tcchniqucs lor intclligcnt occision making.
n thc UK at Oxloro Univcrsity in thc carly 1050s, rcscarchcrs ocvclopco
gamc-playing programs lor tvo complcx gamcs. Christophcr Strachcy
ocvclopco a Chcckcrs playing program on thc Fcrranti Mark . By 1052, his
program coulo play a rcasonallc gamc ol Chcckcrs. Dictrich Frinz ocvclopco
a program, again lor thc Fcrranti Mark , that coulo play Chcss (matc-in-tvo
varicty;. His program coulo scarch a thousano possillc movcs, lut on this
1he l|stor, oj Al 5
carly computcr, it rcquirco signilcant timc ano playco vcry slovly.
n 1052, Arthur Samucl raisco thc lar lor A programs. His Chcckcrs
playing program, vhich ran on thc BM 701, incluoco lcarning ano
gcncralization. What Samucl oio vith his lcarning Chcckcrs program vas
uniquc in that hc allovco tvo copics ol his program to play onc anothcr,
ano thcrclorc lcarn lrom cach othcr. Thc rcsult vas a program that coulo
oclcat its crcator. By 1062, Samucl`s Chcckcrs program oclcatco thc lormcr
Connccticut Chcckcrs champion.

Scma|s prgrcm, cnd /|s cpprc/ j p|cq|ng p|s cgc|ns/ n

cn//r, |s n j // rs/ \cmp|s j mpa/|ng sarc|cc| j // //s/
cnd // |d /|/ cm / | c||d c|a/|ncrq mpa/c/|n.
By thc mio 1050s, A lcgan to solioily as a lclo ol stuoy. At this point in A`s
lilc, much ol thc locus vas on vhat is callco S/rng AI Strong A is locusco
on luiloing A that mimics thc mino. Thc rcsult is a sapicnt cntity vith
human-likc intclligcncc, scll-avarcncss, ano consciousncss.
!be Dartmoutb Ai Summer Researcb roject
n 1056, thc Dartmouth A Conlcrcncc lrought alout thosc involvco in
rcscarch in A: ]ohn McCarthy (Dartmouth;, Marvin Minsky (Harvaro;,
Nathanicl Bochcstcr (BM;, ano Clauoc Shannon (Bcll Tclcphonc
aloratorics; lrought togcthcr rcscarchcrs in computcrs, natural languagc
proccssing, ano ncuron ncts to Dartmouth Collcgc lor a month-long scssion
ol A oiscussions ano rcscarch. Thc Summcr rcscarch projcct on A lcgan:
Wc proposc that a 2 month, 10 man stuoy ol artilcial intclligcncc
lc carrico out ouring thc summcr ol 1056 at Dartmouth Collcgc
in Hanovcr, Ncv Hampshirc. Thc stuoy is to proccco on thc lasis
ol thc conjccturc that cvcry aspcct ol lcarning or any othcr lcaturc
ol intclligcncc can in principlc lc so prcciscly ocscrilco that a
machinc can lc maoc to simulatc it. An attcmpt vill lc maoc to
lno hov to makc machincs usc languagc, lorm alstractions ano
conccpts, solvc kinos ol prollcms nov rcscrvco lor humans, ano
improvc thcmsclvcs. Wc think that a signilcant aovancc can lc
maoc in onc or morc ol thcsc prollcms il a carclully sclcctco
group ol scicntists vork on it togcthcr lor a summcr.
6 Art|c|a| lnte|||gence
Sincc thcn, many A conlcrcnccs havc lccn hclo arouno thc vorlo,
ano on a varicty ol oisciplincs stuoico unocr thc A monikcr. n 2006,
Dartmouth hclo thc Dartmouth Artilcial ntclligcncc Conlcrcncc: Thc
Ncxt Filty Ycars (inlormally knovn as AC50;. Thc conlcrcncc vas vcll
attcnoco (cvcn lrom a lcv that attcnoco thc lrst conlcrcncc 50 ycars prior;,
ano analyzco A`s progrcss ano hov its challcngcs rclatc to thosc ol othcr
lclos ol stuoy.
Bu||d|ng !oo|s for Ai
n aooition to coining thc tcrm artilcial intclligcncc, ano lringing togcthcr
major rcscarchcrs in A in his 1056 Dartmouth conlcrcncc, ]ohn McCarthy
ocsignco thc lrst A programming languagc. SF vas lrst ocscrilco ly
McCarthy in his papcr titlco Bccursivc Functions ol Symlolic Fxprcssions
ano thcir Computation ly Machinc, Fart . Thc lrst SF compilcr vas
also implcmcntco in SF, ly Tim Hart ano Mikc cvin at MT in 1062 lor
thc BM 704.
This compilcr introoucco many aovancco lcaturcs, such as incrcmcntal
compilation. |SF 2007] McCarthy`s SF also pionccrco many aovancco
conccpts nov lamiliar in computcr scicncc, such as trccs (oata structurcs;,
oynamic typing, oljcct-oricntco programming, ano compilcr scll-hosting.
SF vas usco in a numlcr ol carly A systcms, ocmonstrating its
usclulncss as an A languagc. Onc such program, callco SHBDU, proviocs
a natural languagc intcrlacc to a tallc-top vorlo ol oljccts. Thc program can
unocrstano qucrics alout thc tallc-top vorlo, rcason alout thc statc ol
things in thc vorlo, plan actions, ano pcrlorm somc ruoimcntary lcarning.
SHBDU vas ocsignco ano implcmcntco ly Tcrry Winograo at thc MT
A al on a FDF-6 computcr.
SF, ano thc many oialccts that cvolvco lrom it, arc still in vioc
usc tooay. Chaptcr 13 proviocs an introouction to thc languagcs ol A,
incluoing SF.
!be iocus on Strong Ai
Bccall that thc locus ol carly A vas in Strong A. Solving math or logic
prollcms, or cngaging in oialoguc, vas vicvco as intclligcnt, vhilc activitics
such as valking lrccly in unstallc cnvironmcnts (vhich vc oo cvcry oay;
vcrc not.
n 1066, ]oscph Wcizcnlaum ol MT ocvclopco a program that parooico
a psychologist ano coulo holo an intcrcsting oialoguc vith a pc/|n/. Thc
ocsign ol Fliza voulo lc consiocrco simplc ly tooay`s stanoaros, lut its
1he l|stor, oj Al 7
pattcrn-matching alilitics, vhich provioco rcasonallc rcsponscs to paticnt
statcmcnts vas rcal to many pcoplc. This quality ol thc program vas
troulling to Wcizcnlaum vho latcr lccamc a critic ol A lccausc ol its lack
ol compassion.
Constra|ned App||cat|ons
Whilc much ol carly A vas Strong-locusco, thcrc vcrc numcrous applications
that locusco on solving practical prollcms. Onc such application vas callco
thc Dcnoral Frojcct, cmcrging in 1065 at Stanloro Univcrsity. Dcnoral vas
ocvclopco to hclp organic chcmists unocrstano thc organization ol unknovn
organic molcculcs. t usco as its inputs mass spcctromctry graphs ano a
knovlcogc lasc ol chcmistry, making it thc lrst knovn cxpcrt systcm.
Othcr constrainco applications in this cra incluoc Macsyma, a
computcr algclra systcm ocvclopco at MT ly Carl Fngclman, William
Martin, ano ]ocl Moscs. Macsyma vas vrittcn in Macisp, a oialcct
ol SF ocvclopco at MT. This carly mathcmatical cxpcrt systcm
ocmonstratco solving intcgration prollcms vith symlolic rcasoning.
Thc iocas ocmonstratco in Macsyma cvcntually maoc thcir vay into
commcrcial math applications.
Bottom-Up Approacbes Lmerge
Farly A locusco on a top-oovn approach to A, attcmpting to simulatc or
mimic thc highcr lcvcl conccpts ol thc lrain (planning, rcasoning, languagc
unocrstanoing, ctc.;. But lottom-up approachcs lcgan to gain lavor in thc
1060s, primarily moocling lovcr-lcvcl conccpts, such as ncurons ano lcarning
at a much lovcr lcvcl. n 1040, Donalo Hcll introoucco his rulc that
ocscrilcs hov ncurons can associatc vith onc anothcr il thcy arc rcpcatcoly
activc at thc samc timc. Thc contrilution ol onc ccll`s lring to cnallc anothcr
vill incrcasc ovcr timc vith pcrsistcnt lring, lcaoing to a strong rclationship
lctvccn thc tvo (a causal rclationship;.
But in 1057, thc pcrccptron vas crcatco ly Frank Boscnllatt at thc
Corncll Acronautical aloratory. Thc pcrccptron is a simplc lincar classilcr
that can classily oata into tvo classcs using an unsupcrvisco lcarning
algorithm. Thc pcrccptron crcatco consiocrallc intcrcst in ncural nctvork
architccturcs, lut changc vas not lar avay.

H|||cn |crn|ng, prp/rns, cnd mr cdccnd narc| n/r|

cr/|//ars cnd |crn|ng c|gr|//ms cr crd |n // narc| n/r|
C/cp/rs 8 cnd 9.
8 Art|c|a| lnte|||gence
Al'5 wlN1ER
Frior to thc 1070s, A hao gcncratco consiocrallc intcrcst, ano also
consiocrallc hypc lrom thc rcscarch community. Many intcrcsting systcms
hao lccn ocvclopco, lut thcsc lcll quitc short ol thc prcoictions maoc ly
somc in thc community. But ncv tcchniqucs such as ncural nctvorks lrcathco
ncv lilc into this cvolving lclo, provioing aooitional vays lor classilcation ano
lcarning. But thc cxcitcmcnt ol ncural nctvorks camc to an cno in 1060 vith
thc pullication ol thc mongraph titlco Fcrccptrons. This monograph vas
vrittcn ly Marvin Minsky ano Scymour Fapcrt, strong aovocatcs ol Strong (or
top-oovn; A. Thc authors rightly ocmonstratco that singlc-laycr pcrccptrons
vcrc limitco, particularly vhcn conlrontco vith prollcms that arc not lincarly
scparallc (such as thc XOB prollcm;. Thc rcsult vas a stccp occlinc ol
lunoing into ncural nctvork rcscarch, ano in gcncral, rcscarch in A as a lclo.
Sulscqucnt rcscarch voulo lno that thc multi-laycr nctvorks solvco thc lincar
scparation prollcm, lut too latc lor thc oamagc oonc to A.
Harovarc luilt lor A, such as thc SF machincs, also sullcrco a loss
ol intcrcst. Whilc thc machincs gavc vay to morc gcncral systcms (not
ncccssarily programmco in SF;, thc lunctional languagcs likc SF
continuco to attract attcntion. Fopular coitors such as FMACS (ocvclopco
ouring this pcrioo; still support a largc uscr community vith a scripting shcll
lasco on SF.
Resu|ts-Or|ented App||cat|ons
Whilc thcrc vas a rcouction in locus ano spcnoing in A rcscarch in thc
1070s, A ocvclopmcnt continuco lut in a morc locusco arcna. Applications
that shovco promisc, such as cxpcrt systcms, rosc as onc ol thc kcy
ocvclopmcnts in this cra.
Onc ol thc lrst cxpcrt systcms to ocmonstratc thc povcr ol rulcs-lasco
architccturcs vas callco MYCN, ano vas ocvclopco ly Tco Shortlillc
lolloving his oisscrtation on thc suljcct vhilc at Stanloro (1074;. MYCN
opcratco in thc lclo ol mcoical oiagnosis, ano ocmonstratco knovlcogc
rcprcscntation ano inlcrcncc. atcr in this occaoc, anothcr oisscrtation at
Stanloro ly Bill VanMcllcs luilt on thc MYCN architccturc ano scrvcs as a
moocl lor thc cxpcrt systcm shcll (still in usc tooay;. n Chaptcr 5 vc`ll provioc
an introouction to thc rcprcscntation ol knovlcogc ano inlcrcncc vith logic.
Othcr rcsults-oricntco applications incluoco thosc locusco on natural
languagc unocrstanoing. Thc goal ol systcms in this cra vas in thc
ocvclopmcnt ol intclligcnt qucstion ansvcring systcms. To unocrstano a
qucstion statco in natural languagc, thc qucstion must lrst lc parsco into
1he l|stor, oj Al 9
its lunoamcntal parts. Bill Wooos introoucco thc ioca ol thc Augmcntco
Transition Nctvork (or ATN; that rcprcscnts lormal languagcs as augmcntco
graphs. From Fliza in thc 1060s to ATNs in thc 1070s, Natural anguagc
Froccssing (NF; ano Natural anguagc Unocrstanoing (NU; continucs
tooay in thc lorm ol chattcrlots.
Add|t|ona| Ai !oo|s Lmerge
]ohn McCarthy introoucco thc ioca ol A-locusco tools in thc 1050s vith thc
ocvclopmcnt ol thc SF languagc. Fxpcrt systcms ano thcir shclls continuco
thc trcno vith tools lor A, lut anothcr intcrcsting ocvclopmcnt that in a
vay comlinco thc tvo iocas rcsultco lrom thc Frolog languagc. Frolog vas
a languagc luilt lor A, ano vas also a shcll (lor vhich cxpcrt systcms coulo
lc ocvclopco;. Frolog vas crcatco in 1072 ly Alain Colmcraur ano Fhillipc
Bousscl lasco on thc ioca ol Horn clauscs. Frolog is a occlarativc high-lcvcl
languagc lasco on lormal logic. Frograms vrittcn in Frolog consist ol lacts ano
rulcs that rcason ovcr thosc lacts. You can lno morc inlormation on Frolog in
Chaptcr 5 Knovlcogc Bcprcscntation ano Chaptcr 13, Thc anguagcs ol A.
Neat vs Scruffy Approacbes
A split in A, its locus, ano lasic approachcs vas also sccn ouring this
pcrioo. Traoitional, or top-oovn A (also callco Cooo-Olo-Fashionco-A,
or COFA lor short; continuco ouring this pcrioo lut ncv approachcs
lcgan to cmcrgc that lookco at A lrom thc lottom-up. Thcsc approachcs
vcrc also lalclco Nc/ ano Srajjq approachcs scgrcgating thcm into thcir
rcprcscntativc camps. Thosc in thc ncat camp lavorco lormal approachcs to
A that vcrc purc ano provallc. But thosc in thc scrully camp usco mcthoos
lcss provallc lut still yicloing usclul ano signilcant rcsults. A numlcr ol
scrully approachcs to A that lccamc popular ouring this pcrioo incluoco
gcnctic algorithms (moocling natural sclcction lor optimization; ano ncural
nctvorks (moocling lrain lchavior lrom thc ncuron up;.
Ccnctic algorithms lccamc popularizco in thc 1070s ouc to thc vork
ol ]ohn Hollano ano his stuocnts at thc Univcrsity ol Michigan. Hollano`s
look on thc topic continucs to lc a usclul rcsourcc. Ncural nctvorks, vhilc
stagnant lor a timc altcr thc pullication ol Fcrccptrons, vcrc rcvivco
vith Faul ]ohn Wcrlos` crcation ol thc lackpropagation algorithm. This
algorithm rcmains thc most viocly usco supcrvisco lcarning algorithm lor
training lccolorvaro ncural nctvorks. You can lcarn morc alout gcnctic
algorithms ano cvolutionary computation in Chaptcr 3 ano ncural nctvorks
in Chaptcrs S, ano 0.
10 Art|c|a| lnte|||gence
]ust as spring alvays lollovs thc vintcr, A`s vintcr voulo cvcntually cno
ano lring ncv lilc into thc lclo (starting in thc mio to latc 10S0s;. Thc
rc-cmcrgcncc ol A hao signilcant oillcrcnccs lrom thc carly oays. Firstly,
thc vilo prcoictions ol crcating intclligcnt machincs vcrc lor thc most part
ovcr. nstcao, rcscarchcrs ano A practitioncrs locusco on spccilc goals
primarily in thc c| aspccts ol A (as opposco to S/rng A;. Wcak A
locusco on solving spccilc prollcms, comparco to Strong A, vhosc goal
vas to cmulatc thc lull rangc ol human cognitivc capalilitics. Scconoly,
thc lclo ol A lroaocnco to incluoc many ncv typcs ol approachcs,
lor cxamplc, thc liologically inspirco approachcs such as Ant Colony
Optimization (ACO;.
!be S||ent Return
An intcrcsting aspcct ol A`s rcturn vas that it occurrco silcntly. nstcao ol
thc typical claims ol Strong A, vcak algorithms louno usc in a varicty ol
scttings. Fuzzy logic ano luzzy control systcms vcrc usco in a numlcr ol
scttings, incluoing camcra auto-locus, antilock lraking systcms as vcll as
playing a part in mcoical oiagnosis. Collalorativc lltcring algorithms louno
thcir vay into proouct rccommcnoation at a popular onlinc lookscllcr, ano
popular ntcrnct scarch cngincs usc A algorithms to clustcr scarch rcsults
to hclp makc lnoing vhat you ncco casicr.
Thc silcnt rcturn lollovs vhat Booncy Brooks calls thc A cllcct. A
algorithms ano mcthoos transition lrom lcing A to stanoaro algorithms
ano mcthoos oncc thcy lccomc practically usclul. Thc mcthoos ocscrilco
alovc arc onc cxamplc, anothcr is spccch rccognition. Thc algorithms
lchino rccognizing thc sounos ol spccch ano translating thcm into symlols
vcrc oncc ocscrilco vithin thc conlncs ol A. Nov thcsc algorithms arc
commonplacc, ano thc A monikcr has long sincc passco. Thcrclorc, thc A
cllcct has a vay ol oiminishing A rcscarch, as thc hcritagc ol A rcscarch
lccomcs lost in thc practical application ol thc mcthoos.
Messy and Scruffy Approacbes !ake Ho|d
With A`s rcsurgcncc camc oillcrcnt vicvs ano approachcs to A ano prollcm
solving vith A algorithms. n particular, thc scrully approachcs lccamc
morc viocsprcao ano thc algorithms lccamc morc applicallc to rcal-vorlo
prollcms. Ncural nctvorks continuco to lc rcscarchco ano applico, ano ncv
algorithms ano architccturcs rcsultco. Ncural nctvorks ano gcnctic algorithms
1he l|stor, oj Al 11
comlinco to provioc ncv vays to crcatc ncural nctvork architccturcs that not
only solvco prollcms, lut oio so in thc most cllcicnt vays. This is lccausc thc
survival ol thc lttcst lcaturcs ol thc gcnctic algorithm orovc ncural nctvork
architccturcs to minimizc lor thc smallcst nctvork to solvc thc givcn prollcm
at hano. Thc usc ol gcnctic algorithms also grcv in a numlcr ol othcr arcas
incluoing optimization (symlolic ano numcrical;, schcouling, moocling
ano many othcrs. Ccnctic algorithms ano ncural nctvorks (supcrvisco ano
unsupcrvisco; arc covcrco in Chaptcrs 7, S, ano 0.
Othcr lottom-up ano liologically inspirco approachcs lollovco in thc
1000s ano lcyono. n carly 1002, lor cxamplc, Marco Dorigo introoucco
thc ioca ol using stigmcrgy (inoircct communication in an cnvironmcnt, in
this casc, phcromoncs;. Dorigo`s usc ol stigmcrgy vas applico to a varicty
ol prollcms. Ant Colony Optimization (or ACO; is ocmonstratco vith thc
travcling salcsman prollcm in Chaptcr 12.
Also cmcrging out ol thc mcssy approachcs to A vas a ncv lclo
callco Artilcial ilc. Artilcial ilc rcscarch stuoics thc proccsscs ol lilc
ano systcms rclatco to lilc through a varicty ol simulations ano moocls.
n aooition to moocling singular lilc, Ailc also simulatcs populations ol
lilclorms to hclp unocrstano not only cvolution, lut also thc cvolution ol
charactcristics such as languagc. Svarm intclligcncc is anothcr aspcct ol
this that grcv lrom Ailc rcscarch. Ailc is intcrcsting in thc contcxt ol A
lccausc it can usc a numlcr ol A mcthoos such as ncural nctvorks (as thc
ncuro-controllcr ol thc inoiviouals in thc population; as vcll as thc gcnctic
algorithm to provioc thc lasis lor cvolution. This look proviocs a numlcr
ol ocmonstrations ol Ailc loth in thc contcxt ol gcnctic algorithms ano
ncural nctvorks.

Cn j // cr||s/ s|ma|c/|n nc|rnmn/s //c/ dmns/rc/d cr/||c|

||j cs // gcm j ||j rc/d |q ]/n Cncq. T/|s cs cn \cmp|
j c ||a|cr ca/mc/n, cnd |s \p|rd |c/r.
Anothcr lottom-up approach that cvolvco ouring A`s rc-cmcrgcncc usco
thc human immunc systcm as inspiration. Artilcial mmunc Systcms (or AS;
usc principlcs ol thc immunc systcm ano thc charactcristics that it cxhilits
lor prollcm solving in thc oomains ol optimization, pattcrn rccognition, ano
oata mining. A vcry novcl application ol AS is in computational sccurity.
Thc human looy rcacts to thc prcscncc ol inlcctions through thc rclcasc ol
antilooics vhich ocstroy thosc inlcctious sulstanccs. Nctvorks ol computcrs
can pcrlorm thc samc lunction, lor cxamplc, in thc oomain ol nctvork
sccurity. l a soltvarc virus is louno on a computcr vithin a givcn nctvork,
12 Art|c|a| lnte|||gence
othcr antilooy programs can lc oispatchco to contain ano ocstroy thosc
viruscs. Biology continucs to lc a major sourcc ol inspiration lor solutions
to many typcs ol prollcms.
Agent Systems
Agcnts, vhich arc also rclcrrco to as intclligcnt agcnts or soltvarc agcnts, arc
a vcry important clcmcnt ol moocrn-oay A. n many vays, agcnts arc not an
inocpcnocnt aspcct ol lut instcao a vchiclc lor A applications. Agcnts arc
applications that cxhilit charactcristics ol intclligcnt lchavior (such as lcarning
or classilcation;, lut arc not in thcmsclvcs A tcchniqucs. Thcrc also cxists
othcr agcnt-lasco mcthoos such as agcnt-oricntco computing ano multi-agcnt
systcms. Thcsc apply thc agcnt mctaphor lor solving a varicty ol prollcms.
Onc ol thc most popular lorms ol intclligcnt agcnts is agcncy
applications. Thc voro agcncy is usco lccausc thc agcnt rcprcscnts a uscr
lor somc task that it pcrlorms lor thc uscr. An cxamplc incluocs a schcouling
application. Agcnts rcprcscnting uscrs intclligcntly ncgotiatc vith onc
anothcr to schcoulc activitics givcn a sct ol constraints lor cach uscr.
Thc conccpt ol agcnts has cvcn lccn applico to thc opcration ol a
occpspacc spacccralt. n 1000 NASA intcgratco vhat vas callco thc Bcmotc
Agcnt into thc Dccp Spacc 1 spacccralt. Dccp Spacc 1`s goal vas to tcst a
numlcr ol high-risk tcchnologics, onc ol vhich vas an agcnt that vas usco to
provioc autonomy to thc spacccralt lor limitco ourations ol timc. Thc Bcmotc
Agcnt cmployco planning tcchniqucs to autonomously schcoulc cxpcrimcnts
lasco on goals oclnco ly grouno opcrators. Unocr constrainco conoitions, thc
Bcmotc Agcnt succccoco in proving that an intclligcnt agcnt coulo lc usco to
autonomously managc a complicatco prolc ano satisly prcoclnco oljcctivcs.
Tooay you`ll lno agcnts in a numlcr ol arcas, incluoing oistrilutco systcms.
Molilc agcnts arc inocpcnocnt agcnts that incluoc autonomy ano thc alility
to travcl amongst noocs ol a nctvork in orocr to pcrlorm thcir proccssing.
nstcao ol thc agcnt communicating vith anothcr agcnt rcmotcly, thc molilc
agcnt can travcl to thc othcr agcnt`s location ano communicatc vith it oircctly.
n oisconncctco nctvork situations, this can lc vcry lcnclcial. You can lcarn
morc alout intclligcnt agcnts (incluoing molilc agcnts; in Chaptcr 11.
n many cascs, A rcscarch tcnos to lc lringc rcscarch, particularly vhcn
it`s locusco on Strong A. But vhat`s notallc alout rcscarch in A is that
thc algorithms tcno to lno uscs in many othcr oisciplincs lcyono that ol
1he l|stor, oj Al 13
A. A rcscarch is ly no mcans purc rcscarch, lut its applications grov vcll
lcyono thc original intcnt ol thc rcscarch. Ncural nctvorks, oata mining,
luzzy logic, ano Artilcial ilc (lor cxamplc; havc louno uscs in many othcr
lclos. Artilcial ilc is an intcrcsting cxamplc lccausc thc algorithms ano
tcchniqucs that havc rcsultco lrom rcscarch ano ocvclopmcnt havc louno
thcir vay into thc cntcrtainmcnt inoustry (lrom thc usc ol svarming in
animatco motion picturcs to thc usc ol A in vioco gamcs;.
Booncy Brook`s has callco this thc A cllcct, suggcsting that anothcr
oclnition lor A is almost implcmcntco. This is lccausc oncc an A
algorithm lnos a morc common usc, it`s no longcr vicvco as an A algorithm
lut instcao just an algorithm that`s usclul in a givcn prollcm oomain.
n this look, thc majority ol thc algorithms ano tcchniqucs arc stuoico
lrom thc pcrspcctivc ol thc systcms approach. This simply mcans that thc
algorithm is cxplorco in thc contcxt ol inputs ano outputs. No algorithm is
usclul in isolation, lut instcao lrom thc pcrspcctivc ol hov it intcracts vith
its cnvironmcnt (oata sampling, lltcring, ano rcouction; ano also hov it
manipulatcs or altcrs its cnvironmcnt. Thcrclorc, thc algorithm ocpcnos
on an unocrstanoing ol thc cnvironmcnt ano also a vay to manipulatc thc
cnvironmcnt. This systcms approach illustratcs thc practical sioc ol artilcial
intclligcncc algorithms ano tcchniqucs ano iocntilcs hov to grouno thc
mcthoo in thc rcal vorlo (scc Figurc 1.1;.
As an cxamplc, onc ol thc most intcrcsting uscs ol A tooay can lc louno in
gamc systcms. Stratcgy gamcs, lor cxamplc, commonly occupy a map vith tvo
or morc opponcnts. Fach opponcnt compctcs lor rcsourccs in thc cnvironmcnt
in orocr to gain thc uppcr hano ovcr thc othcr. Whilc collccting rcsourccs,
cach opponcnt can schcoulc thc ocvclopmcnt ol asscts to lc usco to oclcat thc
othcr. Whcn multiplc asscts cxist lor an opponcnt (such as a military unit;, thcy
can lc applico in unison, or scparatcly to lay sicgc on anothcr opponcnt.
Whcrc stratcgy gamcs ocpcno on a highcr-lcvcl vicv ol thc cnvironmcnt
(such as voulo lc vicvco lrom a gcncral;, lrst-pcrson shootcr gamcs
(FFS; takc a lovcr-lcvcl vicv (lrom that ol a soloicr;. An agcnt in an FFS
ocpcnos most oltcn on its vicv ol thc lattlclclo. Thc FFS agcnt`s vicv ol thc
cnvironmcnt is at a much lovcr lcvcl, unocrstanoing covcr, oljcctivcs, ano
local cncmy positions. Thc cnvironmcnt is manipulatco ly thc FFS agcnt
through its ovn movcmcnt, attacking or oclcnoing lrom cncmics (through
lnoing covcr;, ano possilly communicating vith othcr agcnts.
14 Art|c|a| lnte|||gence
An olvious cxamplc ol thc systcms approach is in thc lclo ol rolotics.
Molilc rolots, lor cxamplc, utilizc an array ol scnsors ano cllccts that makc
up thc physical rolot. At thc corc ol thc rolot is onc or morc algorithms
that yiclo rational lchavior.
llGURL 1.1 !be systems approacb to Art|c|a| inte|||gence.
1he l|stor, oj Al 15
n cach casc, thc A algorithm that`s choscn is thc corc ol an agcnt`s
scnsors (inputs; ano cllcctors (outputs;. For this rcason, thc algorithm
can`t truly lc usclul or unocrstooo unlcss it`s consiocrco lrom its placc in
thc cnvironmcnt.
OvERvlEw OF 1Hl5 BOOk
This look covcrs a vioc rangc ol A tcchniqucs, cach scgmcntco
appropriatcly into thcir particular gcnrc. Thc lolloving chaptcr summarics
prcscnt thc iocas ano mcthoos that arc cxplorco.
Un|nformed Searcb
n thc carly oays ol A, A vas a scarch, vhcthcr scarch involvco looking lor a
plan, or through thc various movcs that arc possillc (ano sulscqucnt movcs;
in a gamc ol Chcckcrs. n this chaptcr on uninlormco (or llino; scarch,
thc conccpt ol scarch in various spaccs is introoucco, thc rcprcscntation
ol spaccs lor scarch, ano thcn thc various popular algorithms usco in llino
scarch arc cxplorco. This incluocs ocpth-lrst, lrcaoth-lrst, unilorm-cost-
scarch, ano othcrs.
informed Searcb
nlormco scarch is an cvolution ol scarch that applics hcuristics to thc scarch
algorithm, givcn thc prollcm spacc, to makc thc algorithm morc cllcicnt.
This chaptcr covcrs lcst-lrst, a star, hill climling, simulatco anncaling, talu
scarch, ano constraint satislaction.
Ai and Games
Onc ol thc carlicst uscs ol llino ano inlormco scarch vas in thc application to
gamcs. Camcs such as Chcckcrs ano Chcss vcrc lclicvco to lc an intclligcnt
activity, ano il a computcr coulo lc cnoovco vith thc alility to play a gamc
ano vin against a human opponcnt, it coulo lc consiocrco intclligcnt.
Samucl`s Chcckcrs program ocmonstratco a program that coulo oclcat its
crcator, ano vhilc a lcat, this cxpcrimcnt oio not prooucc an intclligcnt
computcr cxccpt vithin thc oomain ol Chcckcrs. This chaptcr cxplorcs
tvo-playcr gamcs ano thc corc ol many gamc-playing systcms, thc minimax
algorithm. A varicty ol gamcs arc thcn oiscussco, lrom thc classical gamcs
such as Chcss, Chcckcrs, ano Co to vioco gamc A, cxploring movcmcnt,
lchavior, tcam, ano rcal-timc stratcgy A.
16 Art|c|a| lnte|||gence
Know|edge Representat|on
Knovlcogc rcprcscntation has a long history in A, particularly in
Strong A rcscarch. Thc goal lchino knovlcogc rcprcscntation is to lno
alstractions lor knovlcogc that rcsult in a lasc ol knovlcogc that`s usclul
to a givcn application. For cxamplc, knovlcogc must lc rcprcscntco in
a vay that makcs it casy lor a computcr to rcason vith it ano unocrstano
thc rclationships lctvccn clcmcnts ol thc knovlcogc lasc. This chaptcr
vill provioc an introouction to a numlcr ol lunoamcntal knovlcogc
rcprcscntation tcchniqucs as vcll as introoucc thc iocas lchino prcoicatc
ano lrst-orocr logic to rcason vith knovlcogc.
Macb|ne Learn|ng
Machinc lcarning is lcst ocscrilco as lcarning lrom cxamplc. Machinc
lcarning incorporatcs a varicty ol mcthoos such as supcrvisco ano
unsupcrvisco lcarning. n supcrvisco lcarning, a tcachcr is availallc to
oclnc corrcct or incorrcct rcsponscs. Unsupcrvisco lcarning oillcrs in that
no tcachcr is prcscnt. (nstcao, unsupcrvisco lcarning lcarns lrom thc oata
itscll ly iocntilying its; rclationships. This chaptcr proviocs an introouction
to machinc lcarning, ano thcn cxplorcs a numlcr ol machinc lcarning
algorithms such as occision trccs ano ncarcst ncighlor lcarning.
Lvo|ut|onary Computat|on
Fvolutionary computation introoucco thc ioca ol scrully approachcs to A.
nstcao ol locusing on thc high lcvcl, trying to imitatc thc lchavior ol thc
human lrain, scrully approachcs start at a lovcr lcvcl trying to rccrcatc
thc morc lunoamcntal conccpts ol lilc ano intclligcncc using liological
mctaphors. This chaptcr covcrs a numlcr ol thc cvolutionary mcthoos
incluoing gcnctic algorithms, gcnctic programming, cvolutionary stratcgics,
oillcrcntial cvolution, ano particlc svarm optimization.
Neura| Networks i
Whilc ncural nctvorks arc onc ol thc carlicst (ano morc controvcrsial;
tcchniqucs, thcy rcmain onc ol thc most usclul. Thc attack on ncural
nctvorks scvcrcly impactco A lunoing ano rcscarch, lut ncural
nctvorks rc-cmcrgco lrom A`s vintcr as a stanoaro lor classilcation ano
lcarning. This chaptcr introouccs thc lasics ol ncural nctvorks, ano thcn
cxplorcs thc supcrvisco ncural nctvork algorithms (lcast-mcan-squarcs,
lackpropagation, prolalilistic ncural nctvorks, ano othcrs;. Thc chaptcr
1he l|stor, oj Al 17
cnos vith a oiscussion ol ncural nctvork charactcristics ano vays to tunc
thcm givcn thc prollcm oomain.
Neura| Networks ii
Whcrc thc prcvious chaptcr cxplorco supcrvisco ncural nctvork
algorithms, this chaptcr proviocs an introouction to thc unsupcrvisco
variants. Unsupcrvisco algorithms usc thc oata itscll to lcarn vithout
thc ncco lor a tcachcr. This chaptcr cxplorcs unsupcrvisco lcarning
algorithms, incluoing Hcllian lcarning, Simplc Compctitivc carning,
k-Mcans Clustcring, Aoaptivc Bcsonancc Thcory, ano thc Hoplclo auto-
associativc moocl.
inte|||gent Agents
ntclligcnt (or Soltvarc; Agcnts arc onc ol ncvcst tcchniqucs in thc A
arscnal. n onc major oclnition, agcnts arc applications that incluoc thc
conccpt ol agcncy. This mcans that thosc applications rcprcscnt a uscr ano
satisly thc goals ol thc task autonomously vithout lurthcr oircction lrom thc
uscr. This chaptcr on intclligcnt agcnts vill introoucc thc major conccpts
lchino intclligcnt agcnts, thcir architccturcs ano applications.
B|o|og|ca||y insp|red and Hybr|d Mode|s
A is lllco vith cxamplcs ol thc usc ol liological mctaphors, lrom carly
vork in ncural nctvorks to moocrn-oay vork in artilcial immunc systcms.
Naturc has provcn to lc a vcry vorthy tcachcr lor complcx prollcm
solving. This chaptcr prcscnts a numlcr ol tcchniqucs that arc loth
liologically inspirco as vcll as hylrio (or mixco; moocls ol A. Mcthoos
such as artilcial immunc systcms, simulatco cvolution, inocnmaycr
systcms, luzzy logic, gcnctically cvolvco ncural nctvorks, ano ant colony
optimization arc cxplorco, to namc a lcv.
Languages of Ai
Whilc most pcoplc think ol SF vhcn consiocring thc languagcs ol A,
thcrc havc lccn a largc numlcr ol languagcs ocvclopco spccilcally lor A
application ocvclopmcnt. n this chaptcr, a taxonomy ol computcr languagcs
is prcscntco lollovco ly short cxamplcs (ano aovantagcs; ol cach. Thcn a
numlcr ol A-spccilc languagcs arc invcstigatco, cxploring thcir history ano
usc through cxamplcs. anguagcs cxplorco incluoc SF, Schcmc, FOF-11,
ano Frolog.
18 Art|c|a| lnte|||gence
Thc history ol A is a moocrn-oay orama. t`s lillco vith intcrcsting
charactcrs, coopcration, compctition, ano cvcn occcption. But outsioc ol
thc orama, thcrc has lccn cxccptional rcscarch ano in rcccnt history an
application ol A`s iocas in a numlcr ol oillcrcnt scttings. A has lnally lclt
thc pcrccption ol lringc rcscarch ano cntcrco thc rcalm ol acccptco rcscarch
ano practical ocvclopmcnt.
|SF 2007] Wikipcoia isp (programming languagc;, 2007.
Availallc onlinc at
|Ncvcll 1056] Ncvcll, A., Shav, ].C., Simon, H.A Fmpcrical Fxplorations ol
thc ogic Thcory Machinc: A Casc Stuoy in Hcuristics, in Frocccoings
ol thc Wcstcrn ]oint Computcr Conlcrcncc, 1056.
|Shannon 1050] Shannon, Clauoc, Frogramming a Computcr lor Flaying
Chcss, I/|||sp/|c| Mcgc:|n 41, 1050.
Bayman, Marc D., ct al Bcsults lrom thc Dccp Spacc 1 Tcchnology
Valioation Mission, 50th ntcrnational Astronomical Congrcss,
Amstcroam, Thc Ncthcrlanos, 1000.
oc castr, canoro N., Timmis, ]onathan Artilcial mmunc Systcms: A Ncv
Computational ntclligcncc Approach Springcr, 2002.
Hollano, ]ohn Aoaptation in Natural ano Artilcial Systcms. Univcrsity ol
Michigan Frcss, Ann Arlor, 1075.
McCarthy, ]ohn Bccursivc Functions ol Symlolic Fxprcssions ano thcir
Computation ly Machinc (Fart ;, Communications ol thc ACM, April
Shortlillc, F.H. Bulc-lasco Fxpcr Systcms: Thc Mycin Fxpcrimcnts ol thc
Stanloro Hcuristic Frogramming Frojcct, Aooison-Wcslcy, 10S4.
Winograo, Tcrry Froccourcs as a Bcprcscntation lor Data in a Computcr
Frogram lor Unocrstanoing Natural anguagc, MT A Tcchnical
Bcport 235, Fclruary 1071.
Wooos, William A. Transition Nctvork Crammars lor Natural anguagc
Analysis, Communications ol thc ACM 13:10, 1070.
1he l|stor, oj Al 19
1. n your ovn voros, oclnc intclligcncc ano vhy intclligcncc tcsts can
hioc thc rcal mcasurc ol intclligcncc.
2. What vas thc Turing tcst, ano vhat vas it intcnoco to accomplish?
3. Why vcrc gamcs thc carly tcst-lco lor A mcthoos? Hov oo you think
A ano gamcs arc vicvco tooay?
4. Hov oio Arthur Samucl sct thc lar lor lcarning programs in thc 1050s?
5. What vas thc lrst languagc ocvclopco spccilcally lor A? What languagc
lollovco in thc 1070s, ocvclopco also lor A?
6. Dclnc Strong A.
7. What cvcnt is most commonly attrilutco to lcaoing to A`s vintcr?
S. What is mcant ly Scrully ano Ncat approachcs to A?
0. Altcr A`s vintcr, vhat vas most uniquc alout A`s rc-cmcrgcncc?
10. This look cxplorcs A lrom thc systcms approach. Dclnc thc systcms
approach ano hov this pcrspcctivc is usco to cxplorc A.
C h a p t e r
ninlormco scarch, also callco llino scarch ano navc scarch, is a
class ol gcncral purposc scarch algorithms that opcratc in a lrutc-
lorcc vay. Thcsc algorithms can lc applico to a varicty ol scarch
prollcms, lut sincc thcy oon`t takc into account thc targct prollcm, arc
incllcicnt. n contrast, inlormco scarch mcthoos (oiscussco in Chaptcr 3;
usc a hcuristic to guioc thc scarch lor thc prollcm at hano ano arc thcrclorc
much morc cllcicnt. n this chaptcr, gcncral statc spacc scarch is cxplorco
ano thcn a varicty ol uninlormco scarch algorithms vill lc oiscussco ano
comparco using a sct ol common mctrics.
Scarch is an important aspcct ol A lccausc in many vays, prollcm solving
in A is lunoamcntally a scarch. Scarch can lc oclnco as a prollcm-solving
tcchniquc that cnumcratcs a prollcm spacc lrom an initial position in scarch
ol a goal position (or solution;. Thc manncr in vhich thc prollcm spacc is
scarchco is oclnco ly thc scarch algorithm or stratcgy. As scarch stratcgics
ollcr oillcrcnt vays to cnumcratc thc scarch spacc, hov vcll a stratcgy vorks
is lasco on thc prollcm at hano. ocally, thc scarch algorithm sclcctco is onc
vhosc charactcristics match that ol thc prollcm at hano.
22 Art|c|a| lnte|||gence
Four classcs ol scarch vill lc cxplorco hcrc. n this chaptcr, vc`ll rcvicv
uninlormco scarch, ano in Chaptcr 3, inlormco scarch vill lc oiscussco.
Chaptcr 3 vill also rcvicv constraint satislaction, vhich trics to lno a sct ol
valucs lor a sct ol variallcs. Finally, in Chaptcr 4, vc`ll oiscuss aovcrsarial
scarch, vhich is usco in gamcs to lno cllcctivc stratcgics to play ano vin
tvo-playcr gamcs.
ct`s lcgin our oiscussion ol scarch ly lrst unocrstanoing vhat is mcant
ly a scarch spacc. Whcn solving a prollcm, it`s convcnicnt to think alout
thc solution spacc in tcrms ol a numlcr ol actions that vc can takc, ano thc
ncv statc ol thc cnvironmcnt as vc pcrlorm thosc actions. As vc takc onc
ol multiplc possillc actions (cach havc thcir ovn cost;, our cnvironmcnt
changcs ano opcns up altcrnativcs lor ncv actions. As is thc casc vith
many kinos ol prollcm solving, somc paths lcao to ocao-cnos vhcrc othcrs
lcao to solutions. Ano thcrc may also lc multiplc solutions, somc lcttcr
than othcrs. Thc prollcm ol scarch is to lno a scqucncc ol opcrators that
transition lrom thc start to goal statc. That scqucncc ol opcrators is thc
Hov vc avoio ocao-cnos ano thcn sclcct thc lcst solution availallc
is a proouct ol our particular scarch stratcgy. ct`s nov look at statc spacc
rcprcscntations lor thrcc prollcm oomains.
Searcb |n a bys|ca| Space
ct`s consiocr a simplc scarch prollcm in physical spacc (Figurc 2.1;. Our
initial position is A` lrom vhich thcrc arc thrcc possillc actions that lcao to
position B,` C,` or D.` Flaccs, or statcs, arc markco ly lcttcrs. At cach placc,
thcrc`s an opportunity lor a occision, or action. Thc action (also callco an
opcrator; is simply a lcgal movc lctvccn onc placc ano anothcr. mplico in
this cxcrcisc is a goal statc, or a physical location that vc`rc sccking.
This scarch spacc (shovn in Figurc 2.1; can lc rcoucco to a trcc
structurc as illustratco in Figurc 2.2. Thc scarch spacc has lccn minimizco
hcrc to thc ncccssary placcs on thc physical map (statcs; ano thc transitions
that arc possillc lctvccn thc statcs (application ol opcrators;. Fach nooc in
thc trcc is a physical location ano thc arcs lctvccn noocs arc thc lcgal movcs.
Thc ocpth ol thc trcc is thc oistancc lrom thc initial position.
Un|njormed 5earch 23
Searcb |n a uzz|e Space
Thc Tovcrs ol Hanoi puzzlc is an intcrcsting cxamplc ol a statc spacc lor
solving a puzzlc prollcm. Thc oljcct ol this puzzlc is to movc a numlcr ol
oisks lrom onc pcg to anothcr (onc at a timc;, vith a numlcr ol constraints
that must lc mct. Fach oisk is ol a uniquc sizc ano it`s not lcgal lor a largcr
oisk to sit on top ol a smallcr oisk. Thc initial statc ol thc puzzlc is such that
all oisks lcgin on onc pcg in incrcasing sizc orocr (scc Figurc 2.2;. Our goal
(thc solution; is to movc all oisks to thc last pcg.
As in many statc spaccs, thcrc arc potcntial transitions that arc not lcgal.
For cxamplc, vc can only movc a pcg that has no oljcct alovc it. Furthcr,
vc can`t movc a largc oisk onto a smallcr oisk (though vc can movc any oisk
llGURL 2.1: A searcb prob|em represented as a pbys|ca| space.
llGURL 2.2: Represent|ng tbe pbys|ca| space prob|em |n i|gure 2.1 as a tree.
24 Art|c|a| lnte|||gence
to an cmpty pcg;. Thc spacc ol possillc opcrators is thcrclorc constrainco
only to lcgal movcs. Thc statc spacc can also lc constrainco to movcs that
havc not yct lccn pcrlormco lor a givcn sultrcc. For cxamplc, il vc movc a
small oisk lrom Fcg A to Fcg C, moving thc samc oisk lack to Fcg A coulo
lc oclnco as an invalio transition. Not ooing so voulo rcsult in loops ano
an inlnitcly occp trcc.
Consiocr our initial position lrom Figurc 2.3. Thc only oisk that may
movc is thc small oisk at thc top ol Fcg A. For this oisk, only tvo lcgal movcs
arc possillc, lrom Fcg A to Fcg B or C. From this statc, thcrc arc thrcc
potcntial movcs:
1. Movc thc small oisk lrom Fcg C to Fcg B.
2. Movc thc small oisk lrom Fcg C to Fcg A.
3. Movc thc mcoium oisk lrom Fcg A to Fcg B.
Thc lrst movc (small oisk lrom Fcg C to Fcg B;, vhilc valio is not a potcntial
movc, as vc just movco this oisk to Fcg C (an cmpty pcg;. Moving it a sccono
timc scrvcs no purposc (as this movc coulo havc lccn oonc ouring thc prior
transition;, so thcrc`s no valuc in ooing this nov (a hcuristic;. Thc sccono
movc is also not usclul (anothcr hcuristic;, lccausc it`s thc rcvcrsc ol thc
llGURL 2.3: A searcb space for tbe ^!ower of Hano|" puzz|e.
Un|njormed 5earch 25
prcvious movc. This lcavcs onc valio movc, thc mcoium oisk lrom Fcg A to
Fcg B. Thc possillc movcs lrom this statc lccomc morc complicatco, lccausc
valio movcs arc possillc that movc us larthcr avay lrom thc solution.

A /ar|s/| |s c s|mp| r j|n/ ra| jr s|c|ng c g|cn pr||m r

mc||ng c d|s|n.
Whcn our scqucncc ol movcs lrings us lrom thc initial position to thc goal,
vc havc a solution. Thc goal statc in itscll is not intcrcsting, lut instcao
vhat`s intcrcsting is thc scqucncc ol movcs that lrought us to thc goal statc.
Thc collcction ol movcs (or solution;, oonc in thc propcr orocr, is in csscncc
a p|cn lor rcaching thc goal. Thc plan lor this conlguration ol thc puzzlc
can lc iocntilco ly starting lrom thc goal position ano |c|/rc||ng to thc
initial position.
Searcb |n an Adversar|a| Game Space
An intcrcsting usc ol scarch spaccs is in gamcs. Also knovn as gamc trccs,
thcsc structurcs cnumcratc thc possillc movcs ly cach playcr alloving
thc scarch algorithm to lno an cllcctivc stratcgy lor playing ano vinning
thc gamc.

T/ /p| j cdcrscr|c| scr/ |n gcm /rs |s \p|rd |n C/cp/r 4.

Consiocr a gamc trcc lor thc gamc ol Chcss. Fach possillc movc is provioco
lor cach possillc conlguration (placcmcnt ol picccs; ol thc Chcss loaro.
But sincc thcrc arc 10
possillc conlgurations ol a Chcss loaro, a gamc
trcc to oocumcnt thc scarch spacc voulo not lc lcasillc. Hcuristic scarch,
vhich must lc applico hcrc, vill lc oiscussco in Chaptcr 3.
ct`s nov look at a much simplcr gamc that can lc morc casily
rcprcscntco in a gamc trcc. Thc gamc ol Nim is a tvo-playcr gamc vhcrc
cach playcr takcs turns rcmoving oljccts lrom onc or morc pilcs. Thc playcr
rcquirco to takc thc last oljcct loscs thc gamc.
Nim has lccn stuoico mathcmatically ano solvco in many oillcrcnt
variations. For this rcason, thc playcr vho vill vin can lc calculatco lasco
upon thc numlcr ol oljccts, pilcs, ano vho plays lrst in an optimally
playco gamc.

T/ gcm j N|m |s sc|d / /cc r|g|nc/d |n C/|nc, |a/ cn | /rcd

/ Grmcnq cs // rd n|mm cn | /rcns|c/d cs /c|. A mp|/
mc//mc/|c| //rq j N|m cs rc/d |q C/cr|s Ba/n |n 1901.
Ba/n 1901]
26 Art|c|a| lnte|||gence
ct`s valk through an cxamplc to scc hov Nim is playco. Wc`ll lcgin vith
a singlc small pilc to limit thc numlcr ol movcs that arc rcquirco. Figurc
2.4 illustratcs a short gamc vith a pilc ol six oljccts. Fach playcr may takc
onc, tvo, or thrcc oljccts lrom thc pilc. n this cxamplc, Flaycr-1 starts
thc gamc, lut cnos thc gamc vith a loss (is rcquirco to takc thc last oljcct
vhich rcsults in a loss in thc miscrc lorm ol thc gamc;. Hao Flaycr-1 takcn
3 in its sccono movc, Flaycr-2 voulo havc lccn lclt vith onc rcsulting in a
vin lor Flaycr-1.
A gamc trcc makcs this inlormation visillc, as illustratco in Figurc 2.5.
Notc in thc trcc that Flaycr-1 must rcmovc onc lrom thc pilc to continuc
thc gamc. l Flaycr-1 rcmovcs tvo or thrcc lrom thc pilc, Flaycr-2 can vin
il playing optimally. Thc shaoco noocs in thc trcc illustratc losing positions
lor thc playcr that must choosc ncxt (ano in all cascs, thc only choicc lclt is
to takc thc only rcmaining oljcct;.
Notc that thc ocpth ol thc trcc octcrmincs thc lcngth ol thc gamc
(numlcr ol movcs;. t`s implico in thc trcc that thc shaoco nooc is thc lnal
movc to lc maoc, ano thc playcr that makcs this movc loscs thc gamc. Also
notc thc sizc ol thc trcc. n this cxamplc, using six oljccts, a total ol 2S noocs
is rcquirco. l vc incrcasc our trcc to illustratc a pilc ol scvcn oljccts, thc
trcc incrcascs to 42 noocs. With cight oljccts, thrcc lalloons to 100 noocs.
Fortunatcly, thc trcc can lc optimizco ly rcmoving ouplicatc sultrccs,
rcsulting in a much smallcr trcc.
llGURL 2.4: A samp|e game of N|m w|tb a p||e of s|x objects.
Un|njormed 5earch 27
A short tour ol trccs ano graphs ano thcir tcrminology is in orocr lclorc
cxploring thc various uninlormco scarch mcthoos.
A graph is a lnitc sct ol cr/|s (or nds; that arc conncctco ly dgs
(or crs;. A |p (or q|; may cxist in a graph, vhcrc an arc (or cogc; may
lcao lack to thc original nooc. Craphs may lc and|r/d vhcrc arcs oo
not imply a oircction, or thcy may lc d|r/d (callco a d|grcp/; vhcrc a
oircction is implicit in thc arc. An arc can also carry a vcight, vhcrc a cost
can lc associatco vith a path.
Fach ol thcsc graphs also ocmonstratcs thc propcrty ol conncctivity. Both
graphs arc nn/d lccausc cvcry pair ol noocs is conncctco ly a path. l
cvcry nooc is conncctco to cvcry nooc ly an arc, thc graph is mp|/. Onc
spccial nn/d graph is callco a /r, lut it must contain no q|s.
Builoing a rcprcscntation ol a graph is simplc ano onc ol thc most
common rcprcscntations is thc cdcnq mc/r|\. This structurc is simply
llGURL 2.3: A comp|ete N|m game tree for s|x objects |n one p||e.
llGURL 2.6: An examp|e of an und|rected
grapb conta|n|ng s|x nodes and e|gbt arcs.
llGURL 2.7: An examp|e of a d|rected
grapb conta|n|ng s|x edges and n|ne arcs.
28 Art|c|a| lnte|||gence
an N ly N matrix (vhcrc N is thc numlcr ol noocs in thc graph;. Fach
clcmcnt ol thc matrix oclncs a conncctivity (or aojaccncy; lctvccn thc nooc
rclcrcncco as thc rov ano thc nooc rclcrcncco as thc column.
Bccall thc unoircctco graph in Figurc 2.6. This graph contains six noocs ano
cight arcs. Thc cdcnq mc/r|\ lor this unoircctco graph is shovn in Figurc
2.0. Thc tvo oimcnsions ol thc graph iocntily thc sourcc (rov; ano ocstination
noocs (column; ol thc graph. From Figurc 2.6, vc knov that nooc A is aojaccnt
to noocs B, C, ano D. This is notco in thc aojaccncy matrix vith a valuc ol onc
in cach ol thc B, C, ano D columns lor rov A. Sincc this is an unoircctco graph,
vc notc symmctry in thc aojaccncy matrix. Nooc A connccts to nooc B (as
iocntilco in rov A;, lut also nooc B connccts to nooc A (as shovn in rov B;.
For a oircctco graph (as shovn in Figurc 2.7;, thc associatco aojaccncy
matrix is illustratco in Figurc 2.10. Sincc thc graph is oircctco, no symmctry
can lc louno. nstcao, thc oircction ol thc arcs is notco in thc matrix.
For cxamplc, nooc B connccts to nooc A, lut nooc A has no associatco
conncction to nooc B.
An intcrcsting propcrty ol thc aojaccncy matrix can lc louno ly rcvicving
thc rovs ano columns in isolation. For cxamplc, il vc rcvicv a singlc rov, vc
can iocntily thc noocs to vhich it connccts. For cxamplc, rov C shovs only a
conncction to nooc F (as inoicatco ly thc onc in that ccll;. But il vc rcvicv
thc column lor nooc C, vc lno thc noocs that havc arcs connccting to nooc
C. n this casc, vc scc noocs A, D, ano F (as illustratco graphically in Figurc
2.7;. Wc can also lno vhcthcr a graph is complctc. l thc cntirc matrix is
non-zcro, thcn thc graph is complctc. t`s also simplc to lno a oisconncctco
graph (a nooc vhosc rov ano column contain zcro valucs;. oops in a graph
can also lc algorithmically oiscovcrco ly cnumcrating thc matrix (rccursivcly
llGURL 2.8: A connected grapb w|tb no cyc|es (otberw|se known as a tree).
Un|njormed 5earch 29
lolloving all paths looking lor thc initial nooc;.
n thc simplc casc, thc valucs ol thc aojaccncy matrix simply oclnc thc
conncctivity ol noocs in thc graph. n vcightco graphs, vhcrc arcs may not
all lc cqual, thc valuc in a ccll can iocntily thc vcight (cost, or oistancc;.
Wc`ll cxplorc cxamplcs ol this tcchniquc in thc rcvicv ol ncural nctvork
construction (Chaptcr 11;.
Aojaccncy lists arc also a popular structurc vhcrc cach nooc contains
a list ol thc noocs to vhich it connccts. l thc graph is sparsc, this
rcprcscntation can rcquirc lcss spacc.
Thc uninlormco scarch mcthoos ollcr a varicty ol tcchniqucs lor graph
scarch, cach vith its ovn aovantagcs ano oisaovantagcs. Thcsc mcthoos arc
cxplorco hcrc vith oiscussion ol thcir charactcristics ano complcxitics.
Big-O notation vill lc usco to comparc thc algorithms. This notation
oclncs thc asymptotic uppcr louno ol thc algorithm givcn thc ocpth (d; ol
thc trcc ano thc lranching lactor, or thc avcragc numlcr ol lranchcs (|;
lrom cach nooc. Thcrc arc a numlcr ol common complcxitics that cxist lor
scarch algorithms. Thcsc arc shovn in Tallc 2.1.
!ab|e 2.1: Common orders of searcb funct|ons.
O-Notation Orocr
O(1; Constant (rcgarolcss ol thc numlcr ol noocs;
llGURL 2.9: Adjacency matr|x for tbe
und|rected grapb sbown |n i|gure 2.6.
llGURL 2.10: Adjacency matr|x for tbe
d|rected grapb (d|grapb) sbown |n i|gure 2.7.
30 Art|c|a| lnte|||gence
O(n; incar (consistcnt vith thc numlcr ol noocs;
O(log n; ogarithmic
; Quaoratic
; Ccomctric
O(n'; Comlinatorial
Big-O notation proviocs a vorst-casc mcasurc ol thc complcxity ol a scarch
algorithm ano is a common comparison tool lor algorithms. Wc`ll comparc
thc scarch algorithms using spc mp|\|/q (mcasurc ol thc mcmory
rcquirco ouring thc scarch; ano /|m mp|\|/q (vorst-casc timc rcquirco
to lno a solution;. Wc`ll also rcvicv thc algorithm lor mp|/nss (can thc
algorithm lno a path to a goal nooc il it`s prcscnt in thc graph; ano p/|mc||/q
(lnos thc lovcst cost solution availallc;.
He|per Ais
A numlcr ol hclpcr AFs vill lc usco in thc sourcc cooc usco to ocmonstratc
thc scarch lunctions. Thcsc arc shovn lclov in isting 2.1.
LiS!iNG 2.1: He|per Ais for tbe searcb funct|ons.
}` Graph ^ll `}
graph_t createGrapb (int noues ),
voiu destroyGrapb (graph_t `g_p ),
voiu addLdge (graph_t `g_p, int from, int to, int value ),
int getLdge (graph_t `g_p, int from, int to ),
}` Stack ^ll `}
stack_t `createStack (int uepth ),
voiu destroyStack (stack_t `s_p ),
voiu pusbStack (stack_t `s_p, int value ),
int popStack (stack_t `s_p ),
int |sLmptyStack (stack_t `s_p ),
}` Queue ^ll `}
gueue_t `createQueue (int uepth ),
voiu destroyQueue (gueue_t `g_p ),
voiu enQueue (gueue_t `g_p, int value ),
int deQueue (gueue_t `g_p ),
int |sLmptyQueue (gueue_t `g_p ),
}` lriority Queue ^ll `}
pgueue_t `createQueue (int uepth ),
Un|njormed 5earch 31
voiu destroyQueue (pgueue_t `g_p ),
voiu enQueue (pgueue_t `g_p, int value, int cost ),
voiu deQueue (pgueue_t `g_p, int `value, int `cost ),
int |sLmptyQueue (pgueue_t `g_p ),
int |siu||Queue (pgueue_t `g_p ),

T/ /|pr jan/|ns cn | jand n // CD-BCM c/ ./sj/cr/

Genera| Searcb arad|gms
Bclorc vc oiscuss somc ol thc uninlormco scarch mcthoos, lct`s look at tvo
simplc gcncral uninlormco scarch mcthoos.
Thc lrst is callco Gnrc/ cnd Ts/.` n this mcthoo, vc gcncratc a
potcntial solution ano thcn chcck it against thc solution. l vc`vc louno
thc solution, vc`rc oonc, othcrvisc, vc rcpcat ly trying anothcr potcntial
solution. This is callco Gnrc/ cnd Ts/` lccausc vc gcncratc a potcntial
solution, ano thcn tcst it. Without a propcr solution, vc try again. Notc hcrc
that vc oon`t kccp track ol vhat vc`vc trico lclorc, vc just plov ahcao vith
potcntial solutions, vhich is a truc llino scarch.
Anothcr option is callco Bcndm Scr/` vhich ranoomly sclccts a ncv
statc lrom thc currcnt statc (ly sclccting a givcn valio opcrator ano applying
it;. l vc rcach thc goal statc, thcn vc`rc oonc. Othcrvisc, vc ranoomly
sclcct anothcr opcrator (lcaoing to a ncv statc; ano continuc.
Banoom scarch ano thc Gnrc/ cnd Ts/` mcthoo arc truly llino
mcthoos ol scarch. Thcy can gct lost, gct caught in loops, ano potcntially
ncvcr lno a solution cvcn though onc cxists vithin thc scarch spacc.
ct`s nov look at somc scarch mcthoos that vhilc llino, can lno a
solution (il onc cxists; cvcn il it takcs a long pcrioo ol timc.
Deptb-i|rst Searcb (DiS)
Thc Dcpth-First Scarch (DFS; algorithm is a tcchniquc lor scarching a
graph that lcgins at thc root nooc, ano cxhaustivcly scarchcs cach lranch
to its grcatcst ocpth lclorc lacktracking to prcviously uncxplorco lranchcs
(Figurc 2.11 illustratcs this scarch orocr;. Noocs louno lut yct to lc
rcvicvco arc storco in a FO qucuc (also knovn as a s/c|;.

A s/c| |s c LIFC ,Lcs/-In-F|rs/-Ca/) n/c|nr j |/s. S|m||cr /

c s/c| j pcpr, // |cs/ |/m p|cd n // /p |s // rs/ |/m / |
32 Art|c|a| lnte|||gence
Thc spacc complcxity lor DFS is O(lo; vhcrc thc timc complcxity is
gcomctric (O(l
;;. This can lc vcry prollcmatic on occp lranching graphs,
as thc algorithm vill continuc to thc maximum ocpth ol thc graph. l loops
arc prcscnt in thc graph, thcn DFS vill lollov thcsc cyclcs inoclnitcly.
For this rcason, thc DFS algorithm is not complctc, as cyclcs can prohilit
thc algorithm lrom lnoing thc goal. l cyclcs arc not prcscnt in thc graph,
thcn thc algorithm is complctc (vill alvays lno thc goal nooc;. Thc DFS
algorithm is also not optimal, lut can lc maoc optimal using path chccking
(to cnsurc thc shortcst path to thc goal is louno;.

T/ DFS |mp|mn/c/|n cn | jand n // CD-BCM c/ ./sj/cr/

Craph algorithms can lc implcmcntco cithcr rccursivcly or using a stack to
maintain thc list ol noocs that must lc cnumcratco. n isting 2.2, thc DFS
algorithm is implcmcntco using a FO stack.
L|st|ng 2.2: !be deptb-rst searcb a|gor|tbm.
=incluue stuio.h
=incluue graph.h
=incluue stack.h
=uefne ^ u
=uefne B 1
llGURL 2.11: Searcb order of tbe DiS a|gor|tbm over a sma|| tree.
Un|njormed 5earch 33
=uefne C 2
=uefne D 3
=uefne L 4
=uefne l 5
=uefne G 6
=uefne H 7
int init_graph( graph_t `g_p )

auuLuge( g_p, ^, B, 1 ),
auuLuge( g_p, ^, C, 1 ),
auuLuge( g_p, B, D, 1 ),
auuLuge( g_p, C, L, 1 ),
auuLuge( g_p, C, l, 1 ),
auuLuge( g_p, D, G, 1 ),
auuLuge( g_p, D, H, 1 ),
return u,
voiu ufs( graph_t `g_p, int root, int goal )

int noue,
int to,
stack_t `s_p,
s_p createStack( 1u ),
pushStack( s_p, root ),
while ( !isLmptyStack(s_p) )
noue popStack( s_p ),
printf(un, noue),
if (noue goal) Ereak,
for (to g_p-noues-1 , to u , to--)
if (getLdge( g_p, noue, to ) )
pusbStack( s_p, to ),
destroyStack( s_p ),
int main()

graph_t `g_p,
34 Art|c|a| lnte|||gence
g_p createGrapb( 8 ),
init_graph( g_p ),
ufs( g_p, u, 5 ),
destroyGrapb( g_p ),
return u,

A scr/ c|gr|//m |s /crc/r|:d cs \/cas/|c /n |/ cn scr/

crq nd |n // grcp/ |n scr/ j // gc|. Ij // gc| |s n/ prsn/ |n
// grcp/, // c|gr|//m ||| /rm|nc/, |a/ ||| scr/ c/ cnd crq
nd |n c sqs/mc/| cq.
Deptb-L|m|ted Searcb (DLS)
Dcpth-imitco Scarch (DS; is a mooilcation ol ocpth-lrst scarch that
minimizcs thc ocpth that thc scarch algorithm may go. n aooition to starting
vith a root ano goal nooc, a ocpth is provioco that thc algorithm vill not
ocsccno lclov (scc isting 2.3;. Any noocs lclov that ocpth arc omittco lrom
thc scarch. This mooilcation kccps thc algorithm lrom inoclnitcly cycling
ly halting thc scarch altcr thc prc-imposco ocpth. Figurc 2.12 illustratcs this
scarch vith a ocpth ol tvo (no noocs occpcr than lcvcl tvo arc scarchco;.

T/ DLS |mp|mn/c/|n cn | jand n // CD-BCM c/ ./sj/cr/

L|st|ng 2.3: !be deptb-||m|ted searcb a|gor|tbm.
=incluue stuio.h
=incluue graph.h
=incluue stack.h
=uefne ^ u
=uefne B 1
=uefne C 2
=uefne D 3
=uefne L 4
=uefne l 5
=uefne G 6
=uefne H 7
int init_graph( graph_t `g_p )

Un|njormed 5earch 35
addLdge( g_p, ^, B, 1 ),
addLdge( g_p, ^, C, 1 ),
addLdge( g_p, B, D, 1 ),
addLdge( g_p, C, L, 1 ),
addLdge( g_p, C, l, 1 ),
addLdge( g_p, D, G, 1 ),
addLdge( g_p, D, H, 1 ),
return u,
voiu uls( graph_t `g_p, int root, int goal, int limit )

int noue, uepth, to,

stack_t `s_p, `su_p,
s_p createStack( 1u ),
su_p createStack( 1u ),
pusbStack( s_p, root ),
pusbStack( su_p, u ),
while ( !|sLmptyStack(s_p) )
noue popStack( s_p ),
uepth popStack( su_p ),
printf(u (uepth u)n, noue, uepth),
if (noue goal) Ereak,
if (uepth limit)
for (to g_p-noues-1 , to u , to--)
if (getLdge( g_p, noue, to ) )
pusbStack( s_p, to ),
pusbStack( su_p, uepth+1 ),
destroyStack( s_p ),
destroyStack( su_p ),
int main()

graph_t `g_p,
g_p createGrapb( 8 ),
init_graph( g_p ),
36 Art|c|a| lnte|||gence
uls( g_p, u, 5, 2 ),
destroyGrapb( g_p ),
return u,
Whilc thc algorithm oocs rcmovc thc possilility ol inlnitcly looping in thc
graph, it also rcouccs thc scopc ol thc scarch. l thc goal nooc hao lccn onc
ol thc noocs markco X`, it voulo not havc lccn louno, making thc scarch
algorithm incomplctc. Thc algorithm can lc complctc il thc scarch ocpth is
that ol thc trcc itscll (in this casc d is thrcc;. Thc tcchniquc is also not optimal
sincc thc lrst path may lc louno to thc goal instcao ol thc shortcst path.
Thc timc ano spacc complcxity ol ocpth-limitco scarch is similar to DFS,
lrom vhich this algorithm is ocrivco. Spacc complcxity is O(lo; ano timc
complcxity is O(l
;, lut d in this casc is thc imposco ocpth ol thc scarch ano
not thc maximum ocpth ol thc graph.
iterat|ve Deepen|ng Searcb (iDS)
tcrativc Dccpcning Scarch (DS; is a ocrivativc ol DS ano comlincs thc
lcaturcs ol ocpth-lrst scarch vith that ol lrcaoth-lrst scarch. DS opcratcs
ly pcrlorming DS scarchcs vith incrcasco ocpths until thc goal is louno.
llGURL 2.13: iterat|ng |ncreased deptb searcbes w|tb iDS.
llGURL 2.12: Searcb order for a tree us|ng deptb-||m|ted searcb (deptb - two).
Un|njormed 5earch 37
Thc ocpth lcgins at onc, ano incrcascs until thc goal is louno, or no lurthcr
noocs can lc cnumcratco (scc Figurc 2.13;.
As shovn in Figurc 2.13, DS comlincs ocpth-lrst scarch vith lrcaoth-
lrst scarch. By minimizing thc ocpth ol thc scarch, vc lorcc thc algorithm to
also scarch thc lrcaoth ol thc graph. l thc goal is not louno, thc ocpth that
thc algorithm is pcrmittco to scarch is incrcasco ano thc algorithm is startco
again. Thc algorithm, shovn in isting 2.4, lcgins vith a ocpth ol onc.
LiS!iNG 2.4: !be |terat|ve deepen|ng-searcb a|gor|tbm.
=incluue stuio.h
=incluue graph.h
=incluue stack.h
=uefne ^ u
=uefne B 1
=uefne C 2
=uefne D 3
=uefne L 4
=uefne l 5
=uefne G 6
=uefne H 7
int init_graph( graph_t `g_p )

addLdge( g_p, ^, B, 1 ),
addLdge( g_p, ^, C, 1 ),
addLdge( g_p, B, D, 1 ),
addLdge( g_p, C, L, 1 ),
addLdge( g_p, C, l, 1 ),
addLdge( g_p, D, G, 1 ),
addLdge( g_p, D, H, 1 ),
return u,
int uls( graph_t `g_p, int root, int goal, int limit )

int noue, uepth,

int to,
stack_t `s_p, `su_p,
s_p createStack( 1u ),
su_p createStack( 1u ),
pusbStack( s_p, root ),
38 Art|c|a| lnte|||gence
pusbStack( su_p, u ),
while ( !|sLmptyStack(s_p) )
noue popStack( s_p ),
uepth popStack( su_p ),
printf(u (uepth u)n, noue, uepth),
if (noue goal) return 1,
if (uepth limit)
for (to g_p-noues-1 , to u , to--)
if (getLdge( g_p, noue, to ) )
pusbStack( s_p, to ),
pusbStack( su_p, uepth+1 ),
destroyStack( s_p ),
destroyStack( su_p ),
return u,
int main()

graph_t `g_p,
int status, uepth,
g_p createGrapb( 8 ),
init_graph( g_p ),
uepth 1,
while (1)
status uls( g_p, u, 5, uepth ),
if (status 1) Ereak,
else uepth++,
destroyGrapb( g_p ),
return u,

T/ IDS |mp|mn/c/|n cn | jand n // CD-BCM c/ ./sj/cr/

DS is aovantagcous lccausc it`s not susccptillc to cyclcs (a charactcristic
ol DS, upon vhich it`s lasco;. t also lnos thc goal ncarcst to thc root nooc,
Un|njormed 5earch 39
as oocs thc BFS algorithm (vhich vill lc octailco ncxt;. For this rcason, it`s
a prclcrrco algorithm vhcn thc ocpth ol thc solution is not knovn.
Thc timc complcxity lor DS is iocntical to that ol DFS ano DS, O(l
Spacc complcxity ol DS is O(lo;.
Unlikc DFS ano DS, DS is vill alvays lno thc lcst solution ano
thcrclorc, it is loth complctc ano optimal.
Breadtb-i|rst Searcb (BiS)
n Brcaoth-First Scarch (BFS;, vc scarch thc graph lrom thc root nooc in
orocr ol thc oistancc lrom thc root. Bccausc thc orocr scarch is ncarcst thc
root, BFS is guarantcco to lno thc lcst possillc solution (shallovcst; in a
non-vcightco graph, ano is thcrclorc also complctc. Bathcr than oigging
occp oovn into thc graph, progrcssing lurthcr ano lurthcr lrom thc root
(as is thc casc vith DFS;, BFS chccks cach nooc ncarcst thc root lclorc
ocsccnoing to thc ncxt lcvcl (scc Figurc 2.14;.
Thc implcmcntation ol BFS uscs a FFO (lrst-in-lrst-out; qucuc,
oillcring lrom thc stack (FO; implcmcntation lor DFS. As ncv noocs
arc louno to lc scarchco, thcsc noocs arc chcckco against thc goal, ano il
thc goal is not louno, thc ncv noocs arc aooco to thc qucuc. To continuc
thc scarch, thc olocst nooc is ocqucuco (FFO orocr;. Using FFO orocr
lor ncv nooc scarch, vc alvays chcck thc olocst noocs lrst, rcsulting in
lrcaoth-lrst rcvicv (scc isting 2.5;.
LiS!iNG 2.5: !be breadtb-rst searcb a|gor|tbm.
=incluue stuio.h
=incluue graph.h
=incluue gueue.h
=uefne ^ u
llGURL 2.14: Searcb order of tbe breadtb-rst searcb a|gor|tbm.
40 Art|c|a| lnte|||gence
=uefne B 1
=uefne C 2
=uefne D 3
=uefne L 4
=uefne l 5
=uefne G 6
=uefne H 7
int init_graph( graph_t `g_p )

addLdge( g_p, ^, B, 1 ),
addLdge( g_p, ^, C, 1 ),
addLdge( g_p, B, D, 1 ),
addLdge( g_p, C, L, 1 ),
addLdge( g_p, C, l, 1 ),
addLdge( g_p, D, G, 1 ),
addLdge( g_p, D, H, 1 ),
return u,
voiu Efs( graph_t `g_p, int root, int goal )

int noue,
int to,
gueue_t `g_p,
g_p createQueue( 1u ),
enQueue( g_p, root ),
while ( !|sLmptyQueue(g_p) )
noue deQueue( g_p ),
printf(un, noue),
if (noue goal) Ereak,
for (to g_p-noues-1 , to u , to--)
if (getLdge( g_p, noue, to ) )
enQueue( g_p, to ),
destroyQueue( g_p ),
int main()

Un|njormed 5earch 41
graph_t `g_p,
g_p createGrapb( 8 ),
init_graph( g_p ),
Efs( g_p, u, 7 ),
destroyGrapb( g_p ),
return u,

T/ BFS |mp|mn/c/|n cn | jand n // CD-BCM c/ ./sj/cr/

Thc oisaovantagc ol BFS is that cach nooc that is scarchco is rcquirco
to lc storco (spacc complcxity is O(l
;;. Thc cntirc ocpth ol thc trcc oocs
not havc to lc scarchco, so d in this contcxt is thc ocpth ol thc solution, ano
not thc maximum ocpth ol thc trcc. Timc complcxity is also O(l

In prc/|c| |mp|mn/c/|ns j BFS, cnd //r scr/ c|gr|//ms, c

|sd ||s/ |s mc|n/c|nd //c/ n/c|ns //s nds |n // grcp/ //c/
/cc |n c|s|/d. T/|s c||s // c|gr|//m / j|n/|q scr/ //
grcp/ |//a/ r-c|s|/|ng nds. In |mp|mn/c/|ns /r // grcp/ |s
|g//d, |p|ng c |sd ||s/ |s n/ pss|||.
llGURL 2.13: B|d|rect|ona| searcb meet|ng |n tbe m|dd|e at node H.
42 Art|c|a| lnte|||gence
B|d|rect|ona| Searcb
Thc Bioircctional Scarch algorithm is a ocrivativc ol BFS that opcratcs ly
pcrlorming tvo lrcaoth-lrst scarchcs simultancously, onc lcginning lrom
thc root nooc ano thc othcr lrom thc goal nooc. Whcn thc tvo scarchcs
mcct in thc mioolc, a path can lc rcconstructco lrom thc root to thc goal.
Thc scarchcs mccting is octcrminco vhcn a common nooc is louno (a nooc
visitco ly loth scarchcs, scc Figurc 2.15;. This is accomplishco ly kccping
a closco list ol thc noocs visitco.
Bioircctional scarch is an intcrcsting ioca, lut rcquircs that vc knov thc
goal that vc`rc sccking in thc graph. This isn`t alvays practical, vhich limits
thc application ol thc algorithm. Whcn it can lc octcrminco, thc algorithm
has usclul charactcristics. Thc timc ano spacc complcxity lor lioircctional
scarch is O(lo/2;, sincc vc`rc only rcquirco to scarch hall ol thc ocpth ol
thc trcc. Sincc it is lasco on BFS, lioircctional scarch is loth complctc ano
Un|form-Cost Searcb (UCS)
Onc aovantagc ol BFS is that it alvays lnos thc shallovcst solution. But
consiocr thc cogc having a cost associatco vith it. Thc shallovcst solution
may not lc thc lcst, ano a occpcr solution vith a rcoucco path cost voulo
lc lcttcr (lor cxamplc, scc Figurc 2.16;. Unilorm -Cost Scarch (UCS; can
lc applico to lno thc lcast-cost path through a graph ly maintaining an
orocrco list ol noocs in orocr ol ocsccnoing cost. This allovs us to cvaluatc
thc lcast cost path lrst
llGURL 2.16: An examp|e grapb wbere cboos|ng tbe |owest cost patb for tbe rst node (A->C)
may not resu|t |n tbe best overa|| patb tbrougb tbe grapb (A->B->L).
Un|njormed 5earch 43

Un|jrm-s/ scr/ |s cn an|njrmd scr/ m//d |cas n /ar|s/|

|s c/ac||q asd. T/ c|gr|//m mcsars // c/ac| s/ j // pc//
|//a/ c//mp/|ng / s/|mc/ |/.
Thc algorithm lor UCS uscs thc accumulatco path cost ano a priority qucuc
to octcrminc thc path to cvaluatc (scc isting 2.6;. Thc priority qucuc
(sortco lrom lcast cost to grcatcst; contains thc noocs to lc cvaluatco. As
nooc chilorcn arc cvaluatco, vc aoo thcir cost to thc nooc vith thc aggrcgatc
sum ol thc currcnt path. This nooc is thcn aooco to thc qucuc, ano vhcn
all chilorcn havc lccn cvaluatco, thc qucuc is sortco in orocr ol asccnoing
cost. Whcn thc lrst clcmcnt in thc priority qucuc is thc goal nooc, thcn thc
lcst solution has lccn louno.
LiS!iNG 2.6: !be un|form-cost searcb a|gor|tbm.
=incluue stuio.h
=incluue graph.h
=incluue pgueue.h
=uefne ^ u
=uefne B 1
=uefne C 2
=uefne D 3
=uefne L 4
int init_graph( graph_t `g_p )

addLdge( g_p, ^, B, 5 ),
addLdge( g_p, ^, C, 1 ),
addLdge( g_p, ^, D, 2 ),
addLdge( g_p, B, L, 1 ),
addLdge( g_p, C, L, 7 ),
addLdge( g_p, D, L, 5 ),
return u,
voiu ucs( graph_t `g_p, int root, int goal )

int noue, cost, chilu_cost,

int to,
pgueue_t `g_p,
g_p createQueue( 7 ),
enQueue( g_p, root, u ),
while ( !|sLmptyQueue(g_p) )
44 Art|c|a| lnte|||gence
deQueue( g_p, 8noue, 8cost ),
if (noue goal)
printf(cost un, cost),
for (to g_p-noues-1 , to u , to--)
chilu_cost getLdge( g_p, noue, to ),
if (chilu_cost)
enQueue( g_p, to, (chilu_cost+cost) ),
destroyQueue( g_p ),
int main()

graph_t `g_p,
g_p createGrapb( 6 ),
init_graph( g_p ),
ucs( g_p, ^, L ),
destroyGrapb( g_p ),
return u,
llGURL 2.17: Node eva|uat|ons and tbe
state of tbe pr|or|ty queue.
llGURL 2.18: i||ustrat|ng tbe patb cost
tbrougb tbe grapb.
Un|njormed 5earch 45

T/ UCS |mp|mn/c/|n cn | jand n // CD-BCM c/ ./sj/cr/

Thc UCS algorithm is casily ocmonstratco using our cxamplc graph in
Figurc 2.16. Figurc 2.17 shovs thc statc ol thc priority qucuc as thc noocs
arc cvaluatco. At stcp onc, thc initial nooc has lccn aooco to thc priority
qucuc, vith a cost ol zcro. At stcp tvo, cach ol thc thrcc conncctco noocs
arc cvaluatco ano aooco to thc priority qucuc. Whcn no lurthcr chilorcn arc
availallc to cvaluatc, thc priority qucuc is sortco to placc thcm in asccnoing
cost orocr.
At stcp thrcc, chilorcn ol nooc C arc cvaluatco. n this casc, vc lno thc
ocsirco goal (F;, lut sincc its accumulatco path cost is cight, it cnos up at
thc cno ol thc qucuc. For stcp lour, vc cvaluatc nooc D ano again lno thc
goal nooc. Thc path cost rcsults in scvcn, vhich is still grcatcr than our B
nooc in thc qucuc. Finally, at stcp lvc, nooc B is cvaluatco. Thc goal nooc is
louno again, vith a rcsulting path cost ol six. Thc priority qucuc nov contains
thc goal nooc at thc top, vhich mcans at thc ncxt itcration ol thc loop, thc
algorithm vill cxit vith a path ol A->B->F (vorking lackvaros lrom thc
goal nooc to thc initial nooc;.
To limit thc sizc ol thc priority qucuc, it`s possillc to prunc cntrics that arc
rcounoant. For cxamplc, at stcp 4 in Figurc 2.17, thc cntry lor F(S; coulo havc
lccn salcly rcmovco, as anothcr path cxists that has a rcoucco cost (F(7;;.
Thc scarch ol thc graph is shovn in Figurc 2.1S, vhich iocntilcs thc path
cost at cach cogc ol thc graph. Thc path cost shovn alovc thc goal nooc (F;
makcs it casy to scc thc lcast-cost path through thc graph, cvcn vhcn it`s not
apparcnt lrom thc initial nooc.
UCS is optimal ano can lc complctc, lut only il thc cogc costs arc
non-ncgativc (thc summco path cost alvays incrcascs;. Timc ano spacc
complcxity arc thc samc as BFS, O(l
; lor cach, as it`s possillc lor thc cntirc
trcc to lc cvaluatco.
Onc ol thc lasic prollcms vith traoitional DFS ano BFS is that thcy
lack a visitco list (a list ol noocs that havc alrcaoy lccn cvaluatco;. This
mooilcation makcs thc algorithms complctc, ly ignoring cyclcs ano only
lolloving paths that havc not yct lccn lollovco. For BFS, kccping a visitco
list can rcoucc thc scarch timc, lut lor DFS, thc algorithm can lc maoc
46 Art|c|a| lnte|||gence
Fach ol thc algorithms has aovantagcs ano oisaovantagcs lasco on thc graph
to lc scarchco. For cxamplc, il thc lranching lactor ol thc graph is small,
thcn BFS is thc lcst choicc. l thc trcc is occp, lut a solution is knovn to
lc shallov in thc graph, thcn DS is a gooo choicc. l thc graph is vcightco,
thcn UCS shoulo lc usco as it vill alvays lno thc lcst solution vhcrc DFS
ano BFS vill not.
Uninlormco scarch algorithms arc a class ol graph scarch algorithms that
cxhaustivcly scarch lor a nooc vithout thc usc ol a hcuristic to guioc thc
scarch. Scarch algorithms arc ol intcrcst in A lccausc many prollcms can
lc rcoucco to simplc scarch prollcms in a statc spacc. Thc statc spacc
consists ol statcs (noocs; ano opcrators (cogcs;, alloving thc statc spacc to
lc rcprcscntco as a graph. Fxamplcs rangc lrom graphs ol physical spaccs
to massivc gamc trccs such as arc possillc vith thc gamc ol Chcss.
Thc ocpth-lrst scarch algorithm opcratcs ly cvaluating lranchcs to
thcir maximum ocpth, ano thcn lacktracking to lollov unvisitco lranchcs.
Dcpth-limitco scarch (DS; is lasco on DFS, lut rcstricts thc ocpth ol thc
scarch. tcrativc-occpcning scarch (DS; uscs DS, lut continually incrcascs
thc scarch ocpth until thc solution is louno.
Thc lrcaoth-lrst scarch (BFS; algorithm scarchcs vith incrcasing
ocpth lrom thc root (scarchcs all noocs vith ocpth onc, thcn all noocs vith
ocpth tvo, ctc.;. A spccial ocrivativc algorithm ol BFS, lioircctional scarch
(BD;, pcrlorms tvo simultancous scarchcs. Starting at thc root nooc ano
thc goal nooc, BD pcrlorms tvo BFS scarchcs in scarch ol thc mioolc.
Oncc a common nooc is louno in thc mioolc, a path cxists lctvccn thc root
ano goal noocs.
Thc unilorm-cost scarch (UCS; algorithm is iocal lor vcight graphs
(graphs vhosc cogcs havc costs associatco vith thcm;. UCS cvaluatcs a graph
using a priority qucuc that is orocrco in path cost to thc particular nooc. t`s
lasco on thc BFS algorithm ano is loth complctc ano optimal.
Tall c 2. 2: Summary ol thc uni nlormco al gori thms ano thci r
Un|njormed 5earch 47
Algoritbm Timc Spacc Optimal Complctc crivativc
; O(lm; No No
DS O(l
; O(ll; No No DFS
DS O(l
; O(lo; Ycs No DS
; O(l
; Ycs Ycs
BD O(l
; O(l
; Ycs Ycs BFS
; O(l
; Ycs Ycs BFS
|, lranching lactor
d, trcc ocpth ol thc solution
m, trcc ocpth
|, scarch ocpth limit
|Bouton 1001] Nim, a gamc vith a complctc mathcmatical thcory, Ann,
Math, Frinccton 3, 35-30, 1001-1002.
1. What is uninlormco (or llino; scarch ano hov oocs it oillcr lrom
inlormco (or hcuristic; scarch?
2. Thc graph structurc is iocal lor gcncral statc spacc rcprcscntation.
Fxplain vhy ano oclnc thc inoivioual componcnts.
3. Dclnc thc qucuing structurcs usco in DFS ano BFS ano cxplain vhy
cach uscs thcir particular stylc.
4. What is thc oclnition ol trcc ocpth?
5. What is thc oclnition ol thc lranching lactor?
6. What arc timc ano spacc complcxity ano vhy arc thcy usclul as mctrics
lor graph scarch?
7. l an algorithm alvays lnos a solution in a graph, vhat is this propcrty
callco? l it alvays lnos thc lcst solution, vhat is this charactcristic?
S. Consiocring DFS ano BFS, vhich algorithm vill alvays lno thc lcst
solution lor a non-vcightco graph?
0. Usc thc DFS ano BFS algorithms to solvc thc Tovcrs ol Hanoi prollcm.
Which pcrlorms lcttcr ano vhy?
10. Frovioc thc scarch orocr lor thc noocs shovn in Figurc 2.10 lor DFS, BFS,
DS (o=2;, DS (start ocpth = 1;, ano BD (start nooc A, goal nooc ;.
48 Art|c|a| lnte|||gence
11. n gcncral, DS is lcttcr than DFS. Drav a graph vhcrc this is not thc
12. n gcncral, DS is not complctc. Why?
13. ocntily a major oisaovantagc ol lioircctional scarch.
14. Using thc UCS algorithm, lno thc shortcst path lrom A to F in Figurc 2.20.
llGURL 2.19: Lxamp|e grapb. llGURL 2.20: Lxamp|e
we|gbted grapb.
C h a p t e r iNiORMLD SLARCH

n Chaptcr 2, vc cxplorco thc uninlormco scarch mcthoos such as

ocpth-lrst ano lrcaoth-lrst scarch. Thcsc mcthoos opcratc in a lrutc-
lorcc lashion ano arc sulscqucntly incllcicnt. n contrast, this chaptcr
vill prcscnt thc inlormco scarch mcthoos. Thcsc mcthoos incorporatc a
hcuristic, vhich is usco to octcrminc thc quality ol any statc in thc scarch
spacc. n a graph scarch, this rcsults in a stratcgy lor nooc cxpansion (vhich
nooc shoulo lc cvaluatco ncxt;. A varicty ol inlormco scarch mcthoos vill lc
invcstigatco ano, as vith uninlormco mcthoos, comparco using a common
sct ol mctrics.

A /ar|s/| |s c ra| j //am| //c/ mcq /|p s|c c g|cn pr||m.

Har|s/|s /c| pr||m |n|dg |n/ ns|drc/|n / /|p ga|d //
scr/ |//|n // dmc|n.
n this chaptcr, vc`ll cxplorc a numlcr ol inlormco scarch mcthoos, incluoing
lcst-lrst scarch, a-star scarch, itcrativc improvcmcnt algorithms such as hill
climling ano simulatco anncaling, ano lnally, constraint satislaction. Wc`ll
ocmonstratc cach vith a samplc prollcm ano illustratc thc hcuristics usco.
50 Art|c|a| lnte|||gence
BE51-FlR51 5EARCH {BE51-F5}
n Bcst-First scarch, thc scarch spacc is cvaluatco accoroing to a hcuristic
lunction. Noocs yct to lc cvaluatco arc kcpt on an OFFN list ano thosc that
havc alrcaoy lccn cvaluatco arc storco on a COSFD list. Thc OFFN list is
rcprcscntco as a priority qucuc, such that unvisitco noocs can lc ocqucuco
in orocr ol thcir cvaluation lunction (rccall thc priority qucuc lrom Chaptcr
2 lor thc Unilorm-Cost Scarch;.
Thc cvaluation lunction j,n) is maoc up ol tvo parts. Thcsc arc thc
hcuristic lunction (/,n); ano thc cstimatco cost (g,n);, vhcrc (scc Fq 3.1;:
j (n) = g(n)+/(n) (Fq 3.1;
Wc can think ol thc cstimatco cost as a valuc mcasurallc lrom our scarch
spacc, ano thc hcuristic lunction as an coucatco gucss. Thc OFFN list is
thcn luilt in orocr ol j,n). This makcs lcst-lrst scarch lunoamcntally grdq
lccausc it alvays chooscs thc lcst local opportunity in thc scarch jrn/|r.

T/ scr/ jrn/|r |s dnd cs // s/ j nd ppr/an|/|s //c/ cn |

scr/d n\/. In Bs/-F|rs/ scr/, // jrn/|r |s c pr|r|/q qaa sr/d
|n j,n) rdr. G|cn // s/r|/ rdr j j,n), // s|/|n j // nd /
cc|ac/ jrm // pr|r|/q qaa |s grdq.
Thc complcxity ol lcst-lrst is O(l
; lor loth timc ano spacc (all noocs
arc savco in mcmory;. By maintaining a COSFD list (to avoio rcvisiting
noocs ano thcrclorc avoioing loops; lcst-lrst scarch is complctc, lut it is
not optimal, as a solution can lc louno in a longcr path (highcr /,n) vith a
lovcr g,n) valuc.

Bs/-F|rs/ scr/ |s c m||nc/|n j cc|ac/|n jan/|ns, /,n) cnd g,n).

N/ //c/ Brcd//-F|rs/ scr/ |s c sp|c| cs j Bs/-F|rs/ scr/ /r
j,n) = /,n), cnd Un|jrm-Cs/ scr/ |s c sp|c| cs j Bs/-F|rs/ scr/
/r j,n) = g,n).
Best-i|rst Searcb and tbe N-Queens rob|em
ct`s nov oiscuss thc lcst-lrst scarch algorithm in thc contcxt ol a largc
scarch spacc. Thc N-quccns prollcm is a scarch prollcm vhcrc thc ocsirco
rcsult is an N ly N loaro vith N quccns such that no quccn thrcatcns
anothcr (scc Figurc 3.1;. For this loaro, in cach ol thc horizontal, vcrtical,
ano oiagonal rovs, no quccn is allc to capturc anothcr.
lnjormed 5earch 51
An important aspcct ol prollcm solving ano scarch is rcprcscntation. For
this cxamplc, vc`ll choosc a simplc rcprcscntation that lts thc solution spacc
vcll ano makcs it simplc to cnumcratc. Fach loaro position is rcprcscntco
ly a singlc lit ano il thc lit is zcro, thcn thc position is vacant, othcrvisc,
it is occupico ly a quccn. Wc`ll simplily thc prollcm ly assigning a quccn
to cach rov on thc loaro. Fnumcrating thc scarch spacc is thcn oclnco as
looking at thc possillc movcs ol quccns horizontally. For cxamplc, thc quccn
at thc top ol Figurc 3.1 can movc lclt or right, lut thc quccn in thc sccono
rov can only movc right (scc Figurc 3.1;. Figurc 3.2 also shovs thc loaro
rcprcscntation as a 16-lit valuc (unsignco short, in thc casc ol C;.
Civcn a statc (thc loaro conlguration;, vc can iocntily thc chilo statcs
lor this loaro ly crcating a ncv loaro lor cach ol thc possillc quccn
llGURL 3.1: Samp|e N-Queens board (wbere N-4).
llGURL 3.2: Board representat|on for tbe N-Queens prob|em (wbere N-4).
52 Art|c|a| lnte|||gence
position changcs, givcn horizontal movcmcnt only. For Figurc 3.2, this loaro
conlguration can rcsult in six ncv chilo statcs (a singlc quccn changc position
in cach;. Notc that sincc vc maintain a closco list, loaro conlgurations that
havc alrcaoy lccn cvaluatco arc not gcncratco, rcsulting in a small trcc ano
morc cllcicnt scarch.
For thc hcuristic, vc`ll usc thc nooc`s ocpth in thc trcc lor /,n), ano
thc numlcr ol connicts (numlcr ol quccns that coulo capturc anothcr;
lor g,n).
Best-i|rst Searcb imp|ementat|on
ct`s nov look at a simplc implcmcntation ol Bcst-First scarch in thc C
languagc. Wc`ll prcscnt thc tvo major lunctions that makc up this scarch
algorithm, thc lrst is lcst_ls, vhich is thc main loop ol thc algorithm. Thc
sccono lunction, gcncratcChiloNoocs, luilos out thc possillc statcs (loaro
conlgurations; givcn thc currcnt statc.
Our main lunction (lcst_ls; is thc OFFN list cnumcrator ano solution
tcstcr. Frior to calling this lunction, our OFFN list (priority qucuc;
ano COSFD list havc lccn crcatco. Thc root nooc, our initial loaro
conlguration, has lccn placco on thc OFFN list. Thc lcst_ls lunction (scc
isting 3.1; thcn ocqucucs thc ncxt nooc lrom thc opcn list (lcst l(n;; l
this nooc has a g(n; (numlcr ol connicts; ol zcro, thcn a solution has lccn
louno, ano vc cxit.
LiS!iNG 3.1: !be Best-Searcb rst ma|n funct|on.
voiu best_fs ( pgueue_t `open_pg_p, gueue_t `closeu_g_p )

noue_t `noue_p,
int cost,
}` Lnumerate the Open list `}
while ( !|sLmptyQueue (open_pg_p) )
deQueue ( open_pg_p, (int `)8noue_p, 8cost ),
}` Solution founu `}
if (noue_p-g u)
printf(lounu Solution (uepth u):n, noue_p-h),
em|tBoard ( noue_p ),
generateCb||dNodes( open_pg_p, closeu_g_p, noue_p ),
lnjormed 5earch 53
Notc in isting 3.1 that vhilc cost is thc j,n), vc chcck g,n) to octcrminc
vhcthcr a solution is louno. This is lccausc j,n) may lc non-zcro sincc it
incluocs thc ocpth ol thc solution (/,n);.

T/ Bs/FS |mp|mn/c/|n cn | jand n // CD-BCM c/ ./sj/cr/

Thc ncxt lunction, gcncratcChiloNoocs, takcs thc currcnt loaro conlguration
ano cnumcratcs all possillc chilo conlgurations ly potcntially moving cach
quccn onc position. Thc movcs array oclncs thc possillc movcs lor cach
position on thc loaro (-1 mcans only right, 2 mcans loth lclt ano right, ano
1 mcans only lclt;. Thc loaro is thcn cnumcratco, ano vhcncvcr a quccn is
louno, thc movcs array is chcckco lor thc lcgal movcs, ano ncv chilo noocs
arc crcatco ano loaoco onto thc OFFN list.
Notc that vc chcck thc COSFD list hcrc to avoio crcating a loaro
conlguration that vc`vc sccn lclorc. Oncc all positions on thc currcnt loaro
havc lccn chcckco, ano ncv chilo noocs arc crcatco, thc lunction rcturns
to lcst_ls.
Whcn a ncv loaro conlguration is louno, thc crcatcNooc lunction
is callco to allocatc a ncv nooc structurc ano placcs this ncv nooc on thc
OFFN list (ano COSFD list;. Notc hcrc that thc onc plus thc ocpth (h(n;;
is passco in to iocntily thc lcvcl ol thc solution in thc trcc.
LiS!iNG 3.2: !be generateCb||dNodes funct|on to enumerate tbe cb||d nodes.
voiu generateCb||dNodes( pgueue_t `pg_p,
gueue_t `closeu_g_p, noue_t `noue_p )

int i,
unsigneu short cEoaru1, cEoaru2,
const int moves|16| -1, 2, 2, 1,
-1, 2, 2, 1,
-1, 2, 2, 1,
-1, 2, 2, 1 ],
}` Generate the chilu noues for the current noue Ey
` shuffing the pieces on the Eoaru.
54 Art|c|a| lnte|||gence
for (i u , i 16 , i++)
}` ls there a gueen at this position `}
if (cbeck|ece( noue_p-Eoaru, i ))
}` Remove current gueen from the Eoaru `}
cEoaru1 cEoaru2 ( noue_p-Eoaru 8 -(1 (15-i) ) ),
if (moves|i| -1)
}` Can only move right `}
cEoaru1 | ( 1 (15-(i+1)) ),
if (!searcbQueue( closeu_g_p, cEoaru1))
(voiu)createNode( pg_p, closeu_g_p, cEoaru1, noue_p-h+1 ),
] else if (moves|i| 2)
}` Can move left or right `}
cEoaru1 | ( 1 (15-(i+1)) ),
if (!searcbQueue( closeu_g_p, cEoaru1))
(voiu)createNode( pg_p, closeu_g_p, cEoaru1, noue_p-h+1 ),
cEoaru2 | ( 1 (15-(i-1)) ),
if (!searcbQueue( closeu_g_p, cEoaru2))
(voiu)createNode( pg_p, closeu_g_p, cEoaru2, noue_p-h+1 ),
] else if (moves|i| 1)
}` Can only move left `}
cEoaru2 | ( 1 (15-(i-1)) ),
if (!searcbQueue( closeu_g_p, cEoaru2))
(voiu)createNode( pg_p, closeu_g_p, cEoaru2, noue_p-h+1 ),
ct`s nov vatch thc algorithm in action. Oncc invokco, a ranoom root nooc
is cnqucuco ano thcn thc possillc chilo conlgurations arc cnumcratco ano
loaoco onto thc OFFN list (scc isting 3.3;. Thc ocmonstration hcrc shovs
a shallov trcc ol thrcc conlgurations chcckco, thc root nooc, onc at lcvcl
onc, ano thc solution louno at ocpth tvo. A conocnsco vcrsion ol this run
is shovn in Figurc 3.3.
lnjormed 5earch 55
LiS!iNG 3.3: Best-i|rst Searcb for tbe N-Queens prob|em (N-4).
New noue: evaluateBoaru 4824 (h u, g 3)
lnitial Boaru:
Eoaru is ux4824
u 1 u u
1 u u u
llGURL 3.3: Grapb|ca| (condensed) v|ew of tbe searcb tree |n L|st|ng 3.3.
56 Art|c|a| lnte|||gence
u u 1 u
u 1 u u
Checking Eoaru ux4824 (h u g 3)
New noue: evaluateBoaru 2824 (h 1, g 2)
New noue: evaluateBoaru 8824 (h 1, g 3)
New noue: evaluateBoaru 4424 (h 1, g 4)
New noue: evaluateBoaru 4814 (h 1, g 3)
New noue: evaluateBoaru 4844 (h 1, g 4)
New noue: evaluateBoaru 4822 (h 1, g 3)
New noue: evaluateBoaru 4828 (h 1, g 2)
Checking Eoaru ux2824 (h 1 g 2)
New noue: evaluateBoaru 1824 (h 2, g 1)
New noue: evaluateBoaru 2424 (h 2, g 5)
New noue: evaluateBoaru 2814 (h 2, g u)
New noue: evaluateBoaru 2844 (h 2, g 2)
New noue: evaluateBoaru 2822 (h 2, g 3)
New noue: evaluateBoaru 2828 (h 2, g 2)
Checking Eoaru ux2814 (h 2 g u)
lounu Solution (h 2 g u):
Eoaru is ux2814
u u 1 u
1 u u u
u u u 1
u 1 u u
Var|ants of Best-i|rst Searcb
Onc intcrcsting variant ol lcst-lrst scarch is callco grdq |s/-rs/ scr/.
n this variant, j,n) = /,n), ano thc OFFN list is orocrco in j orocr. Sincc
/ is thc only lactor usco to octcrminc vhich nooc to sclcct ncxt (iocntilco
as thc closcncss to thc goal;, it`s oclnco as grccoy. Bccausc ol this, grccoy
lcst-lrst is not complctc as thc hcuristic is not cdm|ss||| (lccausc it can
ovcrcstimatc thc path to thc goal;. Wc`ll oiscuss aomissilility in morc octail
in thc oiscussion ol A-star scarch.
Anothcr variant ol lcst-lrst scarch is |cm-scr/, likc grccoy lcst-lrst
scarch, it uscs thc hcuristic j,n) = /,n). Thc oillcrcncc vith lcam-scarch is
that it kccps only a sct ol thc lcst canoioatc noocs lor cxpansion ano simply
throvs thc rcst vay. This makcs lcam-scarch much morc mcmory cllcicnt
than grccoy lcst-lrst scarch, lut sullcrs in that noocs can lc oiscaroco
vhich coulo rcsult in thc optimal path. For this rcason, lcam-scarch is
ncithcr optimal or complctc.
lnjormed 5earch 57
A scarch, likc lcst-lrst scarch, cvaluatcs a scarch spacc using a hcuristic
lunction. But A uscs loth thc cost ol gctting lrom thc initial statc to thc
currcnt statc (g,n);, as vcll as an cstimatco cost (hcuristic; ol thc path lrom
thc currcnt nooc to thc goal (/,n);. Thcsc arc summco to thc cost lunction j,n)
(Scc Fq 3.1;. Thc A scarch, unlikc lcst-lrst, is loth optimal ano complctc.
Thc OFFN ano COSFD lists arc usco again to iocntily thc lronticr lor
scarch (OFFN list; ano thc noocs cvaluatco thus lar (COSFD;. Thc OFFN
list is implcmcntco as a priority qucuc orocrco in lovcst j,n) orocr. What
makcs A intcrcsting is that it continually rc-cvaluatcs thc cost lunction lor
noocs as it rc-cncountcrs thcm. This allovs A to cllcicntly lno thc minimal
path lrom thc initial statc to thc goal statc.
ct`s nov look at A at a high lcvcl ano thcn vc`ll oig lurthcr ano apply
it to a vcll-knovn prollcm. isting 3.4 proviocs thc high lcvcl nov lor A.
LiS!iNG 3.4: H|gb-|eve| ow for tbe A searcb a|gor|tbm.
lnitialize OlLN list (priority gueue)
lnitialize CLOSLD list
llace start noue on the OlLN list
Loop while the OlLN list is not empty
Get Eest noue (parent) from OlLN list (least j (n))
if parent is the goal noue, uone
llace parent on the CLOSLD list
Lxpanu parent to all aujacent noues (auj_noue)
if auj_noue is on the CLOSLD list
uiscaru auj_noue anu continue
else if auj_noue is on the OlLN list
if auj_noue`s g value is Eetter than
the OlLN.auj_noue`s g value
uiscaru OlLN.cur_noue
calculate auj_noue`s g, h anu f values
set auj_noue preuecessor to parent
auu auj_noue to OlLN list
calculate auj_noue`s g, h anu f values
set auj_noue preuecessor to parent
58 Art|c|a| lnte|||gence
auu auj_noue to OlLN list
enu loop
Notc in thc nov lrom isting 3.4 that oncc vc lno thc lcst nooc lrom thc
OFFN list, vc cxpano all ol thc chilo noocs (lcgal statcs possillc lrom thc
lcst nooc;. l thc ncv lcgal statcs arc not louno on cithcr thc OFFN or
COSFD lists, thcy arc aooco as ncv noocs (sctting thc prcocccssor to thc
lcst nooc, or parcnt;. l thc ncv nooc is on thc COSFD list, vc oiscaro
it ano continuc. Finally, il thc ncv nooc is on thc OFFN list, lut thc ncv
nooc has a lcttcr g valuc, vc oiscaro thc nooc on thc OFFN list ano aoo
thc ncv nooc to thc OFFN list (othcrvisc, thc ncv nooc is oiscaroco, il its g
valuc is vorsc;. By rc-cvaluating thc noocs on thc OFFN list, ano rcplacing
thcm vhcn cost lunctions pcrmit, vc allov lcttcr paths to cmcrgc lrom thc
statc spacc.
As vc`vc oclnco alrcaoy, A is complctc, as long as thc mcmory supports
thc ocpth ano lranching lactor ol thc trcc. A is also optimal, lut this
charactcristic ocpcnos on thc usc ol an cdm|ss||| hcuristic. Bccausc A
must kccp track ol thc noocs cvaluatco so lar (ano also thc oiscovcrco noocs
to lc cvaluatco;, thc timc ano spacc complcxity arc loth O(l

T/ /ar|s/| |s dnd cs cdm|ss||| |j |/ carc/|q s/|mc/s //

pc// s/ / // gc|, r andrs/|mc/s |/ ,rmc|ns p/|m|s/|). T/|s
rqa|rs //c/ // /ar|s/| | mn/n|, /|/ mcns //c/ // s/
ncr drcss cr // pc//, cnd |ns/cd mn/n|c||q |nrcss. T/|s
mcns //c/ g,n) ,pc// s/ jrm // |n|/|c| nd / // arrn/ nd)
mn/n|c||q |nrcss, /|| /,n) ,pc// s/ jrm // arrn/ nd /
// gc| nd) mn/n|c||q drcss.
llGURL 3.4: !be L|gbt uzz|e and a demonstrat|on of mov|ng from an |n|t|a| congurat|on to
tbe goa| congurat|on (does not |nc|ude a|| steps).
lnjormed 5earch 59
A Searcb and tbe L|gbt uzz|e
Whilc A has lccn applico succcsslully to prollcm oomains such as path-
lnoing, vc`ll apply it hcrc to vhat`s callco thc Fight Fuzzlc (also knovn
as thc N ly M, or n
-1 tilc puzzlc;. This particular variation ol thc puzzlc
consists ol cight tilcs in a 3 ly 3 grio. Onc location contains no tilc, vhich
can lc usco to movc othcr tilcs to migratc lrom onc conlguration to anothcr
(scc Figurc 3.4;.
Notc in Figurc 3.4 that thcrc arc tvo lcgal movcs that arc possillc.
Thc 1` tilc can movc lclt, ano thc 6` tilc can movc oovn. Thc lnal goal
conlguration is shovn at thc right. Notc that this is onc variation ol thc goal,
ano thc onc that vc`ll usc hcrc.
Thc Fight Fuzzlc is intcrcsting lccausc it`s a oillcult prollcm to solvc,
lut onc that`s lccn stuoico at lcngth ano is thcrclorc vcry vcll unocrstooo.
|Archcr 1000] For cxamplc, thc numlcr ol possillc loaro conlgurations ol
thc Fight Fuzzlc is (nn;', lut only hall ol thcsc arc lcgal conlgurations.

Dar|ng // 1870s, // F|j/n Ia::| ,4 |q 4 ccr|cn/ j // N |q M

pa::|) |cm c pa::| rc: ma/ ||| // Ba|||s a| j // 1970s
cnd 1980s.
On avcragc, 22 movcs arc rcquirco to solvc thc 3 ly 3 variant ol thc puzzlc.
But consiocring 22 as thc avcragc ocpth ol thc trcc, vith an avcragc lranching
lactor ol 2.67, 2.4 trillion non-uniquc tilc conlgurations can lc cvaluatco.
L|gbt-uzz|e Representat|on
Wc`ll usc a common rcprcscntation lor thc Fight Fuzzlc, a lincar vcctor
containing thc tilc placcmcnt lrom lclt to right, top to lottom (scc Figurc
3.5;. This particular lgurc shovs thc movcs possillc lrom thc initial puzzlc
conlguration to ocpth tvo ol this particular statc spacc trcc.
llGURL 3.3: L|gbt uzz|e congurat|on us|ng a s|mp|e vector.
60 Art|c|a| lnte|||gence
For our hcuristic, vc`ll usc thc ocpth ol thc trcc as thc cost lrom thc root to
thc currcnt nooc (othcrvisc knovn as g,n);, ano thc numlcr ol misplacco
tilcs (/,n); as thc cstimatco cost to thc goal nooc (cxcluoing thc llank;. Thc
path cost (j,n); thcn lccomcs thc cost ol thc path to thc currcnt nooc (g,n);
plus thc cstimatco cost to thc goal nooc (/,n);. You can scc thcsc hcuristics
in thc trcc in Figurc 3.6. From thc root nooc, only tvo movcs arc possillc,
lut lrom thcsc tvo movcs, thrcc ncv movcs (statcs; opcn up. At thc lottom
ol this trcc, you can scc that thc cost lunction has occrcasco, inoicating that
thcsc loaro conlgurations arc likcly canoioatcs to cxplorc ncxt.

T/r cr / ppa|cr /ar|s/|s jr // N-pa::| pr||m. T/ rs/ |s

s|mp|q // nam|r j /||s a/ j p|c, /|/ |n gnrc| drcss cs
// gc| |s cpprc/d. T/ //r /ar|s/| |s // Mcn/c//cn d|s/cn j
llGURL 3.6: L|gbt uzz|e tree end|ng at deptb two, |||ustrat|ng tbe cost funct|ons.
lnjormed 5earch 61
/||s /|/ sams // /|| d|s/cn j c/ a/ j p|c /|| / |/s rr/
|c/|n. Fr //|s |mp|mn/c/|n, || dmns/rc/ // s|mp|, |a/
jj/|c, /||s-a/-j-p|c /ar|s/|.

W/|| //r cr ,!`!)' |crd ngarc/|ns pss|||, //r cr n|q

,!`!)'/2 cc||d ngarc/|ns. T/ //r /c|j j // ngarc/|ns cr
ans|cc||. W|| n/ d|| n //|s /r, |a/ |n // sar |mp|mn/c/|n
qa|| s // /s/ |n |n|/Ia::| as|ng // np/ j |ncrs|ns / cc||dc/
// ngarc/|n j // |crd. T/|s np/ cn | jar//r \p|rd |n
KGng 2005].
A Searcb imp|ementat|on
Thc corc thc ol A-star algorithm is implcmcntco in thc lunction astar(;. This
lunction implcmcnts A-star as shovn in isting 3.4. Wc`ll also prcscnt thc
cvaluation lunction, vhich implcmcnts thc tilcs-out-ol-placc` mctric. Thc
list ano othcr support lunctions arc not prcscntco hcrc, lut arc availallc on
thc CD-BOM lor rcvicv.

T/ A` |mp|mn/c/|n cn | jand n // CD-BCM c/ ./sj/cr//!/

ct`s start vith thc cvaluation lunction vhich calculatcs thc cstimatco cost
lrom thc currcnt nooc to thc goal (as thc numlcr ol tilcs out ol placc;, scc
isting 3.6. Thc lunction simply cnumcratcs thc 3 ly 3 loaro as a onc-
oimcnsional vcctor, incrcmcnting a scorc valuc vhcncvcr a tilc is prcscnt in
a position it shoulo not lc in. This scorc is thcn rcturnco to thc callcr.
LiS!iNG 3.6: !be L|gbt uzz|e b(n) est|mated cost metr|c.
uouEle eva|uateBoard( Eoaru_t `Eoaru_p )

int i,
const int test|M^_BO^RD-1|1, 2, 3, 4, 5, 6, 7, 8 ],
int scoreu,
for (i u , i M^_BO^RD-1 , i++)
score + (Eoaru_p-array|i| ! test|i|),
return (uouEle)score,
62 Art|c|a| lnte|||gence
Thc astar lunction is shovn in isting 3.7. Frior to calling this lunction, vc`vc
sclcctco a ranoom loaro conlguration ano placco it onto thc OFFN list. Wc
thcn vork through thc OFFN list, rctricving thc lcst nooc (vith thc lcast l
valuc using gctistBcst; ano immcoiatcly placc it on thc COSFD list. Wc
chcck to scc il this nooc is thc solution, ano il so, vc cmit thc path lrom
thc initial nooc to thc goal (vhich illustratcs thc movcs that vcrc maoc;. To
minimizc scarching too occply in thc trcc, vc halt cnumcrating noocs past
a givcn ocpth (vc scarch thcm no lurthcr;.
Thc ncxt stcp is to cnumcratc thc possillc movcs lrom this statc, vhich
vill lc a maximum ol lour. Thc gctChiloBoaro lunction is usco to rcturn
an aojaccnt nooc (using thc inocx passco in to octcrminc vhich possillc
movc to makc;. l a movc isn`t possillc, thcn a NU is rcturnco ano it`s
With a ncv chilo nooc, vc lrst chcck to scc il it`s alrcaoy lccn cvaluatco
(il it`s on thc COSFD list;. l it is, thcn vc`rc to ocstroy this nooc ano
continuc (to gct thc chilo nooc lor thc currcnt loaro conlguration;. l
vc`vc not sccn this particular loaro conlguration lclorc, vc calculatc thc
hcuristics lor thc nooc. First, vc initializc thc nooc`s ocpth in thc trcc as thc
parcnt`s ocpth plus onc. Ncxt, vc call cvaluatcBoaro to gct thc /||s-a/-j-
p|c mctric, vhich vill act as our h valuc (cost lrom thc root nooc to this
nooc;. Thc g valuc is sct to thc currcnt ocpth, ano thc l valuc is initializco
vith Fq 3.1.
(Fq 3.1;
Wc incluoc an c|p/c ano |/c paramctcr hcrc to givc oillcrcnt vcights to
thc g ano / valucs. n this implcmcntation, c|p/c is 1.0 ano |/c is 2.0. This
mcans that morc vcight is givcn to thc h valuc, ano sulscqucntly thc closcr a
nooc is to thc goal is vcighco highcr than its ocpth in thc statc spacc trcc.
With thc j valuc calculatco, vc chcck to scc il thc nooc is on thc OFFN
list. l it is, vc comparc thcir j valucs. l thc nooc on thc OFFN list has a
vorsc j valuc, thc nooc on thc OFFN list is oiscaroco ano thc ncv chilo
nooc takcs its placc (sctting thc prcocccssor link to thc parcnt, so vc knov
hov vc got to this nooc;. l thc nooc on thc OFFN list has a lcttcr j valuc,
thcn thc nooc on thc OFFN list rcmains on thc opcn list ano thc ncv chilo
is oiscaroco.
Finally, il thc ncv chilo nooc cxists on ncithcr thc COSFD or OFFN
list, it`s a ncv nooc that vc`vc yct to scc. t`s simply aooco to thc OFFN list,
ano thc proccss continucs.
This algorithm continucs until cithcr onc ol tvo cvcnts occur. l thc
OFFN list lccomcs cmpty, thcn no solution vas louno ano thc algorithm
lnjormed 5earch 63
cxits. l thc solution is louno, thcn shovSolution is callco, ano thc noocs
linkco togcthcr via thc prcocccssor links arc cnumcratco to shov thc solution
lrom thc initial nooc to thc goal nooc.
LiS!iNG 3.7: !be A a|gor|tbm.
voiu astar( voiu )

Eoaru_t `cur_Eoaru_p, `chilu_p, `temp,

int i,
}` vhile items are on the open list `}
while ( ||stCount(8openList_p) )
}` Get the current Eest Eoaru on the open list `}
cur_Eoaru_p getL|stBest( 8openList_p ),
putL|st( 8closeuList_p, cur_Eoaru_p ),
}` Do we have a solution `}
if (cur_Eoaru_p-h (uouEle)u.u)
sbowSo|ut|on( cur_Eoaru_p ),
] else
}` Heuristic - average numEer of steps is 22 for a 3x3, so
` uon`t go too ueep.
if (cur_Eoaru_p-uepth M^_DLllH) continue,
}` Lnumerate aujacent states `}
for (i u , i 4 , i++)
chilu_p getCb||dBoard( cur_Eoaru_p, i ),
if (chilu_p ! (Eoaru_t `)u)
if ( onL|st(8closeuList_p, chilu_p-array, NLL) )
nodeiree( chilu_p ),
chilu_p-uepth cur_Eoaru_p-uepth + 1,
chilu_p-h eva|uateBoard( chilu_p ),
chilu_p-g (uouEle)chilu_p-uepth,
chilu_p-f (chilu_p-g ` ^LlH^) + (chilu_p-h ` BLl^),
}` New chilu Eoaru on the open list `}
if ( onL|st(8openList_p, chilu_p-array, NLL) )
temp getL|st(8openList_p, chilu_p-array),
if (temp-g chilu_p-g)
64 Art|c|a| lnte|||gence
putL|st(8openList_p, temp),
nodeiree( temp ),
] else
}` Chilu Eoaru either uoesn`t exist, or is Eetter than a
` previous Eoaru. Hook it to the parent anu place on the
` open list.
chilu_p-preu cur_Eoaru_p,
putL|st( 8openList_p, chilu_p ),
L|gbt uzz|e Demonstrat|on w|tb A
n thc implcmcntation, thc tilcs arc lalclco A-H vith a spacc usco to ocnotc
thc llank tilc. Upon cxccution, oncc thc solution is louno, thc path takcn
lrom thc initial loaro to thc goal is cnumcratco. This is shovn lclov in
isting 3.S, minimizco lor spacc.
LiS!iNG 3.8: A samp|e run of tbe A program to so|ve tbe L|gbt uzz|e.
L ^
lnjormed 5earch 65
D l
A Var|ants
Thc popularity ol A has spavnco a numlcr ol variants that ollcr oillcrcnt
charactcristics. Thc I/rc/|c-Dpn|ng A` algorithm lacktracks to othcr
noocs vhcn thc cost ol thc currcnt lranch cxcccos a thrcsholo. To minimizc
thc mcmory rcquircmcnts ol A, thc S|mp||j|d Mmrq-Bandd A`
algorithm (SMA; vas crcatco. SMA uscs thc mcmory maoc availallc to
it, ano vhcn it runs out ol mcmory, thc algorithm orops thc lcast promising
nooc to makc room lor ncv scarch noocs lrom thc lronticr.
App||cat|ons of A Searcb
A scarch is a popular tcchniquc ano has sccn usc as a path-lnoing algorithm
lor computcr stratcgy gamcs. For lcttcr pcrlormancc, many gamcs cmploy
simplcr shortcut mcthoos lor path-lnoing ly limiting thc spacc ol thcir
movcmcnt (using a much sparscr graph ovcr thc lanoscapc;, or ly prc-
calculating routcs lor in-gamc usc.
Hill climling is an itcrativc improvcmcnt algorithm that is similar to grccoy
lcst-lrst scarch, cxccpt that lacktracking is not pcrmittco. At cach stcp in
thc scarch, a singlc nooc is choscn to lollov. Thc critcrion lor thc nooc to
lollov is that it`s thc lcst statc lor thc currcnt statc. Sincc thc lronticr lor thc
scarch is a singlc nooc, thc algorithm is also similar to lcam scarch using a
lcam vioth ol onc (our OFFN list can contain cxactly onc nooc;.
66 Art|c|a| lnte|||gence
Thc prollcm vith hill climling is that thc lcst nooc to cnumcratc locally
may not lc thc lcst nooc glolally. For this rcason, hill climling can lcao to
local optimums, lut not ncccssarily thc glolal optimum (thc lcst solution
availallc;. Consiocr thc lunction in Figurc 3.7. Thcrc cxists a local optimum
ano a glolal optimum. Thc goal shoulo lc to maximizc thc lunction, lut il
vc lcgin at thc lar lclt ano vork our vay tovaro thc glolal optimum, vc
gct stuck at thc local optimum.
Simulatco Anncaling (SA; is anothcr itcrativc improvcmcnt algorithm in
vhich ranoomncss is incorporatco to cxpano thc scarch spacc ano avoio
lccoming trappco in local minimum. As thc namc implics, thc algorithm
simulatcs thc proccss ol anncaling.
Annc||ng is a tcchniquc in mctal-casting vhcrc moltcn mctal is hcatco
ano thcn coolco in a graoual manncr to cvcnly oistrilutc thc molcculcs into a
crystallinc structurc. l thc mctal is coolco too quickly, a crystallinc structurc
oocs not rcsult, ano thc mctal solio is vcak ano lrittlc (having lccn lllco vith
lulllcs ano cracks;. l coolco in a graoual ano controllco vay, a crystallinc
structurc lorms at a molccular lcvcl rcsulting in grcat structural intcgrity.
Thc lasic algorithm lor simulatco anncaling is shovn in isting 3.0. Wc
start vith an initial solution canoioatc ano thc loop vhilc thc tcmpcraturc is
grcatcr than zcro. n this loop, vc crcatc an aojaccnt canoioatc solution ly
pcrturling our currcnt solution. This changcs thc solution to a ncighloring
solution, lut at ranoom. Wc thcn calculatc thc oclta cncrgy lctvccn thc
ncv (aojaccnt; solution, ano our currcnt solution. l this oclta cncrgy is lcss
llGURL 3.7: State space |||ustrat|ng tbe prob|em w|tb b||| c||mb|ng.
lnjormed 5earch 67
than zcro, thcn our ncv solution is lcttcr than thc olo, ano vc acccpt it (vc
movc thc ncv aojaccnt solution to our currcnt solution;.
LiS!iNG 3.9: S|mu|ated annea||ng a|gor|tbm.

cur_solution ranuom()
computeL( cur_solution )
while (lemperature u)
auj_solution perturE_solution( cur_solution )
computeL( auj_solution )
}` ls new solution Eetter, then take it `}
if (ueltaL u)
cur_solution auj_solution
p exp( -ueltaL } lemperature )
}` Ranuomly accept worse solution `}
if ( p R^NDOM(u..1) )
cur_solution auj_solution
reuuce lemperature
enu simulateu_annealing
l our ncv solution vas not lcttcr than thc olo, thcn vc acccpt it vith a
prolalility proportional to thc currcnt tcmpcraturc ano thc oclta cncrgy.
Thc lovcr thc tcmpcraturc, thc lcss likcly vc`ll acccpt a vorsc solution. But
thc lcttcr thc oclta cncrgy, thc morc likcly vc`ll acccpt it. This prolalility
is calculatco as shovn in Fq 3.2.
(Fq 3.2;
Sincc our tcmpcraturc occrcascs ovcr timc, it`s lcss likcly that a vorsc
solution vill lc acccptco. Farly on vhcn thc tcmpcraturc is high, vorsc
solutions can lc acccptco alloving thc scarch to movc avay lrom local
maximum in scarch ol thc glolal maximum. As thc tcmpcraturc occrcascs,
it lccomcs morc oillcult to acccpt a vorsc solution, vhich mcans that thc
algorithm scttlcs on a solution ano simply lnc-tuncs it (il possillc;.
68 Art|c|a| lnte|||gence
Thc classical simulatco anncaling algorithm also incluocs mn/ cr|
cyclcs vhcrc a numlcr ol trials arc pcrlormco lclorc occrcasing thc
!be !rave||ng Sa|esman rob|em (!S)
To ocmonstratc thc simulatco anncaling algorithm, vc`ll usc thc classic
Travcling Salcsman Frollcm (or TSF;. n thc TSF, vc`rc givcn a sct ol citics
ano a rclativc cost lor travcling lctvccn cach city to cach othcr. Thc goal
is to lno a path through all citics vhcrc vc visit all citics oncc, ano lno thc
shortcst ovcrall tour. Wc`ll start at onc city, visit cach othcr city, ano thcn
cno at thc initial city.
Consiocr thc graph shovn in Figurc 3.S. Many citics arc conncctco to
onc anothcr, lut an optimal path cxists that tours cach city only oncc.
Thc TSF is loth intcrcsting ano important lccausc it has practical
implications. Consiocr transportation prollcms vhcrc oclivcrics arc rcquirco
ano lucl ano timc arc to lc minimizco. Anothcr intcrcsting application is
that ol orilling holcs in a circuit loaro. A numlcr ol holcs must lc orillco
quickly on a singlc loaro, ano in orocr to oo this, an optimal path is nccoco
to minimizc thc movcmcnt ol thc orill (vhich vill lc slov;. Solutions to thc
TSF can thcrclorc lc vcry usclul.
!S !our Representat|on
To rcprcscnt a sct ol citics ano thc tour lctvccn thcm, vc`ll usc an implicit
cdcnq ||s/. Fach city vill lc containco in thc list, ano citics that arc ncxt
to onc anothcr arc implico as conncctco in thc tour. Bccall our samplc TSF
in Figurc 3.S vhcrc scvcn citics makc up thc vorlo. This vill lc rcprcscntco
as shovn in Figurc 3.0.
llGURL 3.8: A Samp|e !S tour tbrougb a sma|| grapb.
lnjormed 5earch 69
llGURL 3.9: Adjacency ||st for tbe !S tour sbown |n i|gure 3.8.
llGURL 3.10: Demonstrat|on of row swapp|ng to perturb tbe tour.
70 Art|c|a| lnte|||gence
Notc that thc list shovn in Figurc 3.0 is a singlc list in tour orocr. Whcn
vc rcach thc cno ol thc list, vc vrap to thc lrst clcmcnt, complcting thc
tour. To pcrturl thc tour vc takc tvo ranoom rovs lrom thc list ano svap
thcm. This is ocmonstratco in Figurc 3.10. Notc hov ly simply svapping
tvo clcmcnts, thc tour is grcatly pcrturlco ano rcsults in a vorsc tour
S|mu|ated Annea||ng imp|ementat|on
Thc implcmcntation ol simulatco anncaling is actually quitc simplc in thc
C languagc. Wc`ll rcvicv thrcc ol thc lunctions that makc up thc simulatco
anncaling implcmcntation, thc main simulatco anncaling algorithm,
pcrturling a tour, ano computing thc lcngth ol thc tour. Thc rcmaining
lunctions arc availallc on thc CD-BOM.
LiS!iNG 3.10: Structures for tbe !S so|ut|on.
typeuef struct
int x, y,
] city_t,
typeuef struct
city_t cities|M^_ClllLS|,
uouEle tour_length,
] solution_t,
Thc Fucliocan oistancc ol thc tour is calculatco vith computc_tour. This
lunction valks through thc tour, accumulating thc scgmcnts lctvccn cach
city (scc isting 3.11;. t cnos ly vrapping arouno thc list, ano aooing in thc
oistancc lrom thc last city lack to thc lrst.
LiS!iNG 3.11: Ca|cu|at|ng tbe Luc||dean tour w|tb compute_tour.
voiu compute_tour( solution_t `sol )

int i,
uouEle tour_length (uouEle)u.u,
for (i u , i M^_ClllLS-1 , i++)
tour_length +
sol-cities|i|.x, sol-cities|i|.y,
sol-cities|i+1|.x, sol-cities|i+1|.y ),
lnjormed 5earch 71

tour_length +
sol-cities|u|.x, sol-cities|u|.y ),
sol-tour_length tour_length,
Civcn a solution, vc can crcatc an aojaccnt solution using thc lunction
pcrturl_tour. n this lunction, vc ranoomly sclcct tvo citics in thc tour, ano
svap thcm. A loop cxists to cnsurc that vc`vc sclcctco tvo uniquc ranoom
points (so that vc oon`t svap a singlc city vith itscll;. Oncc sclcctco, thc x
ano y cooroinatcs arc svappco ano thc lunction is complctc.
LiS!iNG 3.12: erturb|ng tbe tour by creat|ng an adjacent so|ut|on.
voiu perturb_tour( solution_t `sol )

int p1, p2, x, y,

p1 R^NDM^(M^_ClllLS),
p2 R^NDM^(M^_ClllLS),
] while (p1 p2),
x sol-cities|p1|.x,
y sol-cities|p1|.y,
sol-cities|p1|.x sol-cities|p2|.x,
sol-cities|p1|.y sol-cities|p2|.y,
sol-cities|p2|.x x,
sol-cities|p2|.y y,
Finally, thc simulatco_anncaling lunction implcmcnts thc corc ol
thc simulatco anncaling algorithm. Thc algorithm loops arouno thc
tcmpcraturc, constantly rcoucing until it rcachcs a valuc ncar zcro.
Thc initial solution has lccn initializco prior to this lunction. Wc takc
thc currcnt solution ano pcrturl it (ranoomly altcr it; lor a numlcr ol
72 Art|c|a| lnte|||gence
itcrations (thc Montc Carlo stcp;. l thc ncv solution is lcttcr, vc acccpt
it ly copying it into thc currcnt solution. l thc ncv solution is vorsc,
thcn vc acccpt it vith a prolalility oclnco ly Fq 3.2. Thc vorsc thc ncv
solution ano thc lovcr thc tcmpcraturc, thc lcss likcly vc arc to acccpt thc
ncv solution. Whcn thc Montc Carlo stcp is complctc, thc tcmpcraturc
is rcoucco ano thc proccss continucs. Whcn thc algorithm complctcs, vc
cmit thc city tour.
LiS!iNG 3.13: !be s|mu|ated annea||ng ma|n funct|on |mp|ementat|on.
int s|mu|ated_annea||ng( voiu )

uouEle temperature lNlll^L_lLMl, uelta_e,

solution_t tempSolution,
int iteration,
while( temperature u.uuu1 )
}` Copy the current solution to a temp `}
memcpy( (char `)8tempSolution,
(char `)8curSolution, sizeof(solution_t) ),
}` Monte Carlo lterations `}
for (iteration u ,
iteration NM_llLR^llONS , iteration++)
perturb_tour( 8tempSolution ),
compute_tour( 8tempSolution ),
uelta_e tempSolution.tour_length
}` ls the new solution Eetter than the olu `}
if (uelta_e u.u)
}` ^ccept the new, Eetter, solution `}
memcpy( (char `)8curSolution,
(char `)8tempSolution, sizeof(solution_t) ),
] else
}` lroEaEilistically accept a worse solution `}
if ( exp( (-uelta_e } temperature) ) R^NDOM())
memcpy( (char `)8curSolution,
(char `)8tempSolution, sizeof(solution_t) ),
}` Decrease the temperature `}
lnjormed 5earch 73
temperature ` ^LlH^,
return u,
Simulatco anncaling pcrmits a ranoom valk through a statc spacc, grccoily
lolloving thc lcst path. But simulatco anncaling also prolalilistically allovs
lolloving vorsc paths in an cllort to cscapc local maximums in scarch ol
thc glolal maximum. This makcs simulatco anncaling a ranoom scarch,
lut hcuristically orivcn. For all ol its aovantagcs, simulatco anncaling is
incomplctc ano suloptimal.
S|mu|ated Annea||ng Demonstrat|on
ct`s nov look at thc simulatco anncaling algorithm in action. Wc`ll look at
thc algorithm lrom a varicty ol pcrspcctivcs, lrom thc tcmpcraturc schcoulc,
to a samplc solution to TSF lor 25 citics.
llGURL 3.11: !be temperature decay curve us|ng Lq 3.3.
74 Art|c|a| lnte|||gence
Thc tcmpcraturc schcoulc is a lactor in thc prolalility lor acccpting a
vorsc solution. n this implcmcntation, vc`ll usc a gcomctric occay lor thc
tcmpcraturc, as shovn in Fq 3.3.
T = aT (Eq 3.3)
n this casc, vc usc an alpha ol 0.000. Thc tcmpcraturc occay using this
cquation is shovn in Figurc 3.11.
Thc rclativc ltncss ol thc solution ovcr a run is shovn in Figurc 3.12.
This graph shovs thc lcngth ol thc tour ouring thc occrcasc in tcmpcraturc.
Notc at thc lclt-hano sioc ol thc graph that thc rclativc ltncss is vcry crratic.
This is ouc to thc high tcmpcraturc acccpting a numlcr ol poorcr solutions.
As thc tcmpcraturc occrcascs (moving to thc right ol thc graph;, poorcr
solutions arc not acccptco as rcaoily. At thc lclt-hano sioc ol thc graph, thc
algorithm pcrmits cxploration ol thc statc spacc, vhcrc at thc right-hano ol
thc graph, thc solution is lnc-tunco.
A samplc TSF tour is shovn lnally in Figurc 3.13. This particular
solution vas lor a 25 city tour.
llGURL 3.12: !be re|at|ve tness.
lnjormed 5earch 75
Talu scarch is a vcry simplc scarch algorithm that is casy to implcmcnt ano
can lc vcry cllcctivc. Thc lasic ioca lchino Talu scarch is ncighlorhooo
scarch vith a Tc|a list ol noocs that is maoc up ol noocs prcviously cvaluatco.
Thcrclorc, thc scarch may octcrioratc, lut this allovs thc algorithm to viocn
thc scarch to avoio lccoming stuck in local maxima. During cach itcration
ol thc algorithm, thc currcnt scarch canoioatc is comparco against thc lcst
solution louno so lar so that thc lcst nooc is savco lor latcr. Altcr somc
scarch critcria has lccn mct (a solution louno, or a maximum numlcr ol
itcrations; thc algorithm cxits.
Thc Talu list can lc ol lnitc sizc so that thc olocst noocs can lc oroppco
making room lor ncv Talu noocs. Thc noocs on thc Talu list can also lc
timco, such that a nooc can only lc Talu lor somc pcrioo ol timc. Fithcr
casc allovs thc algorithm to rcusc thc Talu list ano minimizc thc amount
ol mcmory nccoco.
llGURL 3.13: Samp|e !S tour opt|m|zed by s|mu|ated annea||ng.
76 Art|c|a| lnte|||gence
Monitoring Talu scarch through thc statc spacc ol thc 4-Quccns prollcm
is shovn in Figurc 3.14. Thc initial position is thc root, vhich has a scorc
ol thrcc (thrcc connicts;. Thc goal is to minimizc thc scorc, vhcrc zcro is a
solution (goal nooc;. At thc lrst itcration, thc ncighlor noocs arc cvaluatco,
ano thc lcst sclcctco. Notc also hcrc that our initial nooc has lccn placco
on thc Talu list. At itcration tvo, thc ncighlors arc cvaluatco lor thc currcnt
nooc ano thc lcst is choscn to movc lorvaro. Thc Talu list nov contains thc
prcvious tvo lcst noocs. n this itcration, vc`vc louno a nooc vith a scorc ol
zcro, vhich inoicatcs a goal nooc ano thc algorithm tcrminatcs.
Thc lasic nov lor Talu scarch is shovn in isting 3.14. Civcn an initial
position (shovn hcrc as a initial ranoom position;, thc scarch spacc is
cnumcratco ly taking thc lcst ncighlor nooc that is not Talu. l it`s lcttcr
than our lcst savco solution, it lccomcs thc lcst solution. Thc proccss thcn
continucs vith thc last solution until a tcrmination critcria is mct.
llGURL 3.14: !be 4-Queens prob|em so|ved by !abu searcb.
lnjormed 5earch 77
LiS!iNG 3.14: !be bas|c ow of tbe !abu searcb a|gor|tbm.

cur_solution ranuom()
evaluate_position( cur_solution )
Eest cur_solution
taEu( cur_solution )
while (!termination_critera)
}` Get the Eest neighEor, not on the taEu list `}
cur_solution Eest_non_taEu_neighEor( cur_solution )
evaluate_position( cur_solution )
taEu( cur_solution )
if (cur_solution.f Eest.f)
Eest cur_solution

return Eest
To illustratc thc Talu scarch algorithm, vc`ll usc thc N-Quccns prollcm
as ocmonstratco vith thc lcst-lrst scarch algorithm. (Scc Figurc 3.1 lor a
rccap ol thc prollcm ano ocsirco solution.; Altcr oiscussing thc lasic Talu
scarch implcmcntation, vc`ll cxplorc somc ol thc variants that improvc thc
!abu Searcb imp|ementat|on
Thc Talu scarch algorithm is vcry simplc ano can lc illustratco in a singlc
lunction (scc isting 3.15, lunction ;. This lunction is thc corc ol
thc Talu scarch algorithm. Thc supporting lunctions arc not shovn hcrc,
lut arc availallc on thc CD-BOM.

T/ C sar |cngacg |mp|mn/c/|n j Tc|a scr/ cn | jand n

// CD-BCM c/ ./sj/cr//!//c|as..
Thc implcmcntation lcgins vith a sccoing ol thc ranoom lunction
(BANDNT; lollovco ly thc crcation ol thc Talu qucuc. This qucuc
rcprcscnts our Talu list, or thosc clcmcnts that vill not lc cvaluatco lurthcr
78 Art|c|a| lnte|||gence
il rcoiscovcrco. Thc initial solution is thcn crcatco, ano copico to thc lcst
solution (via initBoaro to crcatc thc solution, ano cvaluatcBoaro to cvaluatc
thc valuc ol thc solution;. Thc currcnt solution is thcn loaoco onto thc Talu
list so that it`s not cvaluatco again.
Thc loop thcn lcgins, lor vhich vc`ll opcratc lorcvcr, or until a solution
is louno. For this simplc prollcm, vc`ll alvays lno a solution in somc
numlcr ol itcrations. Thc call to rcvicvChiloNoocs cvaluatcs thc ncighlor
solutions, ano picks thc lcst onc that is not on thc Talu list. This solution is
rcturnco (ly rclcrcncc; ano thcn loaoco onto thc Talu list. Notc hcrc that
vc lrst chcck to scc il it`s alrcaoy on thc Talu list. l not, vc chcck thc statc
ol thc Talu list. l lull, vc ncco thc olocst clcmcnt to makc room lor thc
ncv nooc, ano thcn aoo it to thc qucuc.

Bc|| //c/ qaas cr FIFC |n nc/ar. T/rjr, rmc|ng c nd jrm

// qaa ca/mc/|c||q rmcs // |ds/ nd, sc/|sjq|ng // p||q
jr // c|gr|//m ,rmc // |ds/ nd rs/, |j // Tc|a ||s/ |s ja||).
Finally, vc chcck thc valuc ol thc solution, ano il zcro, vc havc thc goal nooc.
This can nov lc cmittco using thc cmitBoaro lunction.
LiS!iNG 3.15: Bas|c !abu searcb a|gor|tbm |mp|ementat|on |n C.
voiu taEu_s()

unsigneu short Eest_sol, cur_sol,

int Eest_f, cur_f,
taEu_g createQueue(M^_LLLMLNlS),
}` Get initial Eoaru `}
cur_sol Eest_sol |n|tBoard(),
cur_f Eest_f eva|uateBoard( Eest_sol ),
enQueue( taEu_g, Eest_sol ),
while( 1 )
printf(lteration for xn, cur_sol),
}` Return (Ey reference) the Eest non-taEu neighEor `}
rev|ewCb||dNodes( 8cur_sol, 8cur_f ),
}` ^uu the current Eest solution to the taEu list (remove
` the oluest if neeueu).
if (!searcbQueue( taEu_g, cur_sol ))
if (|siu||Queue( taEu_g ))
lnjormed 5earch 79
(voiu)deQueue( taEu_g ),
enQueue( taEu_g, cur_sol ),
}` Save the Eest solution so far `}
if (cur_f Eest_f)
Eest_sol cur_sol,
Eest_f cur_f,
}` Solution founu `}
if (Eest_f u )
em|tBoard( Eest_sol ),
destroyQueue( taEu_g ),
!abu Searcb Demonstrat|on
Thc Talu scarch application cllcicntly lnos thc solution to this prollcm (a
statc spacc ol 256 uniquc noocs;. Thc lrst cvaluatcBoaro is thc initial nooc
(scc isting 3.16;, lollovco ly lour itcrations ol thc algorithm. Notc that vhilc
thc initial nooc hao a cost ol tvo, sulscqucnt noocs cvaluatco vcrc vorsc,
lut cvcntually lco to thc goal. Talu scarch pcrmits thc cvaluation avay lrom
local minimum to lno thc glolal minimum, as ocmonstratco hcrc.
LiS!iNG 3.16: Samp|e execut|on of !abu searcb for tbe 4-Queens prob|em.
evaluateBoaru 1281 (f 2)
lteration for 1281
evaluateBoaru 2281 (f 2)
evaluateBoaru 2181 (f 3)
evaluateBoaru 2481 (f 3)
evaluateBoaru 2241 (f 2)
evaluateBoaru 2221 (f 3)
evaluateBoaru 2281 (f 2)
evaluateBoaru 2282 (f 3)
lteration for 2281
evaluateBoaru 4281 (f 1)
80 Art|c|a| lnte|||gence
evaluateBoaru 4181 (f 1)
evaluateBoaru 4481 (f 3)
evaluateBoaru 4281 (f 1)
evaluateBoaru 4241 (f 3)
evaluateBoaru 4282 (f 2)
lteration for 4281
evaluateBoaru 8281 (f 2)
evaluateBoaru 8181 (f 3)
evaluateBoaru 8481 (f 4)
evaluateBoaru 8241 (f 2)
evaluateBoaru 8221 (f 3)
evaluateBoaru 8281 (f 2)
evaluateBoaru 8282 (f 2)
lteration for 8282
evaluateBoaru 4282 (f 2)
evaluateBoaru 2282 (f 3)
evaluateBoaru 4182 (f u)
evaluateBoaru 4482 (f 2)
evaluateBoaru 4282 (f 2)
evaluateBoaru 4142 (f 2)
evaluateBoaru 4181 (f 1)
evaluateBoaru 4184 (f 3)
solution is ux4182
u 1 u u
u u u 1
1 u u u
u u 1 u
!abu Searcb Var|ants
n orocr to makc Talu scarch morc cllcctivc lor vcry oillcult scarch prollcms,
a numlcr ol mooilcations cxist. Thc lrst ol thcsc is callco |n/ns|c/|n ano
csscntially intcnsilcs thc scarch arouno a givcn point (such as thc lcst knovn
solution;. Thc ioca is that vc takc a promising nooc, ano intcnsily thc scarch
arouno this point. This is implcmcntco using an intcrmcoiatc mcmory, vhich
contains thc ncighlor noocs to oig into lurthcr.
Onc issuc that comcs up in local scarch algorithms is that thcy can gct
stuck in local optimums. Talu scarch introouccs thc conccpt ol d|crs|c/|n
to allov thc algorithm to scarch noocs that havc lccn prcviously uncxplorco
to cxpano thc spacc ol scarch.
lnjormed 5earch 81
Whcn vc lollov thc lcst solutions, it`s vcry possillc to gct stuck in
local optimums lor oillcult prollcms. Anothcr intcrcsting variant is callco
ns/rc|n/ r|c\c/|n, vhich rclaxcs thc ncighlorhooo sclcction algorithm to
acccpt lovcr quality noocs in thc scarch spacc. This pcrmits thc algorithm to
cxpano its scarch to ocsccno into lovcr quality solutions in scarch ol highcr
quality solutions. |Ccnorcau 2002]
n many scarch prollcms, vc`rc intcrcstco not just in thc goal, lut hov vc
got lrom thc initial statc to thc goal statc (takc lor cxamplc, thc cight puzzlc;.
As vc`ll lcarn latcr, planning systcms rcly on this aspcct ol scarch as a plan
is nothing morc than a scqucncc ol stcps to gct lrom a givcn statc to a goal
statc. For somc prollcms, vc`rc not intcrcstco in thc path to thc goal, lut
instcao just thc goal statc (lor cxamplc, thc N-Quccns prollcm;. Frollcms
ol this typc arc callco Constraint Satislaction Frollcms (CSF;.
Formally, vc can think alout CSF in tcrms ol a sct ol ccr|c||s vith a
dmc|n ol possillc valucs, ano a sct ol ns/rc|n/s that spccily thc allovallc
comlinations ol variallc valucs. Consiocr thc lolloving simplc cxamplc. Wc
vish to lno valucs lor thc sct ol variallcs \ ano q cach having a oomain ol
1-0], such that Fq 3.4 (thc constraint; is satislco.
\ + q = \ * q (Fq 3.4;
Without much vork, vc knov that assigning thc valuc ol tvo lor loth \
ano q satislcs thc constraint oclnco ly thc cquation.
Grapb Co|or|ng as a CS
Onc ol thc morc popular CSFs is callco Craph Coloring. Civcn a graph,
ano a sct ol colors, thc prollcm is to color thc noocs such that an cogc oocs
not oircctly conncct to a nooc ol thc samc color. Consiocr thc map shovn
in Figurc 3.15. Wc can scc a sct ol oljccts that arc aojaccnt to onc anothcr.
Oljcct A is aojaccnt to oljccts B ano C, vhilc oljcct D is aojaccnt only to
oljcct B. Thc graph portion ol Figurc 3.14 illustratcs thc graph ol thc map.
From this graph, vc can scc cogcs vhich oclnc thc aojaccncy ol thc oljccts
(noocs; ol thc graph.
Nov consiocr thc prollcm ol coloring thc map givcn thc constraints that
cach oljcct can lc onc color ano no colorco oljccts shoulo lc aojaccnt to onc
anothcr. Can thc graph lc colorco using thrcc colors (rco, grccn, ano lluc;?
82 Art|c|a| lnte|||gence
Using trial ano crror, vc can vcry casily color this simplc graph ly
itcrating through thc noocs ol thc graph ano assigning a color so that our
constraint rcmains satislco. ct`s start vith nooc A, color it, ano thcn stcp to
cach rcmaining nooc, coloring as vc go. n isting 3.17, vc scc thc coloring
proccss. Fach nooc is lollovco ly a constraint, vith thc color lnally choscn
in parcnthcscs.
Nooc A - Fick any color (Bco;
Nooc B - Fick a color othcr than Bco (Bluc;
Nooc C - Fick a color othcr than Bco ano Bluc (Crccn;
Nooc D - Fick a color othcr than Bluc (Bco;
Nooc F - Fick a color othcr than Crccn (Bco;
Nooc F - Fick a color othcr than Crccn or Bco (Bluc;
Nooc C - Fick a color othcr than Bco or Bluc (Crccn;
LiS!iNG 3.17: Grapb co|or|ng tbrougb tr|a| and error.
Through a simplc proccss ol climination, vc`vc lccn allc to color thc graph
using thc constraints ol prcviously colorco noocs to octcrminc thc color to
paint aojaccnt noocs (lnal rcsult shovn in Figurc 3.17;.
llGURL 3.13: !be c|ass|ca| grapb co|or|ng CS.
lnjormed 5earch 83

T/ jcmas Far C|r T/rm ,/ prc //c/ n|q jar |rs cr

rqa|rd / |r cnq p|cncr mcp) dc/s |c| / // m|d 1800s. T/r
r namras jc||d c//mp/s / prc // //rm cnd |/ rmc|nd
n/ar an/|| 1976, /n App| cnd Hc|n rc/d c jrmc| prj.
Scbedu||ng as a CS
Onc ol thc most practical applications ol constraint satislaction is to thc prollcm
ol schcouling. Numcrous typcs ol schcouling prollcms cxist, lrom airlinc
timctallcs to thc schcouling ol manulacturing proccsscs. Thc schcouling
prollcm comcs oovn to allocating rsars to c/|c|/|s in /|m prcscrving a
sct ol constraints. For cxamplc, in a manulacturing prollcm, a rcsourcc can
lc proccssco through a varicty ol activitics cach rcquiring a spccilc amount
ol timc. n aooition, activitics havc prcccocncc that must lc maintainco (a
rcsourcc must lc proccssco ly Activity A lclorc Activity B;. Thc goal ol thc
CSF in this prollcm is to iocntily an optimal schcoulc ol rcsourccs through thc
activitics such that thc cno proouct can lc optimally prooucco.
llGURL 3.16: Resu|t of Grapb Co|or|ng from L|st|ng 3.17.
84 Art|c|a| lnte|||gence
A largc numlcr ol algorithms cxist to solvc CSFs lrom thc simplc Gnrc/
cnd Ts/ algorithm to constraint-propagation ano consistcncy. Wc`ll cxplorc
a lcv ol thc availallc algorithms that can lc usco. Notc that somc ol thc
algorithms vc`vc oiscussco thus lar (such as ocpth-lrst scarch invcstigatco
in Chaptcr 2, ano simulatco anncaling ano Talu scarch lrom Chaptcr 3; can
lc usco cllcctivcly to solvc CSFs.
Generate and !est
Gnrc/ cnd Ts/ is thc simplcst ol thc algorithms to iocntily a solution lor
a CSF. n this algorithm, cach ol thc possillc solutions is attcmptco (cach
valuc cnumcratco lor cach variallc; ano thcn tcstco lor thc solution. Sincc
tcsting cach comlination ol variallc vithin thc oomain ol cach valuc can
lc cxtrcmcly slov ano incllcicnt, hcuristics can lc applico to avoio thosc
comlinations that arc outsioc ol thc solution spacc.
Thc |c|/rc||ng algorithm opcratcs vith a simplc uninlormco scarch
algorithm, such as ocpth-lrst scarch. At cach nooc, a variallc is instantiatco
vith a valuc ano thc constraint violations arc chcckco. l thc valucs arc lcgal,
scarch is pcrmittco to continuc, othcrvisc, thc currcnt lranch is alanoonco
ano thc ncxt nooc lrom thc OFFN list is cvaluatco.
To incrcasc thc cllcicncy ol thc lacktracking algorithm, thc ms/
ns/rc|nd ccr|c|| is instantiatco lrst. Takc lor cxamplc, nooc C lrom
Figurc 3.14. n this casc, thc nooc has lour ncighlors (thc most ol any nooc
in thc graph;.

B// Gnrc/ cnd Ts/ cnd |c|/rc||ng cr mmn sqs/mc/| scr/

c|gr|//ms, cs //q sqs/mc/|c||q css|gn cc|as / ccr|c||s |n scr/ j
c s|a/|n. Gnrc/ cnd Ts/ |s /|g/|q |nj|n/, /|| |c|/rc||ng
sajjrs jrm /rcs/|ng, r // rpc/d jc||ar / nd c s|a/|n jr //
scm rcsn ,jr \cmp|, c s|ng| ccr|c|| rmc|n|ng ns/cn/).
iorward Cbeck|ng and Look Abead
Frcrd /||ng is similar to lacktracking, cxccpt that vhcn a particular
nooc is cvaluatco lor thc currcnt variallc (callco arc consistcncy;, only thosc
valio noocs arc consiocrco lor thc OFFN list to cvaluatc in thc luturc. Noocs
that can lc octcctco as invalio arc immcoiatcly ignorco, rcsulting only in thc
lnjormed 5earch 85
most promising lranchcs lor lurthcr scarch. This can minimizc a numlcr ol
noocs gcncratco lor scarch, lut tcnos to involvc morc vork vhcn cvaluating
a singlc nooc (lor lorvaro chccking ol constraints;.
A variation on lorvaro chccking is callco || c/cd. n this algorithm,
instcao ol simply cvaluating chilo noocs lasco on thc currcntly instantiatco
valuc, all sulscqucnt to lc instantiatco variallcs arc instantiatco givcn thc
currcntly instantiatco valucs. This rcsults in vcry nat scarch trccs. (Scc
Figurc 3.17 lor a graphical vicv ol lacktracking, lorvaro chccking, ano
look ahcao.;

Frcrd /||ng |s mmn|q mr jj/|c //cn |c|/rc||ng cs //

nam|r j nds / | cc|ac/d |s rdad.
llGURL 3.17: Compar|son of backtrack|ng, forward cbeck|ng, and |ook abead constra|nt
propagat|on a|gor|tbms.
86 Art|c|a| lnte|||gence
M|n-Con|cts Searcb
An intcrcsting /ar|s/| rpc|r algorithm is thc Min-Connicts hcuristic. This
algorithm lcgins ly choosing thc variallc that violatcs thc lcvcst numlcr
ol constraints ano thcn systcmatically improvcs thc solution through using
an algorithm such as hill climling or A vith thc hcuristic lunction
oclnco as thc total numlcr ol constraints violatco.
nlormco scarch mcthoos, unlikc thc uninlormco (or llino; mcthoos, usc a
hcuristic to octcrminc thc quality ol any statc in thc scarch spacc. This allovs
thc algorithm to guioc thc scarch ano choosc thc ncxt nooc to cxpano. n
this chaptcr, a numlcr ol inlormco scarch mcthoos vcrc cxplorco, incluoing
lcst-lrst scarch, A scarch, hill-climling scarch, simulatco anncaling, Talu
scarch, ano lnally algorithms lor constraint satislaction. Unocrstanoing thc
inlormco mcthoos ol scarch is important lccausc much ol prollcm solving
in A can lc rclnco to scarch mcthoos. Thc kcy is choosing thc algorithm
that is lcst suitco to thc particular prollcm at hano.
!ab|e 3.1: Summary of tbe un|nformed a|gor|tbms and tbe|r cbaracter|st|cs.
Algoritbm Timc Spacc Optimal Complctc crivativc
Bcst-First Scarch O(lm; O(lm; No Ycs BFS/UCS
A Scarch O(2
; O(l
; Ycs Ycs BcstFS
DA O(2
; O(o; Ycs Ycs A
SimAnncal - - No No
Talu - - No No
|, lranching lactor
d, trcc ocpth ol thc solution
m, trcc ocpth
|Archcr 1000] Archcr, A.F. A Moocrn Trcatmcnt ol thc 15 Fuzzlc,
Amr|cn Mc//. Monthly 106, 703-700, 1000.
lnjormed 5earch 87
|KCong 2005] Cong, Kcvin. A Mathcmatical Analysis ol thc Sixtccn Fuzzlc.
ast upoatco 12/2005.
Availallc onlinc at
|Ccnorcau 2002] Ccnorcau, Michcl. An ntroouction to Talu Scarch,
Univcrsitc oc Montrcal. ]uly 2002. Availallc onlinc at
|Clovcr 1000] Clovcr, Frco. Talu Scarch: A Tutorial, ntcrlaccs, 20 (4;:
74-04, 1000.
1. Bcst-lrst scarch uscs a comlinco hcuristic to choosc thc lcst path to
lollov in thc statc spacc. Dclnc thc tvo hcuristics usco (h(n; ano g(n;;.
2. Bcst-lrst scarch uscs loth an OFFN list ano a COSFD list. Dcscrilc
thc purposc ol cach lor thc lcst-lrst algorithm.
3. Dcscrilc thc oillcrcnccs lctvccn lcst-lrst scarch ano grccoy lcst-lrst
4. Dcscrilc thc oillcrcnccs lctvccn lcst-lrst scarch ano lcam scarch.
5. What arc thc aovantagcs ol lcam scarch ovcr lcst-lrst scarch?
6. A scarch uscs a comlinco hcurstic to sclcct thc lcst path to lollov
through thc statc spacc tovaro thc goal. Dclnc thc tvo hcuristics usco
(h(n; ano g(n;;.
7. Briclly ocscrilc A scarch ano thc prollcms to vhich it can lc
S. What is mcant ly an aomissillc hcuristic?
0. Hov oo thc alpha ano lcta paramctcrs tunc thc hcuristics lor A
10. Bricny cxplain thc oillcrcncc lctvccn A scarch ano SMA. What
aovantagc oocs SMA havc ovcr A?
11. Hill climling is a stanoaro itcrativc improvcmcnt algorithm similar
to grccoy lcst-lrst scarch. What arc thc primary prollcms vith hill
12. Dcscrilc Simulatco anncaling ano il it comlincs itcrativc improvcmcnt
vith stochastic scarch.
13. Dcscrilc thc algorithm ano hov it oillcrs lrom ranoom scarch.
88 Art|c|a| lnte|||gence
14. What is thc purposc ol thc Montc Carlo stcp in thc simulatco anncaling
15. Bricny ocscrilc thc Talu scarch algorithm.
16. Thc Talu list can lc sizco lor thc prollcm at hano. What cllcct oocs
changing thc sizc ol thc Talu list havc on thc scarch algorithm?
17. Dcscrilc thc intcnsilcation ano oivcrsilcation mooilcations ol Talu
1S. Dcscrilc thc csscncc ol a constraint satislaction prollcm.
10. What arc somc ol thc major applications ol constraint satislaction
20. Comparc ano contrast thc CSF algorithms ol lacktracking, lorvaro
chccking, ano look ahcao.