Today’s Topics Exam Thursday Oct 22. 5:30-7:3-pm, same room as lecture Makeup Thursday Oct 29? Or that Monday or Wednesday? Exam Covers Material through End of Lecture 14 Part of Oct 20 class will be Exam Review –Bring (worked!) copy of my Fall 2014 cs540 midterm I will Arrange for TA to come to Epic Oct 21, 5:30-7:30pm What if Arcs have Costs? –Finding Least-Cost Solutions (eg, GPS, Google Maps) –Uniform-cost search, A* search –Heuristic functions Search Wrapup (except genetic and games) 10/6/15CS Fall 2015 (Shavlik©), Lecture 11, Week 51
What if Arcs Have Costs? Might want CHEAPEST solutions –and be willing to spend more cpu cycles We’ll put (non-negative) costs on arcs –If costs negative, infinite loops would be great! 10/6/15CS Fall 2015 (Shavlik©), Lecture 11, Week 52 S B G
Uniform Cost Search (UC) Sort OPEN by g(node), which is the cost from a/the startNode to node by the path taken to reach node Need to store ‘parent pointers’ in nodes (so can ‘back trace’ to startNode) Sometimes we will need to change these pointers if a CHEAPER path to node found 10/6/15CS Fall 2015 (Shavlik©), Lecture 11, Week 5 3
Addition to Our Generic Search Code If a child of X is ALREADY IN OPEN OR CLOSED, see if current path is better If so, remove old item from OPEN/CLOSED and insert new item in OPEN Otherwise discard child –In some cases non-optimal paths will never reach CLOSED, but safer to always check 10/6/15CS Fall 2015 (Shavlik©), Lecture 11, Week 5 4
New and Improved, Now with Arc Costs - assume LOWER scores are better 10/6/15 CS Fall 2015 (Shavlik©), Lecture 11, Week 5 5 Start score = 9 B score = 11 C score = 8 D score = 4 E score = 3 Goal score = 0 Step# OPEN CLOSED X CHILDREN RemainingCHILDREN (this part done on doc camera for UNIFORM and, later, A*)
UC - not shown, but you should use a SUPERSCRIPT to show parent Step# OPEN CLOSED X CHILDREN RemCHILDREN 1 { S 0 } { } S { S 5, B 1, C 6 } { B 1, C 6 } 2 { B 1, C 6 } { S 0 } B { D 8 } { D 8 } 3 { C 6, D 8 } { S 0, B 1 } C { G 15 } { G 15 } 4 { D 8, G 15 } { S 0, B 1, C 6 } D { E 10, C 16 } { E 10 } 5 { E 10, G 15 } { S 0, B 1, C 6, D 8 } E { G 14 } { G 14 } 6 { G 14 } { S 0, B 1, C 6, D 8, E 10 } G DONE A* - subscript is g+h Step# OPEN CLOSED X CHILDREN RemCHILDREN 1 { S 0+9 } { } S 0+9 { S 5+9, B 1+11, C 6+8 } { B 1+11, C 6+8 } 2 { B 1+11, C 6+8 } { S 0+9 } B 1+11 { D 8+4 } { D 8+4 } 3 { D 8+4, C 6+8 } { S 0+9, B 1+11 } D 8+4 { E 10+3, C 16+8 } { E 10+3 } 4 { E 10+3, C 6+8 } {S 0+9, B 1+11, D 8+4 } E 10+3 { G 14+0 } { G 14 } 5 { C 6+8, G 14+0 } {… E 10+3 } C 6+8 { G 15+0 } { } 6 { G 14+0 } {… E 10+3, C 6+8 } G 14+0 DONE 9/29/15CS Fall 2015 (Shavlik©), Lecture 9, Week 4 Lecture 1, Slide 6
Theorem Uniform-cost search will produce a lowest-cost solution PROOF Assume we have found solution path S that costs C If cheaper soln exists, the beginning of it would be in OPEN (we keep ALL partial solns) Since all arc costs are non-negative, this partial soln would cost less than C (total costs never get smaller) But by construction, we POP OPEN and lowest-cost always at front Hence cannot have something something still in OPEN that costs less than C 10/6/15CS Fall 2015 (Shavlik©), Lecture 11, Week 5 7
UC Doesn’t Use Domain K (K = knowledge) Under certain conditions (later), sorting by this will get a shortest path f(node) = g(node) + h(node) while possible ‘expanding’ many fewer nodes h(node) is our heuristic estimate of ‘distance’ to goal 10/6/15CS Fall 2015 (Shavlik©), Lecture 11, Week 5 8 S n G g(n) h(n)
Practice with f(n) Go back to Slide 5 and use f(n) An example where using h(n) greatly helps 10/6/15CS Fall 2015 (Shavlik©), Lecture 11, Week 5 9 h=94 SA D F E C B G Z h=89...
Graph Where One Needs to Remove Item from CLOSED (also shows why we check for GOAL when REMOVING from OPEN, rather than when ADDING) 10/6/15CS Fall 2015 (Shavlik©), Lecture 11, Week 5 10 S h=3 B h=20 C h= G h=0 99
Admissibility Defn: if a search algo always produces shortest paths (assuming one exists), then the algo is called admissible If h(n) never over estimates the actual distance to a goal, then using f(n)=g(n)+h(n) will lead to best-first search being admissible (and we also call h(n) admissible) BEST with an admissible h(n) is called A* (pronounced “A star” – some AI humor!) Note that A* can have large OPEN and CLOSED since all promising partial paths kept 10/6/15CS Fall 2015 (Shavlik©), Lecture 11, Week 5 11
What Happens if h(n) Overestimates? Best solution might get pushed deep into OPEN and never checked 10/6/15CS Fall 2015 (Shavlik©), Lecture 11, Week 5 12 S h=3 B h=999 C h= G h=0 99
What Happens if h(n) Underestimates? Might waste time on a non-optimal path 10/6/15CS Fall 2015 (Shavlik©), Lecture 11, Week 5 13 S h=3 B h=1 C h= G h=0 99 D h=1...
Creating Good h Functions Mainly a task-specific ‘art’ h(n) should be a fast algorithm (would not be good if h(n) implemented DFS!) Often ‘simplifying assumptions’ or ‘relaxations’ of the task create good h’s Note that user focuses on creating h using domain K and A* ‘works out the details’ 10/6/15CS Fall 2015 (Shavlik©), Lecture 11, Week 5 14
Some Properties of A* 1.“Informedness” If h 1 (n) and h 2 (n) are both admissible, and n h 1 (n) h 2 (n) then the nodes A* expands using h 1 (n) are a subset of those it expands using h 2 (n) Visually 10/6/15CS Fall 2015 (Shavlik©), Lecture 11, Week 5 15 h True distance h1h1 h2h2 error So the better h(n) is, the faster A* runs
Some Properties of A* 2.“Robustness” If h ‘rarely’ overestimates by more than , then A* will rarely find a sol’n whose cost is more than optimal 2.“Completeness” A* will terminate with a optimal soln even in infinite space, provided a soln exists and all arc costs are greater than some positive number 10/6/15CS Fall 2015 (Shavlik©), Lecture 11, Week 5 16
THINK Before You Search! Naïve Algo ACTIONS: Fill ‘top-left most’ empty cell with legal moves in {1, 2, …, 9 } LARGE search tree! Smarter Algo (usually NEVER need to search!) 1)Mark each empty cell with candidates that do not violate game’s rules, eg, top cell in this image can be filled with {3, 5, 8, or 9} 2)IF NO cells with only one possible filler Let k be the smaller set of fillers, pick ‘top-left most’ cell with k fillers and put the k next board states in OPEN 3)ELSE For all those cells with only ONE possible filler, choose that filer If game solved EXIT else update “possible fillers’” for all empty cells and go to 2 10/6/15CS Fall 2015 (Shavlik©), Lecture 11, Week 5 17 Only 2 legal here
Search Wrap Up Lots of Variations and Tradeoffs We’ve Explored a Wide Range but not All Powerful, General-Purpose, Problem-Solving Method –Watch for Places it can be Employed –Especially when cpu cycles abundant OPEN a Key Data Structure –CLOSED Prevents Repeated Work Our General Search Algo Inefficient for Some Methods, but Provides a Unifying View –Needs Modification for Some Methods to Work Correctly Heuristic Functions a Good Way to Use Domain K in Intuitive Way Next: Search with an Adversary (game playing) Then: Genetic Search (based on evolution) 10/6/15CS Fall 2015 (Shavlik©), Lecture 11, Week 5 18