Searching for Solutions

CS4700 (Summer 2014!)
Foundations of Artificial Intelligence
Searching for Solutions
Jon Park
DEPARTMENT OF COMPUTER SCIENCE
CORNELL UNIVERSITY
Agenda
‒ Review
‒ Search Problem Formulation
‒ Searching for Solutions
Agenda
‒ Review
‒ Search Problem Formulation
‒ Searching for Solutions
Perspectives of AI
Acting
Thinking
Human-like
4
Thinking
Humanly
Acting
Humanly
Rational
Thinking
Rationally
Acting
Rationally
Perspectives of AI
Acting
Thinking
Human-like
5
Thinking
Humanly
Acting
Humanly
Rational
Thinking
Rationally
Acting
Rationally
How does an agent meet the goal?
9
Agenda
‒ Review
‒ Search Problem Formulation
‒ Searching for Solutions
Search Problem Formulation
1.
2.
3.
4.
states (State space) - e.g. cities
initial state - e.g. Ithaca
actions – e.g. drive to a nearby city
transition model – e.g. current city changes
Transition(state1, action) = state2
5. goal test (or set of goal states) – e.g. destination cities
6. path cost (additive) - e.g. total distance traveled
Sum of step costs c(state,action,state) ≥ 0
A solution is a sequence of actions leading from the initial
state to a goal state
Example: Vacuum-cleaner
Vacuum world state space graph
•
•
•
•
•
states?
Initial state?
actions?
goal test?
path cost?
Vacuum world state space graph
• states? The agent is in one of 2 locations, with or
without dirt.
• Initial state? Agent in location 1, dirt everywhere!
• actions? Left, Right, Suck
• goal test? no dirt at all locations?
• path cost? Number of movements
Vacuum world state space graph
• states? The agent is in one of 2 locations, with or
without dirt. [2 x 22]
• Initial state? Agent in location 1, dirt everywhere!
• actions? Left, Right, Suck
• goal test? no dirt at all locations?
• path cost? Number of movements
Example: Robot Assembly
•
•
•
•
•
States:
Initial state:
Actions:
Goal test:
Path Cost:
Example: 8-puzzle
•
•
•
•
•
states ?
initial state?
actions?
goal test?
path cost?
Example: 8-puzzle
•
•
•
•
states? locations of tiles
initial state? given
actions? move blank left, right, up, down
goal test? Are the tiles corrected located (as the
goal state)
• path cost? Number of moves
Example: 8-puzzle
•
•
•
•
states? locations of tiles [9!]
initial state? given
actions? move blank left, right, up, down
goal test? Are the tiles corrected located (as the
goal state)
• path cost? Number of moves
A Water Jug Problem
• You have a 4gallon and a 3gallon water jug
• You have a faucet
with an unlimited
amount of water
• You need to get
exactly 2 gallons
in 4-gallon jug
Example : water jug problem
• States:
•
•
•
•
initial state:
Actions:
goal test:
path cost:
Example : water jug problem
• States: (x, y)
(Amount of water in 4 gallon jug, 3 gallon jug)
• initial state: (0, 0)
• Actions: Pour water into a jug from another jug or
the faucet (the pouring stops when the jug is full)
• goal test: One of the jugs has 2 gallons of water?
• path cost: Number of moves
Does formulation matter?
25
8-Queens Problem
Place 8 queens in a chessboard so that no two queens
are in the same row, column, or diagonal.
A solution
Not a solution
Formulation #1
 States: all arrangements of 0, 1, 2,
..., 8 queens on the board
 Initial state: 0 queens on the board
 Action: each of the successors is
obtained by adding one queen in an
empty square
 Goal test: 8 queens are on the
board, with no queens attacking
each other
 Path cost: Number of states visited
(tried)
 ~ 64x63x...x57 ~ 3x1014 states
Formulation #2
 2,057 states
 States: all arrangements of k = 0, 1,
2, ..., 8 queens in the k leftmost
columns with no two queens
attacking each other
 Initial state: 0 queens on the board
 Action: each successor is obtained
by adding one queen in any square
that is not attacked by any queen
already in the board, in the leftmost
empty column
 Goal test: 8 queens are on the
board
 Path cost: Number of states visited
(tried)
n-Queens Problem
 Number of states in state space:
• 8-queens  2,057
• 100-queens  1052
 But techniques exist to solve n-queens problems
efficiently for large values of n
They exploit the fact that there are many solutions
well distributed in the state space
Path Planning
What is the state space?
Formulation #1
Cost of one horizontal/vertical step = 1
Cost of one diagonal step = 2
Optimal Solution
This path is the shortest in the discretized state
space, but not in the original continuous space
Formulation #2
sweep-line
Formulation #2
States
Successor Function
Solution Path
A path-smoothing post-processing step is
usually needed to shorten the path further
Formulation #3
Cost of one step: length of segment
Formulation #3
Cost of one step: length of segment
Solution Path
The shortest path in this state space is also the
shortest in the original continuous space
Does formulation matter?
Yes!
(in terms of efficiency, optimality, etc.)
41
Agenda
‒ Review
‒ Search Problem Formulation
‒ Searching for Solutions
Tree-based Search
• Basic idea:
– Exploration of state space by generating successors of
already-explored states (a.k.a. expanding states).
– Every state is evaluated: is it a goal state?
• In practice, the solution space can be a graph, not a
tree
Tree-based Search
• Basic idea:
– Exploration of state space by generating successors of
already-explored states (a.k.a. expanding states).
– Every state is evaluated: is it a goal state?
• In practice, the solution space can be a graph, not a
tree
– E.g., 8-puzzle
– More general approach is graph search
– Tree search can end up repeatedly visiting the same nodes
• Unless it keeps track of all nodes visited
• …but this could take vast amounts of memory
Example: Romanian Cities
Example: Romanian Cities
Example: Romanian Cities
Example: Romanian Cities
This “strategy” is
what differentiates
different search
algorithms
Example: 8 puzzle
Search trees
= data structure to search state-space
• State Space
– Set of valid states for a problem
– Linked by Actions (incurring costs)
– e.g., 20 valid states (cities) in the Romanian travel problem
• Search Tree
– Root node = initial state
– Child nodes = states that can be visited from parent
– Note that the depth of the tree can be infinite
• E.g., via repeated states
– Partial search tree
• Portion of tree that has been expanded so far
– Fringe
• Leaves of partial search tree, candidates for expansion
51
Search Strategies
• A search strategy is defined by picking the order of
node expansion
• Strategies are evaluated along the following
dimensions:
–
–
–
–
completeness: does it always find a solution if one exists?
time complexity: number of nodes generated
space complexity: maximum number of nodes in memory
optimality: does it always find a least-cost solution?
• Time and space complexity are measured in terms of
– b: maximum branching factor of the search tree
– d: depth of the least-cost solution
– m: maximum depth of the state space (may be ∞)