1 CS 2710, ISSP 2160 Chapter 3, Part 2 Heuristic Search.

Slides:



Advertisements
Similar presentations
Local Search and Optimization
Advertisements

Review: Search problem formulation
Informed Search Algorithms
Informed search strategies
Informed search algorithms
An Introduction to Artificial Intelligence
Problem Solving: Informed Search Algorithms Edmondo Trentin, DIISM.
CSCI 5582 Fall 2006 CSCI 5582 Artificial Intelligence Lecture 4 Jim Martin.
Solving Problem by Searching
1 Heuristic Search Chapter 4. 2 Outline Heuristic function Greedy Best-first search Admissible heuristic and A* Properties of A* Algorithm IDA*
SE Last time: Problem-Solving Problem solving: Goal formulation Problem formulation (states, operators) Search for solution Problem formulation:
Review: Search problem formulation
Introduction to Artificial Intelligence A* Search Ruth Bergman Fall 2002.
A* Search Introduction to AI. What is an A* Search? A greedy search method minimizes the cost to the goal by using an heuristic function, h(n). It works.
Artificial Intelligence
Cooperating Intelligent Systems Informed search Chapter 4, AIMA.
Introduction to Artificial Intelligence A* Search Ruth Bergman Fall 2004.
CS 460 Spring 2011 Lecture 3 Heuristic Search / Local Search.
Informed Search Methods How can we make use of other knowledge about the problem to improve searching strategy? Map example: Heuristic: Expand those nodes.
Problem Solving and Search in AI Heuristic Search
CSC344: AI for Games Lecture 4: Informed search
Rutgers CS440, Fall 2003 Heuristic search Reading: AIMA 2 nd ed., Ch
Artificial Intelligence Problem solving by searching CSC 361 Prof. Mohamed Batouche Computer Science Department CCIS – King Saud University Riyadh, Saudi.
Dr.Abeer Mahmoud ARTIFICIAL INTELLIGENCE (CS 461D) Dr. Abeer Mahmoud Computer science Department Princess Nora University Faculty of Computer & Information.
Informed search algorithms
Informed (Heuristic) Search
1 CS 2710, ISSP 2610 Chapter 4, Part 1 Heuristic Search.
Informed search algorithms
2013/10/17 Informed search A* algorithm. Outline 2 Informed = use problem-specific knowledge Which search strategies? Best-first search and its variants.
Informed search algorithms Chapter 4. Outline Best-first search Greedy best-first search A * search Heuristics.
CHAPTER 4: INFORMED SEARCH & EXPLORATION Prepared by: Ece UYKUR.
1 Shanghai Jiao Tong University Informed Search and Exploration.
Informed search algorithms Chapter 4. Best-first search Idea: use an evaluation function f(n) for each node –estimate of "desirability"  Expand most.
Informed search strategies Idea: give the algorithm “hints” about the desirability of different states – Use an evaluation function to rank nodes and select.
Informed searching. Informed search Blind search algorithms do not consider any information about the states and the goals Often there is extra knowledge.
Informed Search Methods. Informed Search  Uninformed searches  easy  but very inefficient in most cases of huge search tree  Informed searches  uses.
Chapter 4 Informed/Heuristic Search
Review: Tree search Initialize the frontier using the starting state While the frontier is not empty – Choose a frontier node to expand according to search.
CSC3203: AI for Games Informed search (1) Patrick Olivier
Informed Search I (Beginning of AIMA Chapter 4.1)
Artificial Intelligence Problem solving by searching.
1 Kuliah 4 : Informed Search. 2 Outline Best-First Search Greedy Search A* Search.
Informed Search and Heuristics Chapter 3.5~7. Outline Best-first search Greedy best-first search A * search Heuristics.
A General Introduction to Artificial Intelligence.
Feng Zhiyong Tianjin University Fall  Best-first search  Greedy best-first search  A * search  Heuristics  Local search algorithms  Hill-climbing.
Best-first search Idea: use an evaluation function f(n) for each node –estimate of "desirability"  Expand most desirable unexpanded node Implementation:
Pengantar Kecerdasan Buatan 4 - Informed Search and Exploration AIMA Ch. 3.5 – 3.6.
Informed Search II CIS 391 Fall CIS Intro to AI 2 Outline PART I  Informed = use problem-specific knowledge  Best-first search and its variants.
Heuristic Search Foundations of Artificial Intelligence.
Introduction to Artificial Intelligence (G51IAI)
Chapter 3.5 and 3.6 Heuristic Search Continued. Review:Learning Objectives Heuristic search strategies –Best-first search –A* algorithm Heuristic functions.
CPSC 420 – Artificial Intelligence Texas A & M University Lecture 5 Lecturer: Laurie webster II, M.S.S.E., M.S.E.e., M.S.BME, Ph.D., P.E.
Romania. Romania Problem Initial state: Arad Goal state: Bucharest Operators: From any node, you can visit any connected node. Operator cost, the.
Reading Material Sections 3.3 – 3.5 Sections 4.1 – 4.2 “Optimal Rectangle Packing: New Results” By R. Korf (optional) “Optimal Rectangle Packing: A Meta-CSP.
Chapter 3 Solving problems by searching. Search We will consider the problem of designing goal-based agents in observable, deterministic, discrete, known.
Chapter 3.5 Heuristic Search. Learning Objectives Heuristic search strategies –Best-first search –A* algorithm Heuristic functions.
Review: Tree search Initialize the frontier using the starting state
Last time: Problem-Solving
Artificial Intelligence (CS 370D)
Heuristic Search Introduction to Artificial Intelligence
Introduction to Artificial Intelligence
Discussion on Greedy Search and A*
Discussion on Greedy Search and A*
CS 4100 Artificial Intelligence
Informed search algorithms
Informed search algorithms
Artificial Intelligence
Artificial Intelligence
CS 416 Artificial Intelligence
Solving Problems by Searching
Presentation transcript:

1 CS 2710, ISSP 2160 Chapter 3, Part 2 Heuristic Search

2 Take advantage of information about the problem

3 Best-First-Search An evaluation function f determines order of nodes on the fringe (there are variations, depending on the search algorithm)

4 Best-First-Search In our framework: –treesearch or graphsearch, with nodes ordered on the fringe in increasing order by an evaluation function, f(n).

5 def treesearch (qfun,fringe): while len(fringe) > 0: cur = fringe[0] fringe = fringe[1:] if goalp(cur): return cur fringe = qfun(makeNodes(cur,successors(cur)),fringe) return [] best-first search: qfun appends the lists together and sorts them in increasing order by f-value [In the more efficient version, a heap is used to maintain the queue in increasing order by f-value]

6 Heuristic Evaluation Function, h(n) F may involve “heuristic evaluation function”, h(n)

7 h(n) Metric on states. Estimate of shortest distance to some goal. h : state  estimate of distance to goal h (goal) = 0 for all goal nodes

8 Greedy Best-First Search f (n) = h (n) Greedy best-first search may switch its strategy mid-search. For example, it may go depth-first for awhile, but then return to the shallow parts of the tree.

9 Greedy Example In the map domain, h(n) could be the straight line distance from a city to Bucharest Greedy search expands the node that currently appears to be closest to the goal

10 Go from Arad to Bucharest Oradea Zerind Arad Sibiu Timisoara Lugoj Mehadia Dobreta Rimnicu Vilcea Fagaras Craiova Pitesti Giurgiu Bucharest Urziceni Vaslui Iasi Neamt Hirsova Eforie

11 Greedy Example Arad 366 Sibiu 253 Zerind 374 Timisoara 329 Arad 366 Oradea 380 Fagaras 178 Rimniciu 193 Bucharest 0Sibiu 253

12 Greedy Search Complete? –Nope Optimal? –Nope Time and Space? –It depends

13 Best of Both In an A* search we combine the best parts of Uniform-Cost and Best-First. [Simple example in lecture] We want to use the cost so-far to allow optimality and completeness, while at the same time using a heuristic to draw us toward a goal.

14 A*: f(n) = g(n) + h(n) g(n): actual cost from start to n h(n): estimated distance from n.state to a goal Even if h continuously returns good values for states along a path, if no goal is reached, g will eventually dominate h and force backtracking to more shallow nodes.

Example Figure 3.24 shows the progress of A* on the Romanian route finding problem. The h-values it uses are in Figure 3.22 The next slide shows the state space with both the edge costs and the h-values in one diagram; this will help you trace through Figure

16 Go from Arad to Bucharest Oradea Zerind Arad Sibiu Timisoara Lugoj Mehadia Dobreta Rimnicu Vilcea Fagaras Craiova Pitesti Giurgiu Bucharest Urziceni Vaslui Iasi Neamt Hirsova Eforie

17 A*: f(n) = g(n) + h(n) If h(n) does not overestimate the real cost then the treesearch version of A* is optimal. An h function that does not overestimate is called admissible

18 A* with an admissible heuristic is optimal Let: g2 be a suboptimal goal on fringe and gO be an optimal goal, g(gO) = C* C* < g(g2) (since g2 is suboptimal) h(g2) = 0 (since g2 is a goal) So f(g2) = g(g2) and C* < f(g2)

19 Proof continued Let n be a node on the fringe that is on an optimal solution path Since h is admissible: f(n) = g(n) + h(n) <= C* For g2 to be the first goal found, it would need to be first on the fringe But f(n) <= C* < f(g2)

20 A* is complete Even if the heuristic is not admissible (As long as all edgecosts exceed some finite e and that the branching factor, b, is finite. The wrap-up notes mention these details)

21 A* and Memory Does A* solve the memory problems with BrFS and Uniform Cost? –A* has same or smaller memory requirement than BrFS or Uniform Cost –How is A* related to BrFS And UC? –BrFS = A* with edgecost(n1,n2) = c, h(n) = 0 (for some positive c) –UC = A* with h(n) = 0 –But it might not be sufficiently better to make A* practically feasible

22 Note Placement of goalp test (and return if successful) in algorithm is critical. Optimality guarantee lost if nodes are tested when they are generated [elaboration and example] True for uniform-cost search too

23 Note for A* Assuming f-costs are nondecreasing along any path: –Can draw contours in the state space –Inside a contour labeled 300 are all nodes with f(n) less than or equal to 300 –A* fans out from start, expanding nodes in bands of increasing f-cost. –h(n) = 0 and edgecosts equal: contours are round –With better heuristics, the bands narrow and stretch toward the goal node

24 EG Admissible Heuristics The 8-puzzle (a small version of the 15 puzzle). Sample heuristics H1: Number of misplaced tiles H2: Manhattan distance

25 8 Puzzle Example H1(S) = 7 H2(S) = = 18 Which heuristic is better?

26 Informedness Let h1 and h2 be admissible heuristics. If h1(n) <= h2(n) for all n, then h2 is more informed than h1 and Fewer nodes will be expanded, on average, with h2 than with h1 The larger values the better (without going over)

27 A* is often not feasible Still a memory hog What can we do? Use an iterative deepening style strategy!

28 IDA* Like iterative deepening, but search to f-contours rather than fixed depths. Each iteration expands all nodes within a particular f-value range.

29 Def fLimSearch(fringe,fLim): nextF = INFINITY while fringe: cur = fringe[0] fringe = fringe[1:] curF = cur.gval + h(cur) if curF <= fLim: if goalp(cur): return(cur,curF) succNodes = makeNodes(cur,successors(cur)) for s in succNodes: fVal = s.gval + h(s) if fVal > fLim and fVal < nextF: nextF = fVal fringe = succNodes + fringe return ([],nextF)

30 def IDAstar(start): result = [] startNode = Node(start) fLim = h(startNode) while not result: result, FLim = fLimSearch([startNode],fLim) return result

31 IDA* Worst case, space is O(bd) (if edgecosts are all equal and the heuristic is admissible; we aren’t analyzing other cases) Optimal, if h is admissible The number of iterations grows as the number of possible f values grow. Let x = average # nodes with the same f-value. The lower x is, the fewer new nodes, on average, are expanded on each iteration. Practical if x above is not too low – avoids the overhead of maintaining a sorted queue, and realizes the space savings of depth- first search

32 Beam Search Cheap, unpredictable search For problems with many solutions, it may be worthwhile to discard unpromising paths Greedy best first search that keeps a fixed number of nodes on the fringe

33 Beam Search def beamSearch(fringe,beamwidth): while len(fringe) > 0: cur = fringe[0] fringe = fringe[1:] if goalp(cur): return cur newnodes = makeNodes(cur, successors(cur)) for s in newnodes: fringe = insertByH(s, fringe) fringe = fringe[:beamwidth] return []

34 Beam Search Optimal? Complete? Hardly! Space? O(b) (generates the successors) Often useful

35 General Notes before Continuing

36 Search strategies differ along many dimensions Basic strategy: depth-first, breadth-first, least-actual-cost (g(n)), best first (h(n)), or a mixture? Is the algorithm iterative, starting by looking at a small part of the state space and then successively looking at larger parts of it? (e.g., iterative deepening and IDA*)

37 Search strategies differ along many dimensions Does it pay attention to cycles? (i.e., our treesearch vs. graphsearch) Can it backtrack? Or are parts of the search tree/graph irrevocably pruned? (e.g., beam search) Does it only look ahead toward goal (h), or does it also consider how far it has come so far? (g)

38 A note on optimality It might be desirable to be greedy (e.g., greedy best-first vs. A*) Simon: people are often “satisficers”: often, they stop as soon as they find a satisfactory solution Consider choosing a line at the grocery store, or finding a parking space

Creating Heuristics 39

40 Combining Heuristics If you have lots of heuristics and none dominates the others and all are admissible… Use them all! h(n) = max(h1(n), …, hm(n))

Relaxed Heuristic Relaxed problem A problem with fewer restrictions on the actions The cost of an optimal solution to a relaxed problem is an admissible heuristic for the original problem. 41

42 Relaxed Problems Exact solutions to different (relaxed) problems H1 (# of misplaced tiles) is perfectly accurate if a tile could move to any square H2 (sum of Manhattan distances) is perfectly accurate if a tile could move 1 square in any direction

43 Relaxed Problems If problem is defined formally as a set of constraints, relaxed problems can be generated automatically Absolver (Prieditis, 1993) –Discovered a better heuristic for 8 puzzle and the first useful heuristic for Rubik’s cube Next slide: formal definition of a problem that will allow us to relax it in order to automatically generate heuristics This looks forward to the planning section of the course

Systematic Relaxation Precondition List –A conjunction of predicates that must hold true before the action can be applied Add List –A list of predicates that are to be added to the description of the world-state as a result of applying the action Delete List –A list of predicates that are no longer true once the action is applied and should, therefore, be deleted from the state description Primitive Predicates –ON(x, y):tile x is on cell y –CLEAR(y):cell y is clear of tiles –ADJ(y, z):cell y is adjacent to cell z 44

Here is the full definition of s move for the n-puzzle Move(x, y, z): precondition listON(x, y), CLEAR(z), ADJ(y, z) add listON(x, z), CLEAR(y) delete listON(x, y), CLEAR(z) 45

(1) Removing CLEAR(z) and ADJ(y, z) gives “# tiles out of place”. Misplaced distance is 1+1=2 moves

(2) Removing CLEAR(z) gives “Manhattan distance”. Manhattan distance is 6+3=9 moves

Pattern Database Heuristics The idea behind pattern database heuristics is to store exact solution costs for every possible sub-problem instance. The idea behind pattern database heuristics is to store exact solution costs for every possible sub-problem instance. 48

Solve part of the problem, ignoring the other tiles

50 Pattern Databases optimal solution cost of the subproblem <= optimal solution cost of the full problem. Run exhaustive search to find optimal solutions for every possible configuration of 3, 7, 11, 12, 13, 14, 15, and store the resulting path costs Do the same for the other tiles and space (maybe in two subsets) Do this once before any problem solving is performed. Expensive, but can be worth it, if the search will be applied to many problem instances (deployed)

Pattern Databases In our example, we have three subproblems (subsets of 7, 4, and 4 tiles) State S has specific configurations of those subsets h(s)? 51

h(s)? Look up the exact costs for s’s configurations of the 7, 4, and 4 subsets of tiles in the database Take the max! The max of a set of admissible heuristics is admissible What if it isn’t feasible to have entries for all possibilities? …. 52

What if it isn’t feasible to have entries for all possibilities? …. Take the max of: –The exact costs we do have, and the Manhattan distance for those we don’t have 53

Sums of admissible heurstics We would like to take the sum rather than the max, since the result is more informed In general, adding two admissible heuristics might not be admissible For example, moves that solve one subproblem might help another subproblem But we can choose patterns that are disjoint, so we can sum them 54

Disjoint Pattern Database Heuristics Patterns that have no tiles in common. (As in our example) When calculating costs for a pattern, only count moves of the tiles in the pattern Patterns that have no tiles in common. (As in our example) When calculating costs for a pattern, only count moves of the tiles in the pattern Add together the heuristic values for the individual patterns. Add together the heuristic values for the individual patterns. The sum is admissible and more informed than taking the max The sum is admissible and more informed than taking the max 55

Examples for Disjoint Pattern Database Heuristics moves needed to solve red tiles 25 moves needed to solve blue tiles Overall heuristic is sum, or 20+25=45 moves 56

Overall heuristic is sum of the Manhattan Distance of each tile which is 39 moves. A trivial example of disjoint pattern database heuristics is Manhattan Distance in the case that we view every tile as a single pattern database 57

58 Other Sources of Heuristics Ad-hoc, informal, rules of thumb (guesswork) Approximate solutions to problems (algorithms course) Learn from experience (solving lots of 8-puzzles) (later in this course)

Wrap Up The material in these notes is covered in R&N The exam will be concerned only with the treesearch, not the graphsearch, versions of the heuristic search algorithms; any question concerning the graphsearch versions will be about the uninformed algorithms Detail to bring out: we assumed in these and the previous notes that all edge costs exceed some finite positive value e; that b (the branching factor) and h-values are finite; and f values are nondecreasing along any path. IDA* is optimal in terms of solution time and space for admissible heuristic tree searches. Further reading (not required): R.E. Korf, Depth-First Iterative-Deepening: An Optimal Admissible Tree Search A* time and space complexity: Order roughly the number of nodes with f(n) smaller than the cost of the optimal path 59