
State Space Representaons and Search Algorithms CS171, Fall 2016 Introduc,on to Ar,ficial Intelligence Prof. Alexander Ihler Reading: R&N 3.1-3.4 Architectures for Intelligence • Search? – Determine how to achieve some goal; “what to do” • Logic & inference? – Reason about what to do – Encode knowledge / “expert” systems – Know what to do • Learning? – Learn what to do • Modern view: complex & mul,-faceted Search • Formulate “what to do” as a search problem – Solu,on tells the agent what to do • If no solu,on in the current search space? – Find space that does contain a solu,on (use search!) – Solve original problem in new search space • Many powerful extensions to these ideas – Constraint sasfac,on; planning; game playing; … • Human problem-solving o[en looks like search Why search? • Engaged in bigger, important problem – Hit a search subproblem we need to solve – Search, solve it, get back to original problem • Predict the results of our ac,ons in the future • Many sequences of ac,ons, each with some u,lity – Maximize performance measure • Want to achieve some goal by some (any?) means • Or, find the best (op,mal) way to achieve it Example: Romania • On holiday in Romania – Currently in Arad – Flight leaves tomorrow from Bucharest • Formulate goal: – Be in Bucharest • Formulate problem: – States: various ci,es – Acons: drive between ci,es / choose next city • Find a solu,on: – Sequence of ci,es, e.g.: Arad, Sibiu, Fagaras, Bucharest Example: Romania Oradea 71 Neamt 87 75 Zerind 151 Iasi 140 92 Arad Sibiu Fagaras 99 118 Vaslui Timisoara 80 Rimnicu Vilcea 97 211 142 111 Pitesti Lugoj 70 98 146 Hirsova Mehadia 85 101 Urziceni 86 75 138 Bucharest 120 Dobreta 90 Cralova Eforie Giurgiu Problem types Classifying the environment: • Stac / Dynamic Previous problem was stac: no aen,on to changes in environment • Determinis,c / Stochas,c Previous problem was determinis,c: no new percepts were necessary, we can predict the future perfectly • Observable / Par,ally Observable / Unobservable Previous problem was observable: it knew the ini,al state, &c • Discrete / Con,nuous Previous problem was discrete: we can enumerate all possibili,es Why not Dijkstra’s Algorithm? • D’s algorithm inputs the en,re graph – Want to search in unknown spaces – Combine search with “exploraon” – Ex: autonomous rover on Mars must search an unknown space • D’s algorithm takes connec,ons as given – Want to search based on agent’s ac,ons, w/ unknown connec,ons – Ex: web crawler may not know what connec,ons are available on a URL before visi,ng it – Ex: agent may not know the result of an ac,on before trying it • D’s algorithm won’t work on infinite spaces – Many ac,ons spaces are infinite or effec,vely infinite – Ex: logical reasoning space is infinite – Ex: real world is essen,ally infinite to a human-size agent Ex: Vacuum World • Observable, start in #5. • Soluon? 1 2 [Right, Suck] 3 4 5 6 7 8 Vacuum world state space graph R L R L S S R R L R L R L L S S S S R L R L S S Ex: Vacuum World • Unobservable, start in {1,2,3,4,5,6,7,8} 1 2 • Soluon? 3 4 [Right, Suck, Le[, Suck] 5 6 7 8 Ex: Vacuum World State-Space Problem Formulaon Oradea 71 Neamt 87 75 Zerind 151 A problem is defined by four items: Iasi 140 92 Arad Sibiu 99 Fagaras 118 Vaslui inial state e.g., "at Arad“ Timisoara 80 Rimnicu Vilcea 97 211 142 111 Lugoj Pitesti 70 85 98 146 Hirsova Mehadia 101 Urziceni 75 86 ac5ons Acons(s) = set of ac,ons avail. in state s 120 138 Bucharest Dobreta 90 Cralova Eforie Giurgiu transion model Results(s,a) = state that results from ac,on a in states Alt: successor funcon S(x) = set of ac,on–state pairs – e.g., S(Arad) = {<Arad à Zerind, Zerind>, … } goal test, (or goal state) e.g., x = "at Bucharest”, Checkmate(x) path cost (addi,ve) – e.g., sum of distances, number of ac,ons executed, etc. – c(x,a,y) is the step cost, assumed to be ≥ 0 A soluon is a sequence of ac,ons leading from the ini,al state to a goal state Selec,ng a state space • Real world is absurdly complex à state space must be abstracted for problem solving • (Abstract) state ß set of real states • (Abstract) ac,on ß complex combinaon of real ac,ons – e.g., "Arad à Zerind" represents a complex set of possible routes, detours, rest stops, etc. • For guaranteed realizability, any real state "in Arad” must get to some real state "in Zerind” • (Abstract) solu,on ß set of real paths that are solu,ons in the real world • Each abstract ac,on should be "easier" than the original problem Ex: Vacuum World • States? – Discrete: dirt, locaon • Ini,al state? 1 2 – Any • Acons? 3 4 – Le[, Right, Suck • Goal test? 5 6 – No dirt at all locaons • Path cost? 7 8 – 1 per ac,on Ex: 8-Queens Place as many queens as possible on the chess board without capture • states? - any arrangement of n<=8 queens - or arrangements of n<=8 queens in le[most n columns, 1 per column, such that no queen aacks any other. • ini,al state? no queens on the board • ac,ons? - add queen to any empty square - or add queen to le[most empty square such that it is not aacked by other queens. • goal test? 8 queens on the board, none aacked. • path cost? 1 per move Ex: 8-Queens Place as many queens as possible on the chess board without capture • states? - any arrangement of n<=8 queens - or arrangements of n<=8 queens in le[most n columns, 1 per column, such that no queen aacks any other. • ini,al state? no queens on the board • ac,ons? - add queen to any empty square - or add queen to le[most empty square such that it is not aacked by other queens. • goal test? 8 queens on the board, none aacked. • path cost? 1 per move (not relevant…) Ex: Robo,c assembly • states? Real-valued coordinates of robot joint angles & parts of the object to be assembled • ini,al state? Rest configuraon • ac,ons? Con,nuous mo,ons of robot joints • goal test? Complete assembly • path cost? Time to execute & energy used Ex: Sliding ,le puzzle 2 8 3 1 2 3 1 6 4 4 5 6 7 5 7 8 Start State Goal State • states? • ini,al state? • ac,ons? Try it yourselves… • goal test? • path cost? Ex: Sliding ,le puzzle 2 8 3 1 2 3 1 6 4 4 5 6 7 5 7 8 Start State Goal State # of states: n+1! / 2 8-puzzle: 181,440 states • states? Locaons of ,les 15-puzzle: 1.3 trillion 24-puzzle: 10^25 • ini,al state? Given • ac,ons? Move blank square up / down / le[ / right • goal test? Goal state (given) • path cost? 1 per move Optimal solution of n-Puzzle family is NP-hard Importance of representaon • Defini,on of “state” can be very important • A good representaon – Reveals important features – Hides irrelevant detail – Exposes useful constraints – Makes frequent operaons easy to do – Supports local inferences from local features • Called “soda straw” principle, or “locality” principle • Inference from features “through a soda straw” – Rapidly or efficiently computable • It’s nice to be fast Reveals important features / Hides irrelevant detail • In search: A man is traveling to market with a fox, a goose, and a bag of oats. He comes to a river. The only way across the river is a boat that can hold the man and exactly one of the fox, goose or bag of oats. The fox will eat the goose if left alone with it, and the goose will eat the oats if left alone with it. How can the man get all his possessions safely across the river? • A good representation makes this problem easy: 1110 0100 MFGO M = man 0000 1010 0010 1101 0101 1111 F = fox 1110 G = goose 0010 O = oats 1010 0 = starting side 1011 0001 1111 1 = ending side 0001 0101 Exposes useful constraints • In logic: If the unicorn is mythical, then it is immortal, but if it is not mythical, then it is a mortal mammal. If the unicorn is either immortal or a mammal, then it is horned. The unicorn is magical if it is horned. Prove that the unicorn is both magical and horned. • A good representation makes this problem easy (as we’ll see when we do our unit on logic): ( ¬ Y ˅ ¬ R ) ^ ( Y ˅ R ) ^ ( Y ˅ M ) ^ ( R ˅ H ) ^ ( ¬ M ˅ H ) ^ ( ¬ H ˅ G ) Makes frequent operaons easy-to-do • Roman numerals • M=1000, D=500, C=100, L=50, X=10, V=5, I=1 • 2000 = MM; 1776 = MDCCLXXVI • Long division is very tedious (try MDCCLXXVI / XVI) • Tes,ng for N < 1000 is very easy (first leaer is not “M”) • Arabic numerals • 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, “.” • Long division is much easier (try 1776 / 16) • Tes,ng for N < 1000 is slightly harder (have to scan the string) Local inferences from local features • Linear vector of pixels = highly non-local inference for vision … … 0 1 0 … … 0 1 1 … … 0 0 0 … … Corner ?? • Rectangular array of pixels = local inference for vision Corne 0 0 0 1 0 0 0 0 0 0 r!! 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Tree search algorithms • Basic idea – Explore space by generang successors of already- explored states (“expanding” states) – Evaluate every generated state: is it a goal state? Example: Romania Arad Sibiu Timisoara Zerind Arad Fagaras Oradea Rimnicu… Arad Lugoj Arad Oradea Oradea 71 Neamt 87 75 Zerind 151 Iasi 140 92 Arad Sibiu 99 Fagaras 118 Vaslui Timisoara 80 Rimnicu Vilcea 97 211 142 111 Lugoj Pitesti 70 85 98 146 Hirsova Mehadia 101 Urziceni 86 75 120 138 Bucharest Dobreta 90 Cralova Eforie Giurgiu Example: Romania Arad Sibiu Timisoara Zerind Arad Fagaras Oradea Rimnicu… Arad Lugoj Arad Oradea Note: we may visit the same node often, wasting time & work function TREE-SEARCH (problem, strategy) : returns a solution or failure! initialize the search tree using the initial state of problem! while (true):! if no candidates for expansion: return failure! choose a leaf node for expansion according to strategy! if the node contains a goal state: return the corresponding solution! else: expand the node and add the resulting nodes to the search tree! ! Repeated states • Failure to detect repeated states can turn a linear problem into an exponen,al one! • Test is o[en implemented as a hash table.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages34 Page
-
File Size-