V03 ProblemSolvingThroughSearch
V03 ProblemSolvingThroughSearch
Based on material by
• Stuart Russell, UC Berkeley
• Inês de Castro Dutra, Cooperating Intelligent Systems, U. Porto
“In which we see how an agent can look ahead to find a sequence of actions
that will eventually achieve its goal.”
Initial state
• Currently in Arad
Formulate goal
• be in Bucharest
Formulate problem
• states: various cities
• actions: drive between cities
Find solution
• Sequence of cities, e.g., Arad→Sibiu→Fagaras→Bucharest
• How? See later
Real-world problem
Robotic
assembly
• States? real-valued coordinates of robot joint angles; parts to be assembled
• Actions? continuous motions of robot joints
• Goal test? complete assembly
• Path cost? execution time
Air-travel planning:
much more
complicated than in-
car navigation!
All TSP-related
problems of finding
a shortest path
• Suitable environments: fully observable, deterministic, discrete (episodic, static, single agent)
Extensions of today’s methods exist to non-deterministic and partially observable as
well as (semi-)dynamic environments (online search) (→ see AIMA, ch. 4.3-4.5)
Heuristic (informed) search
• Knows whether one non-goal state is “more promising” than another
• Suitable environments: as above, but larger
• Cares only to find a goal state rather then the optimal path
• Suitable environments: also, continuous state/action spaces (hill climbing, simulated annealing)
Adversarial search
• Search in the face of an opponent (i.e., dynamic multi-agent environments; also, stochastic and
partially observable forms)
Approach
• Tree search: iteratively expand nodes until a goal node is hit
• Different strategies: order of node expansion
Practical advice
• Depth-first tree search is a major work horse for many AI tasks (due to linear space
complexity)
• Iterative deepening is not wasteful (a tree with nearly the same 𝑏 at each level has most nodes
in the bottom level ➔ generating higher-level states multiple times doesn’t matter)
• Iterative deepening is preferred uninformed search method
(for large search space and 𝑑 is unknown)
• Bi-directional search can help a lot, but 𝑂(𝑏 𝑑/2 ) space complexity is major drawback
Best-first search
• Select the node to be expanded next based on some evaluation function 𝑓(𝑛𝑜𝑑𝑒)
• Typically, 𝒇 is implemented by a heuristic ℎ(𝑛𝑜𝑑𝑒) (measure of “desirability”)
• ℎ(𝑛𝑜𝑑𝑒) facilitates pruning of the search tree: options are eliminated without examination
What could be a good heuristic for the distance to Bucharest (being in Arad)?
Greedy search
• Expand node with lowest subsequent cost estimate according to some ℎ, i.e., 𝑓(𝑛) = ℎ(𝑛)
• 𝑛 may only appear to be closest to the goal
A*
• Obvious improvement: consider full path cost, i.e., 𝑓 𝑛 = 𝑔 𝑛 + ℎ(𝑛)
(𝑔(𝑛) cost so far to reach 𝑛, ℎ(𝑛) estimated cost to goal from 𝑛, 𝑓(𝑛) estimated total path cost)
• ℎ(𝑛) needs to be admissible (see later): ≤ 𝑡𝑟𝑢𝑒 𝑐𝑜𝑠𝑡 and ≥ 0 (e.g., ℎ𝑠𝑡𝑟𝑎𝑖𝑔ℎ𝑡 𝑙𝑖𝑛𝑒 𝑑𝑖𝑠𝑡𝑎𝑛𝑐𝑒 )
• A* search is optimal, complete
• A* has time complexity 𝑂(2 𝑒𝑟𝑟𝑜𝑟 𝑜𝑓 ℎ ⋅𝑑
) and keeps all nodes in memory
Learning to search
• Learn a heuristic function: use inductive supervised learning on features of a state
• Alternative: construct a metalevel state space, consisting of all internal states of search program
Example: For A* searching for a route in Romania, the search tree is its internal state
• Actions in metalevel space: computations that alter the metalevel state
In the example: Expanding a node
• Solution in metalevel space: a path as depicted on the last slide
➔ can be input to machine learning algorithms to avoid unnecessary expansions
Practical advice
• A* is impractical for large scale problems
• Practical, robust choice: SMA*
• Have good heuristic functions! A well-designed heuristic would have 𝑏 ∗ ≈ 1
(𝑏 ∗ is the effective branching factor)
ℎ1 𝑆 = 6
ℎ2 𝑆 = 4 + 0 + 3 + 3 + 1 + 0 + 2 + 1 = 14
Simple improvement
• Given any admissible heuristics ℎ𝑎 , ℎ𝑏 :
• ℎ(𝑛) = max ℎ𝑎 𝑛 , ℎ𝑏 𝑛 is also admissible and dominates ℎ𝑎 , ℎ𝑏
Relaxation as a key
• Admissible heuristics can be derived from the exact solution cost of a relaxed version
of the problem
• A relaxed problem has fewer constraints on the actions
• Relaxation can be automatized!
E.g., «Absolver» by (Prieditis, 1993) found best heuristic for 8-puzzle, first heuristic for Rubik’s cube
Intuition
• Removing constraints adds edges to the state graph
• Additional edges might provide „short cuts“
• The optimal solution cost of a relaxed problem (“short cut”) can be no greater than the
optimal solution cost of the real problem
Uninformed search
• In the abstraction of the problem
• In the choice of algorithm that is optimal for the problem at hand
• In the systematic exploration of the state space graph
Heuristic search
• Additionally, in the heuristic function
→ see also: Polya, «How to solve it - a new aspect of mathematical method», 1945
• Why do you think people have a hard time solving this puzzle,
given that the state space is so simple?
➔ Were it not for the ability to construct useful abstractions, intelligent agents would be
completely swamped by the real world
More terminology
• NP-hard – a problem 𝑥 is said to be NP-hard if all problems in NP can be reduced to (i.e., converted
into / stated as) 𝑥 (i.e., can be solved by an algorithm for 𝑥) efficiently
→ Example: Traveling salesman problem (i.e., any problem in NP is at most as hard as 𝑥)
• NP-complete – a problem 𝑥 is said to be NP-complete if it is NP-hard and in NP
→ Example: The satisfiability problem (SAT) – is there an assignment of truth values to make a given formula of
propositional logic true? (→ see V06 and AIMA ch. 7.5)
…which is all good (i.e., we don’t have to care for efficiency) if 𝑃 = 𝑁𝑃 (tremendously unlikely!)
Further reading
• AIMA appendix A.1 (< 3 pages!)
• J. Koehler’s lecture slides on complexity and AI: https://user.enterpriselab.ch/~takoehle/teaching/ai/ProblemComplexity.pdf
• Some more intuition: http://stackoverflow.com/questions/1857244/what-are-the-differences-between-np-np-complete-and-np-hard
Problem
• Failure to detect repeated states can turn a linear problem into an exponential one!
Solution
• Graph search: remember nodes already expanded, and don’t revisit them
➔ keep a list of explored nodes
Practical advice
• All previous strategies can be implemented as both tree- or graph search
• If additional space complexity is affordable determines whether graph search is possible
➔ Bold italic font shows the additions that handle repeated states in graph search
States
• 𝜃 = (𝑀, 𝐶, 𝐵) signifies the number of missionaries, cannibals, and boats on the left bank
• The start state is (3,3,1) and the goal state is (0,0,0)
Source: http://www.cse.msu.edu/~michmer3/440/Lab1/cannibal.html
• Assumes that passengers have to get out of the boat after the trip
• Red states = missionaries get eaten