3. Ongelmanratkonta haun avulla Eero Hyvönen Helsingin yliopisto
Haku Tavoiteperustaisilla agenteilla Tavoitteen (goal( goal) ) saavuttaminen Ongelman muotoilu (sopivalla yleisyystasolla) Esim. maailma on joukko tiloja uto eri kaupungeissa Toimenpiteillä voidaan siirtyä tilasta toiseen jetaan kaupungista toiseen Tavoitteen muotoilu (kriteeri) Esim. perillä tietyssä kaupungissa Tekoäly, Eero Hyvönen, 2004 2
Haun input: ongelman kuvaus tila-avaruutena avaruutena Haun output (ongelman ratkaisu): toimenpidejono alkutilasta tavoitetilaan Ongelman näin n ratkettua voidaan ratkaisu suorittaa (execution( execution) Esim. lähdetl hdetään n ajamaan kaupungista toiseen Tekoäly, Eero Hyvönen, 2004 3
Hyvin määm ääritelty tila-avaruus avaruus ongelma ja sen ratkaisu lkutila (initial( state) Esim. ollaan kaupungissa rad Tavoitetila (goal( state) Esim. ollaan ukarestissa Seuraajafunktio (successor( function) S-fn(state) -> > {<action, state>} Tila-avaruus avaruus (state( space) Määräytyy alkutilasta ja seuraajafunktiosta Esim. Romanian kartta Polku (path( path) Peräkk kkäisten toimenpiteiden muodostama tilojen jono Tavoitetesti (goal( test) Ratkaisu (solution( solution) Polku alkutilasta tavoitetilaan Toimenpiteen/polun kustannus (cost( cost) Esim. kaupunkien välinen v ajomatka Optimiratkaisu Ratkaisu, jonka kustannus on pienin Tekoäly, Eero Hyvönen, 2004 4
Tekoäly, Eero Hyvönen, 2004 5
Oletuksena yksinkertainen ympärist ristö ympärist ristön n staattisuus havaittavuus ympärist ristön diskreettisyys deterministisyys toimenpiteet suoritetaan jääj ääräpäisesti silmät ummessa toimintaa ei esim. arvioida uudelleen muuttuneessa tilanteessa Tekoäly, Eero Hyvönen, 2004 6
Tekoäly, Eero Hyvönen, 2004 7
Tekoäly, Eero Hyvönen, 2004 8
Tekoäly, Eero Hyvönen, 2004 9
Tekoäly, Eero Hyvönen, 2004 10
Tekoäly, Eero Hyvönen, 2004 11
Tekoäly, Eero Hyvönen, 2004 12
Tekoäly, Eero Hyvönen, 2004 13
24-puzzle (5x5 ruudukko): 10^25 tilaa, on jo vaikea ratkaista optimaalisesti Tekoäly, Eero Hyvönen, 2004 14
Reaalimaailman ongelmatyyppejä Route-finding Esim. lennot Navigointi Touring Esim. traveling salesperson VLSI design ssembly (kokoaminen) ioinformatiikka Esim. proteiinien laskostuminen Tekoäly, Eero Hyvönen, 2004 15
Hakupuu Haun tilan esitysmuoto Haussa hakusolmu (vast. tilaa) lavennetaan (expand)) vastaten siirtymistä seuraaviin tiloihin Jos lavennettu solmu vastaa lopputilaa, haku päättyy, muuten solmuja lavennetaan edelleen Hakustrategia määm äärää,, missä järjestyksessä edetää ään Hakupuu tila-avaruus avaruus Hakusolmu on haun kirjanpidollinen esityselementti Tekoäly, Eero Hyvönen, 2004 16
Tekoäly, Eero Hyvönen, 2004 17
Tekoäly, Eero Hyvönen, 2004 18
Tekoäly, Eero Hyvönen, 2004 19
Tekoäly, Eero Hyvönen, 2004 20
Tekoäly, Eero Hyvönen, 2004 21
Search strategies strategy is defined by picking the order of node expansion Strategies are evaluated along the following dimensions: completeness does it always find a solution if one exists? time complexity number of nodes generated/expanded space complexity maximum number of nodes in memory optimality does it always find a least-cost solution? Time and space complexity are measured in terms of b maximum branching factor of the search tree d depth of the least-cost solution m maximum depth of the state space (may be ) hapter 3 31
Uninformed search strategies Uninformed strategies use only the information available in the problem definition readth-first search Uniform-cost search Depth-first search Depth-limited search Iterative deepening search hapter 3 32
Expand shallowest unexpanded node readth-first search Implementation: fringe is a FIFO queue, i.e., new successors go at end hapter 3 33
Expand shallowest unexpanded node readth-first search Implementation: fringe is a FIFO queue, i.e., new successors go at end hapter 3 34
Expand shallowest unexpanded node readth-first search Implementation: fringe is a FIFO queue, i.e., new successors go at end hapter 3 35
Expand shallowest unexpanded node readth-first search Implementation: fringe is a FIFO queue, i.e., new successors go at end hapter 3 36
Properties of breadth-first search omplete?? hapter 3 37
Properties of breadth-first search omplete?? Yes (if b is finite) Time?? hapter 3 38
Properties of breadth-first search omplete?? Yes (if b is finite) Time?? 1 + b + b 2 + b 3 +... + b d + b(b d 1) = O(b d+1 ), i.e., exp. in d Space?? hapter 3 39
Properties of breadth-first search omplete?? Yes (if b is finite) Time?? 1 + b + b 2 + b 3 +... + b d + b(b d 1) = O(b d+1 ), i.e., exp. in d Space?? O(b d+1 ) (keeps every node in memory) Optimal?? hapter 3 40
Properties of breadth-first search omplete?? Yes (if b is finite) Time?? 1 + b + b 2 + b 3 +... + b d + b(b d 1) = O(b d+1 ), i.e., exp. in d Space?? O(b d+1 ) (keeps every node in memory) Optimal?? Yes (if cost = 1 per step); not optimal in general Space is the big problem; can easily generate nodes at 100M/sec so 24hrs = 8640G. hapter 3 41
Muistisyöppö reath-first Search b=10, 10.000 solmu/s, 1k solmu d Solmut ika Muisti 2 1100 0.11s 1M 6 10^7 19min 10G 10 10^11 12pv 10P
Expand least-cost unexpanded node Uniform-cost search Implementation: fringe = queue ordered by path cost, lowest first Equivalent to breadth-first if step costs all equal omplete?? Yes, if step cost ɛ Time?? # of nodes with g cost of optimal solution, O(b /ɛ ) where is the cost of the optimal solution Space?? # of nodes with g cost of optimal solution, O(b /ɛ ) Optimal?? Yes nodes expanded in increasing order of g(n) hapter 3 42
Expand deepest unexpanded node Depth-first search Implementation: fringe = LIFO queue, i.e., put successors at front H I J K L M N O hapter 3 43
Expand deepest unexpanded node Depth-first search Implementation: fringe = LIFO queue, i.e., put successors at front H I J K L M N O hapter 3 44
Expand deepest unexpanded node Depth-first search Implementation: fringe = LIFO queue, i.e., put successors at front H I J K L M N O hapter 3 45
Expand deepest unexpanded node Depth-first search Implementation: fringe = LIFO queue, i.e., put successors at front H I J K L M N O hapter 3 46
Expand deepest unexpanded node Depth-first search Implementation: fringe = LIFO queue, i.e., put successors at front H I J K L M N O hapter 3 47
Expand deepest unexpanded node Depth-first search Implementation: fringe = LIFO queue, i.e., put successors at front H I J K L M N O hapter 3 48
Expand deepest unexpanded node Depth-first search Implementation: fringe = LIFO queue, i.e., put successors at front H I J K L M N O hapter 3 49
Expand deepest unexpanded node Depth-first search Implementation: fringe = LIFO queue, i.e., put successors at front H I J K L M N O hapter 3 50
Expand deepest unexpanded node Depth-first search Implementation: fringe = LIFO queue, i.e., put successors at front H I J K L M N O hapter 3 51
Expand deepest unexpanded node Depth-first search Implementation: fringe = LIFO queue, i.e., put successors at front H I J K L M N O hapter 3 52
Expand deepest unexpanded node Depth-first search Implementation: fringe = LIFO queue, i.e., put successors at front H I J K L M N O hapter 3 53
Expand deepest unexpanded node Depth-first search Implementation: fringe = LIFO queue, i.e., put successors at front H I J K L M N O hapter 3 54
Properties of depth-first search omplete?? hapter 3 55
Properties of depth-first search omplete?? No: fails in infinite-depth spaces, spaces with loops Modify to avoid repeated states along path complete in finite spaces Time?? hapter 3 56
Properties of depth-first search omplete?? No: fails in infinite-depth spaces, spaces with loops Modify to avoid repeated states along path complete in finite spaces Time?? O(b m ): terrible if m is much larger than d but if solutions are dense, may be much faster than breadth-first Space?? hapter 3 57
Properties of depth-first search omplete?? No: fails in infinite-depth spaces, spaces with loops Modify to avoid repeated states along path complete in finite spaces Time?? O(b m ): terrible if m is much larger than d but if solutions are dense, may be much faster than breadth-first Space?? O(bm), i.e., linear space! Optimal?? hapter 3 58
Properties of depth-first search omplete?? No: fails in infinite-depth spaces, spaces with loops Modify to avoid repeated states along path complete in finite spaces Time?? O(b m ): terrible if m is much larger than d but if solutions are dense, may be much faster than breadth-first Space?? O(bm), i.e., linear space! Optimal?? No hapter 3 59
Depth-limited search = depth-first search with depth limit l, i.e., nodes at depth l have no successors Recursive implementation: function Depth-Limited-Search( problem, limit) returns soln/fail/cutoff Recursive-DLS(Make-Node(Initial-State[problem]), problem, limit) function Recursive-DLS(node, problem, limit) returns soln/fail/cutoff cutoff-occurred? false if Goal-Test(problem, State[node]) then return node else if Depth[node] = limit then return cutoff else for each successor in Expand(node, problem) do result Recursive-DLS(successor, problem, limit) if result = cutoff then cutoff-occurred? true else if result failure then return result if cutoff-occurred? then return cutoff else return failure hapter 3 60
Iterative deepening search function Iterative-Deepening-Search( problem) returns a solution inputs: problem, a problem for depth 0 to do result Depth-Limited-Search( problem, depth) if result cutoff then return result end hapter 3 61
Iterative deepening search l = 0 Limit = 0 hapter 3 62
Iterative deepening search l = 1 Limit = 1 hapter 3 63
Iterative deepening search l = 2 Limit = 2 hapter 3 64
Iterative deepening search l = 3 Limit = 3 H I J K L M N O H I J K L M N O H I J K L M N O H I J K L M N O H I J K L M N O H I J K L M N O H I J K L M N O H I J K L M N O H I J K L M N O H I J K L M N O H I J K L M N O H I J K L M N O hapter 3 65
omplete?? Properties of iterative deepening search hapter 3 66
Properties of iterative deepening search omplete?? Yes Time?? hapter 3 67
Properties of iterative deepening search omplete?? Yes Time?? (d + 1)b 0 + db 1 + (d 1)b 2 +... + b d = O(b d ) Space?? hapter 3 68
Properties of iterative deepening search omplete?? Yes Time?? (d + 1)b 0 + db 1 + (d 1)b 2 +... + b d = O(b d ) Space?? O(bd) Optimal?? hapter 3 69
Properties of iterative deepening search omplete?? Yes Time?? (d + 1)b 0 + db 1 + (d 1)b 2 +... + b d = O(b d ) Space?? O(bd) Optimal?? Yes, if step cost = 1 an be modified to explore uniform-cost tree Numerical comparison for b = 10 and d = 5, solution at far right leaf: N(IDS) = 50 + 400 + 3, 000 + 20, 000 + 100, 000 = 123, 450 N(FS) = 10 + 100 + 1, 000 + 10, 000 + 100, 000 + 999, 990 = 1, 111, 100 IDS does better because other nodes at depth d are not expanded FS can be modified to apply goal test when a node is generated hapter 3 70
Summary of algorithms riterion readth- Uniform- Depth- Depth- Iterative First ost First Limited Deepening omplete? Yes Yes No Yes, if l d Yes Time b d+1 b /ɛ b m b l b d Space b d+1 b /ɛ bm bl bd Optimal? Yes Yes No No Yes hapter 3 71
Repeated states Failure to detect repeated states can turn a linear problem into an exponential one! D hapter 3 72
Graph search function Graph-Search( problem, fringe) returns a solution, or failure closed an empty set fringe Insert(Make-Node(Initial-State[problem]), fringe) loop do if fringe is empty then return failure node Remove-Front(fringe) if Goal-Test(problem, State[node]) then return node if State[node] is not in closed then add State[node] to closed fringe Insertll(Expand(node, problem), fringe) end hapter 3 73
Verkkohaku = puuhaku, joka muistaa aiemmin tutkimansa solmut eikä toista lavennuksia Idea: ei tehdä samaa työtä useaan kertaan Verkkohaku voi olla paljon tehokkaampi kuin puuhaku Tilakompeksisuus kasvaa suljetun listan muistamisen takia Optimaalisuus riippuu käytetystk ytetystä strategiasta Optimiratkaisu voidaan hylätä toistoa vältettv ltettäessä
Haku epätäsm smällisellä tiedolla Sensorless / conformant problems gentti ei tiedä missä tilassa se on (voi olla useassa) Vaihtoehtoiset skenaariot Tila-avaruuden avaruuden uskomustiloina (belief( state) ) tilojen joukot ontingency problems Havainnot ympärist ristöstä tai toimenpiteiden vaikutus epätäsm smällisiä Vaihtoehtoiset skenaariot Hakua laajennetaan havaintoon perustavalla ehdollisella toimenpiteell teellä Toiminnan kokeilun ja haun yhdistelmä Esim. käveleminen k kadulla maitokauppaan dversal problems ontingency problem,, jossa epätäsm smällisyys on toisen agentin aiheuttamaa Exploration problems Tiloja ja toimenpiteiden vaikutuksia ei tunneta vaan ne pitää tutkia Ääritapaus contingency-ongelmista ongelmista Tekoäly, Eero Hyvönen, 2004 28
Summary Problem formulation usually requires abstracting away real-world details to define a state space that can feasibly be explored Variety of uninformed search strategies Iterative deepening search uses only linear space and not much more time than other uninformed algorithms Graph search can be exponentially more efficient than tree search hapter 3 74
Lähteet S. Russell,, P. Norvig: rtificial Intelligence, a Modern pproach. Prentice-Hall Hall,, 2003. S. Russell,, Tekoälykurssin kalvot erkleyn yliopistossa, 2004. Tekoäly, Eero Hyvönen, 2004 29