Last bit on A*-search.. 8 Puzzle I Heuristic: Number of tiles misplaced Why is it admissible? ...
-
Upload
nathan-reed -
Category
Documents
-
view
216 -
download
1
Transcript of Last bit on A*-search.. 8 Puzzle I Heuristic: Number of tiles misplaced Why is it admissible? ...
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
8 Average nodes expanded when optimal path has length…
…4 steps …8 steps …12 steps
UCS 112 6,300 3.6 x 106
TILES 13 39 227
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 13 39 227
MANHATTAN 12 25 73[demo: eight-puzzle]
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!
Trivial Heuristics, Dominance
Dominance: ha ≥ hc if
Heuristics form a semi-lattice: Max of admissible
Graph Search
Tree Search: Extra Work!
Failure to detect repeated states can cause exponentially more work. Why?
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
q c G
a
qe
p
h
f
r
q
q c G
a
Graph Search
Very simple fix: never expand a state twice
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?
Consistency
A
CS
1
1h = 4
h = 1h = 6
What went wrong? Taking a step must not reduce f value!
B
h = 0
Gh = 11 2 3
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
Ch = 1 3
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!
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
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
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. True h(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.)≦
Search Recap
Uniform Cost Search / BFS
Greedy Search / DFS
A* Search
A* applications
http://pacman.elstonj.com/index.cgi?dir=videos&num=&perpage=§ion=
http://www.youtube.com/watch?feature=player_embedded&v=JnkMyfQ5YfY#!
CSE 511A: Artificial IntelligenceSpring 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
Announcements
Projects: Project 1 out. Due Thursday 10 days from now,
midnight.
21
1.What is a CSP?
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
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
One Example
Schedule Lectures at Washburn University
Time-table:
Lop101 Jolley 305
9:0010:0011:0012:0013:0014: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
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:0010:0011:0012:0013:0014:00
AABB
CCDD
Naïve Search Tree
AAAA
AABB
BBBB
BBBB
BBAA AA AATree is gigantic!Depth?Width?Where is a solution?
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 Xi 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
CSPsSearch
Problems
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-
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
Example 2: Cryptarithmetic
Variables:
Domains:
Constraints (boxes):
31
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
Example 3: N-Queens
Formulation 1: Variables: Domains: Constraints
33
Example 3: N-Queens
Formulation 1.5: Variables:
Domains:
Constraints:
… there’s an even better way! What is it?
Implicit:
Explicit:
-or-
Example 3: N-Queens
Formulation 2: Variables:
Domains:
Constraints:
Implicit:
Explicit:
-or-
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.html
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
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:
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
fork Junctions
arrow Junctions
All the valid conjunction labeling
Waltz on Simple Scenes
At least 4 valid labeling choices
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
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
Example 6: Temporal Logic Reasoning
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 meeting M
The period Jones, Brown, Smith, White was present J, B, S, W
44
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
Varieties of CSPs Discrete Variables
Finite domains (Most cases!) Size d means O(dn) 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
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
2. How can we solve CSPs fast?
By taking advantage of their specific structure!
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
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
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
Backtracking Example
55 What are the choice points?
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
WASA
NT Q
NSW
V
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
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
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