Download Problem-Solving A* and Beyond

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Inverse problem wikipedia , lookup

Computational complexity theory wikipedia , lookup

Multiple-criteria decision analysis wikipedia , lookup

Corecursion wikipedia , lookup

Travelling salesman problem wikipedia , lookup

Signal-flow graph wikipedia , lookup

Beta (finance) wikipedia , lookup

Transcript
Problem-Solving: A* and
Beyond
CSCI 3202, Fall 2010
Administrivia
• Reading for this week: 4.1.1-4.1.3 (up to p.
126) in R+N; 5.1-5.4 (pp. 161-176)
• Problem Set 1 will be posted by tomorrow
morning; due September 23 in class. HARD
COPY ONLY, please.
The Basic Idea Behind A* Search
1) 2) 3) 4) Devise an "estimation" function, h, that gives you a plausible
underestimate of the distance from a given state to the goal.
Call the cost of getting from the initial state to the current state g.
To measure the quality of a given state s, sum the cost (g) of arriving
at this state and the estimate (h) of the cost required to get from s to
the goal.
Use best-first search, where g+h is the overall quality function.
How do you estimate distance to the goal? (Or: What’s that “h” function?)
Try to find a metric that will be a close (informative) one,but
that won’t overestimate (it should be optimistic).
Example: 8-9 puzzle
Number of misplaced tiles
Sum of Manhattan distance of misplaced tiles (better)
Best solution length for (say) tiles 1-4
Example: Choosing a path on a map from city A to B
Euclidean distance to B.
AStar-Best-First-Search [Nodes]
IF there are no more nodes THEN FAIL
ThisNode <-- First(Nodes)
IF ThisNode is the goal THEN return ThisNode
ELSE ChildNodes <-- Children(ThisNode)
Astar-Best-First-Search (Sort-by-Lowest-Cost-plus-Estimate
ChildNodes Remove-Node(ThisNode Nodes))
A few handy heuristics
• Redefine the “edges” (moves) of the problem
graph, as by chunking (e.g., Rubik’s cube)
• Eliminate chunks of the problem graph, as by
constraints (e.g., SEND+MORE = MONEY
problem)
• Decompose the problem into subproblems
(Rubik’s cube again; or Rush Hour)
Means-Ends Analysis
A technique for finding the next step to take
in a search process. Here, we find the most
important difference between our current state
and the goal state and use that difference
(recursively) to dictate our next move. To SOLVE a problem: If the current state is the goal state,
then we’re done. If not, first REDUCE the difference between
the current state and goal state to produce a new current state.
Then SOLVE the problem from the (presumably better)
current state and the original goal.
To REDUCE the difference between the current state and the
goal state, find the most important difference between the
current state and the goal state. Find an operator that tends to
reduce that difference, and APPLY that operator to the current
state. To APPLY an operator to the current state, see if there are any
differences between the current state and any preconditions
for the operator. If there are, REDUCE the difference between
the current state and the preconditions for the operator. If not
return the result of APPLYing the operator directly to the
current state.
Local search
• Up until now, we’ve imagined a two-phase
method: find a solution path (search the
problem space graph), and then return that
path so that it can be executed. In local
search, we simply search the graph directly,
hoping to land on a goal state. • Two simple methods: hill-climbing and
beam search.
Hill-Climb [Current-Node]
IF Current-Node is the goal
THEN return Current-Node
ELSE
ChildNodes  Children (Current-Node)
BestChild  LooksBest (ChildNodes)
Hill-Climb [BestChild]
Beam-Search [Set-of-Nodes]
If Set-of-Nodes contains a goal state
THEN return that state
ELSE
AllChildNodes  Find-All-Children (Set-of-Nodes)
BestNChildren  N-Best-Looking (AllChildNodes)
Beam-Search (BestNChildren)
An Example of Hill-Climbing:
the Word Arithmetic Problem
Let each node of the problem space graph be a candidate
solution:
SD*ENM*OYR
0123456789
Each edge from this node leads to a node in which two
assignments have been switched:
SY*ENM*ODR
0123456789
Hill-Climbing Example,
Continued
Now we hill-climb by starting at some
candidate solution and moving to the
adjacent solution that causes the fewest
arithmetic errors. Problem-Solving: The Cognitive Side
• Do we actually use (say) depth-first search?
Or breadth-first search? Or A*?
• Is the problem-space formalism useful,or
natural?
• How do we solve problems, anyhow?
"A man gets an unsigned letter telling him to go to the local graveyard at
midnight. He does not generally pay attention to such things, but complies
out of curiosity. It is a deathly still night, lighted by a thin crescent moon.
The man stations himself in front of his family's ancestral crypt. The man is
about to leave when he hears scraping footsteps. He yells out, but no one
answers. The next morning, the caretaker finds the man dead in front of the
crypt, a hideous grin on his face.
Did the man vote for Teddy Roosevelt in the 1904 U.S. presidential
election?"
-- Poundstone
Hanging from the ceiling are two lengths of string, each six feet long. The
strings are ten feet apart. As the room is ten feet high, the lower ends of the
strings hang four feet above the floor.
On the floor is a Swiss Army knife, a firecracker, a small glass of water, a
twenty-five pound block of ice in an aluminum pan, and a friendly Labrador
retriever.
Your job is to tie the two ends of the two strings together.
-- based on Poundstone,
"Labyrinths of Reason"
All astronomers are stamp collectors.
No baseball players are astronomers.
∴ ???
Other ways of looking at the "search" issue;
"insight" problems
• Retrieving schemas/searching for patterns
• Restructuring the problem space itself
• Functional fixedness and the "Einstellung" effect
Two Physics Problems
Rolling a quarter around another quarter...
Elastic collision (ping-pong vs. bowling ball)
Mr. Smith and his wife invited four other couples for a
party. When everyone arrived, some of the people in the
room shook hands with some of the others. Of course,
nobody shook hands with their spouse and nobody shook
hands with the same person twice.
After that, Mr. Smith asked everyone how many times they
shook someone’s hand. He received different answers from
everybody.
How many times did Mrs. Smith shake someone’s hand?
From Michalewicz and Fogel, How to Solve It: Modern Heuristics
Game-Playing: the Essential
Arsenal
• The idea of a “minimax search”
• Avoiding useless search: the alpha-beta
algorithm
• Other ways of pruning the search tree
• Other central issues in game-playing
The Game of Sim
In Scheme:
(define (minimax gamestate myfunction otherfunction level)
(cond ((= level 0) (getvalue gamestate))
(else
(let* ((successors (getnextmoves gamestate))
(othervals
(map (lambda (successor)
(minimax successor otherfunction
myfunction (- level 1)))
successors)))
(apply myfunction othervals)))))
(define (alpha-beta alpha beta level node max?)
(cond ((= level 0) (static-value node))
(max?
(let ((children (find-next-moves node #t)))
(max-look-at-each-child-node
children alpha beta level)))
(else
(let ((children (find-next-moves node #f)))
(min-look-at-each-child-node
children alpha beta level)))))
(define (max-look-at-each-child-node children alpha beta level)
(cond ((null? children) alpha)
((>= alpha beta) alpha)
(else (let ((next-value
(alpha-beta
alpha beta (- level 1) (first children) #f)))
(max-look-at-each-child-node
(rest children)
(max next-value alpha)
beta level)))))
(define (min-look-at-each-child-node children alpha beta level)
(cond ((null? children) beta)
((>= alpha beta) beta)
(else (let ((next-value
(alpha-beta
alpha beta (- level 1) (first children) #t)))
(min-look-at-each-child-node
(rest children)
alpha (min next-value beta) level)))))
Calling alpha-beta with starting values of a (very low)
alpha value, a (very high) beta value, a depth of 5, the
starting game state, and from the point of view of the
maximizer.
(alpha-beta -1000 1000 5 initial-game-state #t)