Presentation is loading. Please wait.

Presentation is loading. Please wait.

Last bit on A*-search.. 8 Puzzle I  Heuristic: Number of tiles misplaced  Why is it admissible?  h(start) =  This is a relaxed- problem heuristic.

Similar presentations


Presentation on theme: "Last bit on A*-search.. 8 Puzzle I  Heuristic: Number of tiles misplaced  Why is it admissible?  h(start) =  This is a relaxed- problem heuristic."— Presentation transcript:

1 Last bit on A*-search.

2 8 Puzzle I  Heuristic: Number of tiles misplaced  Why is it admissible?  h(start) =  This is a relaxed- problem heuristic 8 Average nodes expanded when optimal path has length… …4 steps…8 steps…12 steps UCS1126,3003.6 x 10 6 TILES 1339227

3 8 Puzzle II  What if we had an easier 8-puzzle where any tile could slide any direction at any time, ignoring other tiles?  Total Manhattan distance  Why admissible?  h(start) = 3 + 1 + 2 + … = 18 Average nodes expanded when optimal path has length… …4 steps…8 steps…12 steps TILES 1339227 MANHATTAN 122573 [demo: eight-puzzle]

4 8 Puzzle III  How about using the actual cost as a heuristic?  Would it be admissible?  Would we save on nodes expanded?  What’s wrong with it?  With A*: a trade-off between quality of estimate and work per node!

5 Trivial Heuristics, Dominance  Dominance: h a ≥ h c if  Heuristics form a semi-lattice:  Max of admissible

6 Graph Search

7 Tree Search: Extra Work!  Failure to detect repeated states can cause exponentially more work. Why?

8 Graph Search  In BFS, for example, we shouldn’t bother expanding the circled nodes (why?) S a b d p a c e p h f r q qc G a q e p h f r q qc G a

9 Graph Search  Very simple fix: never expand a state twice

10 Graph Search  Idea: never expand a state twice  How to implement:  Tree search + list of expanded states (closed list)  Expand the search tree node-by-node, but…  Before expanding a node, check to make sure its state is new  Python trick: store the closed list as a set, not a list  Can graph search wreck completeness? Why/why not?  How about optimality?

11 Consistency A C S 1 1 h = 4 h = 1 h = 6  What went wrong?  Taking a step must not reduce f value! B h = 0 G h = 1 1 2 3

12 Consistency  Stronger than admissability  Definition:  C(A→C)+h(C) ≧ h(A)  C(A→C) ≧ h(A)-h(C)  Consequence:  The f value on a path never decreases  A* search is optimal A G 1 h = 4 h = 0 C h = 1 3

13 Consistency  Are we optimal yet?  No:  We must not pop some node n, and find its child n’ to have lower f value!  What can we require to prevent these inversions?  Consistency:  Real cost must always exceed reduction in heuristic A B G 3 h = 0 h = 10 g = 10 h = 8

14 Optimality of A* Graph Search Proof:  New problem (with graph instead of tree search): nodes on path to G* that would have been in queue aren’t, because some worse n’ for the same state as some n was dequeued and expanded first (disaster!)  Take the highest such n in tree  Let p be the ancestor which was on the queue when n’ was expanded  Assume f(p) ≦ f(n) (consistency!)  f(n) < f(n’) because n’ is suboptimal  p would have been expanded before n’  So n would have been expanded before n’, too  Contradiction!

15 Optimality  Tree search:  A* optimal if heuristic is admissible (and non- negative)  UCS is a special case (h = 0)  Graph search:  A* optimal if heuristic is consistent  UCS optimal (h = 0 is consistent)  Consistency implies admissibility  In general, natural admissible heuristics tend to be consistent

16 Summary: A*  A* uses both backward costs and (estimates of) forward costs  A* is optimal with admissible heuristics  Heuristic design is key: often use relaxed problems

17 Quiz 2 : A* search  T/F: A* is optimal with any h().False  T/F: A* is complete with any h(). True  T/F: A* with the zero heuristic is UCS. True  T/F: Admissibility implies consistency. False  T/F: If n’ is a sub-optimal path to n, then f(n)<f(n’) for any heuristic. Trueh(n)=h(n’) but g(n)<g(n’)  T/F: Admissibility is necessary for Graph-Search to be optimal. True (All heuristics are are non-negative and bounded by some B, i.e. h(x) ≦ B.)

18 Search Recap Uniform Cost Search / BFS Greedy Search / DFS A* Search

19 A* applications  http://pacman.elstonj.com/index.cgi?dir=vi deos&num=&perpage=&section= http://pacman.elstonj.com/index.cgi?dir=vi deos&num=&perpage=&section  http://www.youtube.com/watch?feature=pl ayer_embedded&v=JnkMyfQ5YfY#! http://www.youtube.com/watch?feature=pl ayer_embedded&v=JnkMyfQ5YfY#

20 CSE 511A: Artificial Intelligence Spring 2013 Lecture 4: Constraint Satisfaction Programming Jan 29, 2012 Robert Pless, slides from Kilian Weinberger, Ruoyun Huang, adapted from Dan Klein, Stuart Russell or Andrew Moore

21 Announcements  Projects:  Project 1 out. Due Thursday 10 days from now, midnight. 21

22 1.What is a CSP?

23 What is Search For?  Models of the world: single agents, deterministic actions, fully observed state, discrete state space  Planning: sequences of actions  The path to the goal is the important thing  Paths have various costs, depths  Heuristics to guide, fringe to keep backups  Identification: assignments to variables  The goal itself is important, not the path  All paths at the same depth (for some formulations)  CSPs are specialized for identification problems 23

24 Search Problems  A search problem consists of:  A state space  A successor function  A start state and a goal test  A cost function (for now we set cost=1 for all steps)  A solution is a sequence of actions (a plan) which transforms the start state to a goal state “N”, 1.0 “E”, 1.0

25 One Example  Schedule Lectures at Washburn University Time-table: Lop101 Jolley 305 9:00 10:00 11:00 12:00 13:00 14:00 Courses: -A: Intro to AI -B: Bioinformatics -C: Computational Geometry -D: Discrete Math Constraints: -Only one course per room / slot -Each course meets one two hours slot -A can only be in Jelly 204 -B must be scheduled before noon -D must be in the afternoon

26 Search Problem  State Space:  (partially filled in) time schedule  Successor Function:  Assign time slot to unassigned course  Start State:  Empty schedule  Goal test:  All constraints are met  All courses scheduled Time-table: Lap101 Jelly 204 9:00 10:00 11:00 12:00 13:00 14:00 A A B B C C D D

27 Naïve Search Tree A A A A A A B B B B B B B B B B B B A A A A A A Tree is gigantic! Depth? Width? Where is a solution?

28 Constraint Satisfaction Problems  Standard search problems:  State is a “black box”: arbitrary data structure  Goal test: any function over states  Successor function can be anything  Constraint satisfaction problems (CSPs):  A special subset of search problems  State is defined by variables X i with values from a domain D (sometimes D depends on i )  Goal test is a set of constraints specifying allowable combinations of values for subsets of variables  Path cost irrelevant!  Simple example of a formal representation language  Allows useful general-purpose algorithms with more power than standard search algorithms 28 CSPs Search Problems

29 Example 1: Map-Coloring  Variables:  Domain:  Constraints: adjacent regions must have different colors  Solutions are assignments satisfying all constraints, e.g.: 29 Implicit: Explicit: -or-

30 Constraint Graphs  Binary CSP: each constraint relates (at most) two variables  Binary constraint graph: nodes are variables, arcs show constraints  General-purpose CSP algorithms use the graph structure to speed up search. E.g., Tasmania is an independent subproblem! 30

31 Example 2: Cryptarithmetic  Variables:  Domains:  Constraints (boxes): 31

32 Example 2: Cryptarithmetic II  Variables:  Domains:  Constraints: 32 T, W, O, F, U, R (T * 100 + W * 10 + O) * 2= F * 1000 + O * 100 + U * 10 + R

33 Example 3: N-Queens  Formulation 1:  Variables:  Domains:  Constraints 33

34 Example 3: N-Queens  Formulation 1.5:  Variables:  Domains:  Constraints: … there’s an even better way! What is it? Implicit: Explicit: -or-

35 Example 3: N-Queens  Formulation 2:  Variables:  Domains:  Constraints: Implicit: Explicit: -or-

36 Example 4: Sudoku  Variables:  Each (open) square  Domains:  {1,2,…,9}  Constraints: 9-way alldiff for each row 9-way alldiff for each column 9-way alldiff for each region Check out Peter Norvig’s homepage http://norvig.com/sudoku.htmlhttp://norvig.com/sudoku.html

37 Example 5: The Waltz Algorithm  The Waltz algorithm is for interpreting line drawings of solid polyhedra  An early example of a computation posed as a CSP  First, look at all intersections ? 37 Four types of junctions: L, fork, T, arrow

38 Waltz on Simple Scenes  3 Types of Lines:  Boundary line (edge of an object) (  ) with right hand of arrow denoting “solid” and left hand denoting “space”  Interior convex edge (+)  Interior concave edge (-)  4 types of junctions  L, fork, T, arrow  Adjacent intersections impose constraints on each other 38 All the valid conjunction labeling:

39 Legal Junctions  Only certain junctions are physically possible  How can we formulate a CSP to label an image?  Variables: vertices  Domains: junction labels  Constraints: both ends of a line should have the same label x y (x,y) in,, … 39 All the valid conjunction labeling

40 Waltz on Simple Scenes  Variable (edges): (AB, AC, AE, BA, BD, …, )  Domain: {+,-, ,  }  Constraints (both ends have the same label): arrow (AC, AE, AB), fork(BA, BF, BD), L(CA, CD), arrow(DG, DC, DB), … L Junctions fork Junctions arrow Junctions All the valid conjunction labeling

41 Waltz on Simple Scenes At least 4 valid labeling choices

42 Example 6: Temporal Logic Reasoning  Problem: The meeting ran non-stop the whole day. Each person stayed at the meeting for a continuous period of time. Ms White arrived after the meeting has began. In turn, Director Smith was also present but he arrived after Jones had left. Mr. Brown talked to Ms. White in presence of Smith. Could possibly Jones and White have talked during this meeting? 42

43  Possible Relations: before, meets, overlap, start, during, finish, equal truly-overlap()= overlaps + overlaps-by + starts + started-by + during + contains+ finishes+ finished-by + equal 43 Example 6: Temporal Logic Reasoning

44 1.Ms White arrived after the meeting has began. during(W,M) or finishes(W,M) or equals(W,M) 2.Director Smith was also present but he arrived after Jones had left. after(S, J) 3.Mr. Brown talked to Ms. White in presence of Smith. truly-overlap(B,M), truly-overlap(B,S), truly-overlap(W,S) 4.Could possibly Jones and White have talked during this meeting? truly-overlap(J,W) Event(s)Variable(s) The duration of the meetingM The period Jones, Brown, Smith, White was presentJ, B, S, W 44

45 Real-World CSPs  Assignment problems: e.g., who teaches what class  Timetabling problems: e.g., which class is offered when and where?  Hardware configuration/verification  Transportation scheduling  Factory scheduling  Floorplanning  Fault diagnosis  … lots more!  Many real-world problems involve real-valued variables… 45

46 Varieties of CSPs  Discrete Variables  Finite domains (Most cases!)  Size d means O(d n ) complete assignments  E.g., Boolean CSPs, including Boolean satisfiability (NP-complete)  Infinite domains (integers, strings, etc.)  E.g., our temporal logic reasoning  Linear constraints solvable, nonlinear undecidable  Continuous variables  E.g., start/end times for Hubble Telescope observations  Linear constraints solvable in polynomial time by LP methods (see ESE505 Operation Research for a bit of this theory)  There might be objective functions:  Branch-and-Bound method 46

47 Varieties of Constraints  Varieties of Constraints  Unary constraints involve a single variable (equiv. to shrinking domains):  Binary constraints involve pairs of variables:  Higher-order constraints involve 3 or more variables: e.g., 9-way different constraints in sudoku  Preferences (soft constraints):  E.g., red is better than green  Often representable by a cost for each variable assignment  Gives constrained optimization problems  (We’ll ignore these until we get to Bayes’ nets) 47

48 Modeling Constraint Programming  Choose the right representation  Consider adjacency matrix and adjacency list  Avoid global constraints  CSP solver can handle them automatically  Choose the right variable and constraints  Makes difference even in our earlier toy examples  Read the solver’s manual!

49 2. How can we solve CSPs fast? By taking advantage of their specific structure!

50 CSP problem Solving: Outline  Backtracking search  Branching strategies  Forward Checking  Constraint Propagation

51 Standard Search Formulation  Standard search formulation of CSPs (incremental)  Let's start with the straightforward, dumb approach, then fix it  States are defined by the values assigned so far  Initial state: the empty assignment, {}  Successor function: assign a value to an unassigned variable  Goal test: the current assignment is complete and satisfies all constraints  Simplest CSP ever: two bits, constrained to be equal 51

52 Search Methods  What does BFS do?  What does DFS do?  What’s the obvious problem here?  The order of assignment does not matter.  What’s the other obvious problem?  We are checking constraints too late. 52

53 Search Methods  What does BFS do?  What does DFS do?  [demo]  What’s the obvious problem here?  What’s the slightly-less-obvious problem? 53

54 Backtracking Search  Idea 1: Only consider a single variable at each point  Variable assignments are commutative, so fix ordering  I.e., [WA = red then NT = green] same as [NT = green then WA = red]  Only need to consider assignments to a single variable at each step  How many leaves are there?  Idea 2: Only allow legal assignments at each point  I.e. consider only values which do not conflict previous assignments  Might have to do some computation to figure out whether a value is ok  “Incremental goal test”  Depth-first search for CSPs with these two improvements is called backtracking search (useless name, really)  Backtracking search is the basic uninformed algorithm for CSPs  Can solve n-queens for n  25 54

55 Backtracking Example 55  What are the choice points?

56 Improving Backtracking  General-purpose ideas can give huge gains in speed:  Which variable should be assigned next?  In what order should its values be tried?  Can we detect inevitable failure early?  Can we take advantage of problem structure? 56 WA SA NT Q NSW V

57 Which Variable: Minimum Remaining Values  Minimum remaining values (MRV):  Choose the variable with the fewest legal values  Why min rather than max?  Also called “most constrained variable”  “Fail-fast” ordering 57

58 Which Variable: Degree Heuristic  Tie-breaker among MRV variables  Degree heuristic:  Choose the variable participating in the most constraints on remaining variables  Why most rather than fewest constraints? 58

59 Which Value: Least Constraining Value  Given a choice of variable:  Choose the least constraining value  The one that rules out the fewest values in the remaining variables  Note that it may take some computation to determine this!  Why least rather than most?  Combining these heuristics makes 1000 queens feasible 59 Better choice


Download ppt "Last bit on A*-search.. 8 Puzzle I  Heuristic: Number of tiles misplaced  Why is it admissible?  h(start) =  This is a relaxed- problem heuristic."

Similar presentations


Ads by Google