Sing: Dtministi singl-gnt Anw W. Moo Posso Sool o Comut Sin Cngi Mllon Univsity www.s.mu.u/~wm wm@s.mu.u -68-7 ot to ot ts n uss o ts slis. Anw woul ligt i you oun tis sou mtil usul in giving you own ltus. Fl to us ts slis vtim, o to moiy tm to it you own ns. PowPoint oiginls vill. I you mk us o signiint otion o ts slis in you own ltu, ls inlu tis mssg, o t ollowing link to t sou ositoy o Anw s tutoils: tt://www.s.mu.u/~wm/tutoils. Commnts n otions gtully iv. Sli Ovviw Dtministi, singl-gnt, s olms Bt Fist S Otimlity, Comltnss, Tim n S omlxity S Ts Dt Fist S Ittiv Dning Bst Fist Gy S Sli
A s olm How o w gt om S to G? An wt s t smllst ossil num o tnsitions? Sli Fomlizing s olm A s olm s iv omonnts: Q, S, G, sus, ost Q is init st o stts. S Q is non-mty st o stt stts. G Q is non-mty st o gol stts. sus : Q P(Q) is untion wi tks stt s inut n tuns st o stts s outut. sus(s) mns t st o stts you n om s in on st. ost : Q, Q Positiv um is untion wi tks two stts, s n s, s inut. It tuns t on-st ost o tvling om s to s. T ost untion is only in wn s is susso stt o s. Sli
Ou S Polm Q = {,,,,,,,,,,, } S = { } G = { } sus() = { } sus() = {, } sus() = ULL t. ost(s,s ) = o ll tnsitions Sli Ou S Polm Q = {,,,,,,,,,,, } S = { } G = { } sus() = { } sus() = {, } sus() = ULL t. ost(s,s ) = o ll tnsitions Wy o w? Wt olms lik tis? Sli 6
S Polms Sli 7 Mo S Polms Suling 8-Quns Wt nxt? Sli 8
Mo S Polms But t lnty o tings wi w nomlly ll s olms tt on t it ou Suling igi inition A s olm s iv omonnts: Q, S, G, sus, ost 8-Quns Q is init st o stts. S Q is non-mty st o stt stts. G Q is non-mty st o gol stts. sus : Q P(Q) is untion wi tks stt s inut n tuns st o stts s outut. sus(s) mns t st o stts you n om s in on st. ost : Q, Q Positiv um is untion wi tks two stts, s n s, s inut. It tuns t on-st ost o tvling om Wt snxt? to s. T ost untion is only in wn s is susso stt o s. Cn you tink o xmls? Sli Ou inition xlus Sli 0
Gm ginst vsy Ou inition xlus Cn Hin Stt Continuum (ininit num) o stts All o t ov, lus istiut tm ontol Sli Bt Fist S Ll ll stts tt l om S in st ut n t l in lss tn st. Tn ll ll stts tt l om S in sts ut n t l in lss tn sts. Tn ll ll stts tt l om S in sts ut n t l in lss tn sts. Et until Gol stt. Sli 6
Bt-ist S 0 sts om stt Sli st om stt Bt-ist S 0 sts om stt Sli 7
st om stt Bt-ist S 0 sts om stt sts om stt Sli st om stt Bt-ist S 0 sts om stt sts om stt sts om stt Sli 6 8
st om stt Bt-ist S sts om stt 0 sts om stt sts om stt sts om stt Sli 7 Rmm t t! Also, wn you ll stt, o t sso stt. Tis o is ll koint. T istoy o ssos is us to gnt t solution t, on you v oun t gol: I v got to t gol. I s I ws t o tis. An I ws t o I ws t. An I ws. so solution t is S G Sli 8
st om stt Bkoints sts om stt 0 sts om stt sts om stt sts om stt Sli st om stt Bkoints sts om stt 0 sts om stt sts om stt sts om stt Sli 0 0
Stting Bt Fist S Fo ny stt s tt w v ll, w ll mm: vious(s) s t vious stt on sotst t om stt to s. On t kt ittion o t lgoitm w ll gin wit V k in s t st o tos stts o wi t sotst t om t stt osts xtly k sts Tn, uing tt ittion, w ll omut V k+, in s t st o tos stts o wi t sotst t om t stt osts xtly k+ sts W gin wit k = 0, V 0 = {} n w ll in, vious() = ULL Tn w ll in tings on st om t into V. An w ll k going. Sli V 0 Sli
V 0 V Sli V 0 V V Sli
V V 0 V V Sli V V V 0 V V Sli 6
Bt Fist S V 0 := S (t st o stt stts) vious() := IL k := 0 wil (no gol stt is in V k n V k is not mty) o V k+ := mty st Fo stt s in V k Fo stt s in sus(s) I s s not ly n ll St vious(s ) := s A s into V k+ k := k+ I V k is mty signl FAILURE Els uil t solution t tus: Lt S i t it stt in t sotst t. Din S k =, n oll i <= k, in S i- = vious(s i ). Sli 7 V V 0 Suos you s s onvnintly llow you to otin ssos(stt). Cn you tink o int wy to o? An woul you l to voi stoing somting tt w viously to sto? V V V Sli 8
Anot wy: Wok k Ll ll stts tt n G in st ut n t it in lss tn st. Ll ll stts tt n G in sts ut n t it in lss tn sts. Et. until stt is. num o sts to gol lls tmin t sotst t. Don t n xt ookking ino. Sli Bt Fist Dtils It is in o t to mo tn on gol stt. It is in o t to mo tn on stt stt. Tis lgoitm woks ows om t stt. Any lgoitm wi woks ows om t stt is si to ow ining. ou n lso wok kws om t gol. Tis lgoitm is vy simil to Dijkst s lgoitm. Any lgoitm wi woks kws om t gol is si to kw ining. Bkw vsus ow. Wi is tt? Sli 0
Costs on tnsitions 8 oti tt ins t sotst t in tms o num o tnsitions. It os not in t lst-ost t. W will uikly viw n lgoitm wi os in t lst-ost t. On t kt ittion, o ny stt S, wit g(s) s t lst-ost t to S in k o w sts. Sli Lst Cost Bt Fist V k = t st o stts wi n in xtly k sts, n o wi t lstost k-st t is lss ost tn ny t o lngt lss tn k. In ot wos, V k = t st o stts wos vlus ng on t vious ittion. V 0 := S (t st o stt stts) vious() := IL g() = 0 k := 0 wil (V k is not mty) o V k+ := mty st Fo stt s in V k Fo stt s in sus(s) I s s not ly n ll OR i g(s) + Cost(s,s ) < g(s ) St vious(s ) := s St g(s ) := g(s) + Cost(s,s ) A s into V k+ k := k+ I not ll, xit signling FAILURE Els uil t solution t tus: Lt S k t kt stt in t sotst t. Din S k =, n oll i <= k, in S i- = vious(s i ). Sli 6
Uniom-Cost S A ontully siml o wn t osts on tnsitions It uss ioity uus Sli Pioity Quu Rs A ioity uu is t stutu in wi you n inst n tiv (ting, vlu) is wit t ollowing otions: Init-PiQuu(PQ) Inst-PiQuu(PQ, ting, vlu) Po-lst(PQ) initilizs t PQ to mty. insts (ting, vlu) into t uu. tuns t (ting, vlu) i wit t lowst vlu, n movs it om t uu. Sli 7
Pioity Quu Rs A ioity uu is t stutu in wi you n inst n tiv (ting, vlu) is wit t ollowing otions: Fo mo tils, s Knut o Sgwik o silly ny ook wit t wo lgoitms ominntly ing in t titl. Init-PiQuu(PQ) Inst-PiQuu(PQ, ting, vlu) Po-lst(PQ) initilizs t PQ to mty. insts (ting, vlu) into t uu. tuns t (ting, vlu) i wit t lowst vlu, n movs it om t uu. Pioity Quus n imlmnt in su wy tt t ost o t inst n o otions O(log(num o tings in ioity uu)) Vy (toug not solutly, inily!) Sli Uniom-Cost S A ontully siml o wn t osts on tnsitions It uss ioity uu PQ = St o stts tt v n xn o witing xnsion Pioity o stt s = g(s) = ost o gtting to s using t imli y koints. Sli 6 8
Stting UCS 8 PQ = { (S,0) } Sli 7 UCS Ittions PQ = { (S,0) } 8 Ittion:. Po lst-ost stt om PQ. A sussos Sli 8
UCS Ittions 8 PQ = { (,), (,), (,) } Ittion:. Po lst-ost stt om PQ. A sussos Sli UCS Ittions PQ = { (,), (,), (,6) } 8 Ittion:. Po lst-ost stt om PQ. A sussos Sli 0 0
UCS Ittions 8 PQ = { (,), (,), (,), (,6) } Ittion:. Po lst-ost stt om PQ. A sussos Sli UCS Ittions PQ = { (,), (,), (,), (,6) } 8 ot wt n : liz tt gtting to vi ws tt tn t viously st-known wy to gt to Ittion:. Po lst-ost stt om PQ. A sussos Sli n so s ioity ws ng
UCS Ittions 8 PQ = { (,), (,6), (,), (,6) } Ittion:. Po lst-ost stt om PQ. A sussos Sli UCS Ittions PQ = { (,6),(,6),(,),(,),(,6) } 8 Ittion:. Po lst-ost stt om PQ. A sussos Sli
UCS Ittions 8 PQ = { (,6),(,),(,),(,6) } Ittion:. Po lst-ost stt om PQ. A sussos Sli UCS Ittions PQ = { (,0), (,),(,) } 8 Ittion:. Po lst-ost stt om PQ. A sussos Sli 6
UCS Ittions ot wt n : oun nw wy to gt to PQ = { (,0), (,),(,) } ut it ws mo ostly tn t st known wy n so s ioity ws unng 8 Ittion:. Po lst-ost stt om PQ. A sussos Sli 7 UCS Ittions PQ = { (,),(,) } 8 Ittion:. Po lst-ost stt om PQ. A sussos Sli 8
UCS Ittions PQ = { (,) } 8 Ittion:. Po lst-ost stt om PQ. A sussos Sli UCS Ittions PQ = { (,8) } 8 Ittion:. Po lst-ost stt om PQ. A sussos Sli 0
UCS Ittions PQ = { (G,) } 8 Ittion:. Po lst-ost stt om PQ. A sussos Sli UCS Ittions Qustion: Is tmint s soon s you isov t gol t igt stoing ition? PQ = { (G,) } 8 Ittion:. Po lst-ost stt om PQ. A sussos Sli 6
UCS tmints PQ = { } 8 Tmint only on t gol is o om t ioity uu. Els w my miss sot t. Ittion:. Po lst-ost stt om PQ. A sussos Sli Juging s lgoitm Comltnss: is t lgoitm gunt to in solution i solution xists? Gunt to in otiml? (will it in t lst ost t?) Algoitmi tim omlxity S omlxity (mmoy us) Vils: B L num o stts in t olm t vg ning to (t vg num o sussos) (B>) t lngt o t t om stt to gol wit t sotst num o sts How woul w jug ou lgoitms? Sli 7
Juging s lgoitm B L Q num o stts in t olm t vg ning to (t vg num o sussos) (B>) t lngt o t t om stt to gol wit t sotst num o sts t vg siz o t ioity uu Algoitm LC Lst Cost UCS Bt Fist S Uniom Cost S Com Otiml Tim lt i ll tnsitions sm ost O(log(Q) * min(,b L )) S Sli Juging s lgoitm B L Q num o stts in t olm t vg ning to (t vg num o sussos) (B>) t lngt o t t om stt to gol wit t sotst num o sts t vg siz o t ioity uu Algoitm UCS Bt Fist S LC Lst Cost Uniom Cost S Com Otiml Tim lt i ll tnsitions sm ost O(log(Q) * min(,b L )) S Sli 6 8
S T Rsnttion Wt o o w go toug t s t wit? Sli 7 Dt Fist S 8 An ltntiv to. Alwys xn om t mostntly-xn no, i it s ny unti sussos. Els ku to t vious no on t unt t. Sli 8
DFS in tion Sli DFS S t tvsl Cn you w in t o in wi t s-t nos visit? Sli 60 0
DFS Algoitm W us t stutu w ll ll Pt to snt t,, t om t to t unt stt. E.G. Pt P = <,,, > Along wit no on t t, w must mm wi sussos w still v vill to xn. E.G. t t ollowing oint, w ll v P = < (xn=, ), (xn = ULL), (xn = ), (xn = ) > Sli 6 DFS Algoitm Lt P = < (xn = sus())> Wil (P not mty n to(p) not gol) i xn o to(p) is mty tn mov to(p) ( o t stk ) ls lt s mm o xn o to(p) mov s om xn o to(p) mk nw itm on t to o t P: s (xn = sus(s)) I P is mty tun FAILURE Els tun t t onsisting o stts in P Tis lgoitm n wittn ntly wit usion, i.. using t ogm stk to imlmnt P. Sli 6
Juging s lgoitm B L Q num o stts in t olm t vg ning to (t vg num o sussos) (B>) t lngt o t t om stt to gol wit t sotst num o sts t vg siz o t ioity uu Algoitm UCS DFS Bt Fist S LC Lst Cost Uniom Cost S Dt Fist S Com Otiml Tim lt i ll tnsitions sm ost O(log(Q) * min(,b L )) /A S /A Sli 6 Juging s lgoitm B L Q num o stts in t olm t vg ning to (t vg num o sussos) (B>) t lngt o t t om stt to gol wit t sotst num o sts t vg siz o t ioity uu Algoitm UCS DFS Bt Fist S LC Lst Cost Uniom Cost S Dt Fist S Com Otiml Tim lt i ll tnsitions sm ost O(log(Q) * min(,b L )) /A S /A Sli 6
Juging s lgoitm B L LMAX Q num o stts in t olm t vg ning to (t vg num o sussos) (B>) t lngt o t t om stt to gol wit t sotst num o sts Lngt o longst t om stt to nyw t vg siz o t ioity uu Algoitm UCS DFS** Bt Fist S LC Lst Cost Uniom Cost S Dt Fist S Com Otiml Tim lt i ll tnsitions sm ost Assuming Ayli S S O(log(Q) * min(,b L )) O(B LMAX ) S O(LMAX) Sli 6 Juging s lgoitm B L LMAX Q num o stts in t olm t vg ning to (t vg num o sussos) (B>) t lngt o t t om stt to gol wit t sotst num o sts Lngt o longst t om stt to nyw t vg siz o t ioity uu Algoitm UCS DFS** Bt Fist S LC Lst Cost Uniom Cost S Dt Fist S Com Otiml Tim lt i ll tnsitions sm ost Assuming Ayli S S O(log(Q) * min(,b L )) O(B LMAX ) S O(LMAX) Sli 66
Qustions to on How woul you vnt DFS om looing? How oul you o it to giv n otiml solution? Sli 67 Qustions to on How woul you vnt DFS om looing? How oul you o it to giv n otiml solution? Answ : PC-DFS (Pt Cking DFS): Don t us on stt i tt stt is ly in t unt t Answ : MEMDFS (Mmoizing DFS): Rmm ll stts xn so. v xn nyting twi. Sli 68
Qustions to on How woul you vnt DFS om looing? How oul you o it to giv n otiml solution? Answ : PC-DFS (Pt Cking DFS): Don t us on stt i tt stt is ly in t unt t Answ : MEMDFS (Mmoizing DFS): Rmm ll stts xn so. v xn nyting twi. Sli 6 Qustions to on How woul you vnt DFS om looing? A t osions wn PCDFS is tt tn MEMDFS? How oul you o it to giv n otiml solution? A t osions wn MEMDFS is tt tn PCDFS? Answ : PC-DFS (Pt Cking DFS): Don t us on stt i tt stt is ly in t unt t Answ : MEMDFS (Mmoizing DFS): Rmm ll stts xn so. v xn nyting twi. Sli 70
Juging s lgoitm B L LMAX Q num o stts in t olm t vg ning to (t vg num o sussos) (B>) t lngt o t t om stt to gol wit t sotst num o sts Lngt o longst yl- t om stt to nyw t vg siz o t ioity uu Algoitm UCS Bt Fist S LC Lst Cost Uniom Cost S PCDFS Pt Ck DFS MEMDFS Mmoizing DFS Com Otiml Tim lt i ll tnsitions sm ost O(log(Q) * min(,b L )) O(B LMAX ) O(min(,B LMAX )) S O(LMAX) O(min(,B LMAX )) Sli 7 Juging s lgoitm B L LMAX Q num o stts in t olm t vg ning to (t vg num o sussos) (B>) t lngt o t t om stt to gol wit t sotst num o sts Lngt o longst yl- t om stt to nyw t vg siz o t ioity uu Algoitm UCS Bt Fist S LC Lst Cost Uniom Cost S PCDFS Pt Ck DFS MEMDFS Mmoizing DFS Com Otiml Tim lt i ll tnsitions sm ost O(log(Q) * min(,b L )) O(B LMAX ) O(min(,B LMAX )) S O(LMAX) O(min(,B LMAX )) Sli 7 6
Juging s lgoitm B L LMAX Q num o stts in t olm t vg ning to (t vg num o sussos) (B>) t lngt o t t om stt to gol wit t sotst num o sts Lngt o longst yl- t om stt to nyw t vg siz o t ioity uu Algoitm UCS Bt Fist S LC Lst Cost Uniom Cost S PCDFS Pt Ck DFS MEMDFS Mmoizing DFS Com Otiml Tim lt i ll tnsitions sm ost O(log(Q) * min(,b L )) O(B LMAX ) O(min(,B LMAX )) S O(LMAX) O(min(,B LMAX )) Sli 7 Mz xml Imgin stts lls in mz, you n mov, E, S, W. Wt woul lin DFS o, ssuming it lwys xn t E susso ist, tn, tn W, tn S? G Exnsion o E,, W, S S Ot ustions: Wt woul o? Wt woul PCDFS o? Wt woul MEMDFS o? Sli 7 7
Two ot DFS xmls G O:, E, S, W? S G O:, E, S, W wit loos vnt S Sli 7 Fow DFS o Bkw DFS I you v ssos() untion s wll s sussos() untion you n gin t t gol n t-ist-s kws until you it stt. Wy/Wn migt tis goo i? Sli 76 8
Invnt An Algoitm Tim! H s wy to mtilly s osts somtims. Biitionl S. Cn you guss wt tis lgoitm is, n wy it n ug ost-sv? Sli 77 B L LMAX Q num o stts in t olm t vg ning to (t vg num o sussos) (B>) t lngt o t t om stt to gol wit t sotst num o sts Lngt o longst yl- t om stt to nyw t vg siz o t ioity uu Algoitm UCS MEMDFS Mmoizing DFS BI Bt Fist S LC Lst Cost Uniom Cost S PCDFS Pt Ck DFS Biition BF S Com Otiml Tim lt i ll tnsitions sm ost O(log(Q) * min(,b L )) O(B LMAX ) O(min(,B LMAX )) O(min(,B L/ )) S O(LMAX) O(min(,B LMAX )) O(min(,B L/ )) Sli 78
B L LMAX Q num o stts in t olm t vg ning to (t vg num o sussos) (B>) t lngt o t t om stt to gol wit t sotst num o sts Lngt o longst yl- t om stt to nyw t vg siz o t ioity uu Algoitm UCS Bt Fist S LC Lst Cost Uniom Cost S PCDFS Pt Ck DFS MEMDFS Mmoizing DFS BI Biition BF S Com Otiml Tim lt i ll tnsitions sm ost All tns sm ost O(log(Q) * min(,b L )) O(B LMAX ) O(min(,B LMAX )) O(min(,B L/ )) S O(LMAX) O(min(,B LMAX )) O(min(,B L/ )) Sli 7 Ittiv Dning Ittiv ning is siml lgoitm wi uss DFS s suoutin:. Do DFS wi only ss o ts o lngt o lss. (DFS givs u ny t o lngt ). I il, o DFS wi only ss ts o lngt o lss.. I il, o DFS wi only ss ts o lngt o lss..n so on until suss Cost is O( + + + + L ) = O( L ) Cn mu tt tn gul DFS. But ost n mu gt tn t num o stts. Sli 80 0
Mz xml Imgin stts lls in mz, you n mov, E, S, W. Wt woul Ittiv Dning o, ssuming it lwys xn t E susso ist, tn, tn W, tn S? G S Exnsion o E,, W, S Sli 8 B L LMAX Q num o stts in t olm t vg ning to (t vg num o sussos) (B>) t lngt o t t om stt to gol wit t sotst num o sts Lngt o longst yl- t om stt to nyw t vg siz o t ioity uu Algoitm UCS Bt Fist S LC Lst Cost Uniom Cost S PCDFS Pt Ck DFS MEMDFS Mmoizing DFS BI Biition BF S Ittiv ID Dning Com Otiml Tim lt i ll tnsitions sm ost All tns sm ost i ll tnsitions sm ost O(log(Q) * min(,b L )) O(B LMAX ) O(min(,B LMAX )) O(min(,B L/ )) O(B L ) S O(LMAX) O(min(,B LMAX )) O(min(,B L/ )) O(L) Sli 8
B L LMAX Q num o stts in t olm t vg ning to (t vg num o sussos) (B>) t lngt o t t om stt to gol wit t sotst num o sts Lngt o longst yl- t om stt to nyw t vg siz o t ioity uu Algoitm UCS Bt Fist S LC Lst Cost Uniom Cost S PCDFS Pt Ck DFS MEMDFS Mmoizing DFS BI Biition BF S Ittiv ID Dning Com Otiml Tim lt i ll tnsitions sm ost All tns sm ost i ll tnsitions sm ost O(log(Q) * min(,b L )) O(B LMAX ) O(min(,B LMAX )) O(min(,B L/ )) O(B L ) S O(LMAX) O(min(,B LMAX )) O(min(,B L/ )) O(L) Sli 8 Bst Fist Gy S s uisti. A uisti untion ms stt onto n stimt o t ost to t gol om tt stt. Cn you tink o xmls o uistis? E.G. o t 8-uzzl? E.G. o lnning t toug mz? Dnot t uisti y untion (s) om stts to ost vlu. Sli 8
Huisti S Suos in ition to t stn s siition w lso v uisti. A uisti untion ms stt onto n stimt o t ost to t gol om tt stt. Cn you tink o xmls o uistis? E.G. o t 8-uzzl? E.G. o lnning t toug mz? Dnot t uisti y untion (s) om stts to ost vlu. Sli 8 Euliin Huisti = = =8 8 = = =8 = =6 = =0 = =6 Sli 86
Euliin Huisti = = =8 =8 8 = = Anot ioity uu lgoitm. But tis tim, ioity is t uisti vlu. = = =6 =6 =0 = Sli 87 Bst Fist Gy S Init-PiQuu(PQ) Inst-PiQuu(PQ,,()) wil (PQ is not mty n PQ os not ontin gol stt) (s, ) := Po-lst(PQ) o s in sus(s) i s is not ly in PQ n s nv viously n visit Inst-PiQuu(PQ,s,(s )) Algoitm BstFS Bst Fist S Com Otiml Tim lt O(min(,B LMAX )) S O(min(,B LMAX )) A w imovmnts to tis lgoitm n mk tings mu tt. It s littl ting w lik to ll: A*. to ontinu! Sli 88
Wt you soul know Tooug unstning o, LC, UCS. PCDFS, MEMDFS Unstn t onts o wt s is omlt, otiml, its tim n s omlxity Unstn t is in ittiv ning n iitionl s B l to isuss t oktil tis t os n ons o t ov ss Sli 8