Prof. Radhika Nagpal School of Engineering and Applied Sciences Harvard University
Prof. Radhika Nagpal School of Engineering and Applied Sciences Harvard University
Prof. Radhika Nagpal School of Engineering and Applied Sciences Harvard University
AIMA3e 4.1 (skim 4.2)
Assignments
Asst 0 issues
Asst 1 due Friday (on informed/uninformed search)
Sections
Mandatory Sections this month….
Email list
Prof. Radhika Nagpal If you are not registered for the class yet, please come and talk
to me before end of class.
School of Engineering and Applied Sciences
Harvard University
Problem: Place 8 queens on 8x8 chess board, Problem: Place n queens on nxn chess board,
such that no two queens attack each other. such that no two queens attack each other.
State space is exponential in “n”
▪ even if you are smart…
How big is the search space? E.g. 1052 for 100 queens
Naïve state space = (64 choose 8) = 4, 426,165,368
One per row = 8^8= 16,777,216
Just permutations = 8! Systematic Search
Can get even smarter & prune ~ 15K! Systematically go through the state space and
remember the paths we took
Actual solutions? (priceless!) = 92 (12 “unique”)
What does the “search tree” look like?
What method would you use?
(We will look at this much more closely next week……)
Queen attacks in States: any arrangement of 0 to 8
row, column, diagonals queens on board with none attacked
Can we do better?
Successor: place a queen in the right‐
most empty column
s.t. it is not attacked by any other queen
1
New Search Strategy In many problems, its not the path to the solution that
State: All n‐queens on board matters, but the solution itself…
Successor: Any board that can be n‐queens
generated by moving one queen Airline crew scheduling
in a column
Evaluation: minimize conflicts
Travelling Salesman
Don’t bother remembering the past Protein folding
Performance
Metric: number of checks required to States: all 8 queens on the board
solve all n‐queens from 2 to 50
Systematic search (DFS‐like) > 40,000K Successor: move each queen within
its column to generate a state
With good heuristics > 13,000K (8x7 possibilities).
Today’s technique 4K!!!!!
Good state: fewer conflicts
In many problems, its not the path to the solution that
matters, but the solution itself…
Local Search
In that case we can
use a different search strategy
▪ Keep only the current state
▪ Check successors for a “better” state
Advantages: very little memory (no search tree!) and works in
large or infinite spaces, where systematic search fails
Disadvantages: usually lose guaranteed complete/optimality
▪ Useful for Optimization (maximize an objective function)
2
Local search uses complete‐state formulations
Many problems can be formulated in two ways Hill Climbing and its variants
Simulated Annealing
Complete‐state Problem Formulation
The current state represents a full solution
Cooperative Search
Partial‐state Problem Formulation Local Beam Search
The current state represents part of the solution Genetic Algorithms
Imagine that we are trying to find the highest peak on Hill climbing can easily get permanently stuck
a mountain range (global maxima) Local maxima, plateaus.
Avoid by adding randomness
Strategy
Given current state, evaluate next states Stochastic Hill Climbing
Pick the best one (highest value) Pick the successor with a probability related to the steepness
(goodness)
Objective (evaluation) function
E.g. n‐queens Random‐restarts
Don’t waste time being stuck, simply retry from new initial
Analysis: condition. (why is this a good idea?)
Complete? Optimal? Complexity?
How does this compare to random walk? Tabu Search
Remember last “k” answers and avoid revisiting…
3
Complete State Formulation: Concept: Consider a ball stuck in a crevice (local minima),
suppose we could shake it a bit to dislodge it….
Current state: board with 8 queens
Successor function: all boards that result from moving a single Inspiration: In metallurgy, strengthen metal by first heating
queen within its column (8x7 = 56 successors) then slowly cooling (high exploration, then lower)
Objective: minimize number of conflicts (goal=zero)
Strategy
Given current state, pick a random successor
How well does it perform?
If it is better, then take it
Hill climbing If not, accept with probability p
▪ 14% success, 86% stuck p depends on “badness” of move and T
▪ But quick to succeed or get stuck (4 iterations, 3 iterations) T (temperature) represents “exploration”,
Random‐restart high initially, then lower slowly.
▪ If “trial” event has probability p, expected number of trials =1/p
Analysis: (minimization)
Expect: 7 trials x 4 steps each = 28 steps.
Complete? Optimal? Efficiency?
For a million queens, random restart finds solution in < minute! How does this compare to random‐restart?
Hill climbing and Simulated Annealing assume a
Strategy:
single point moving through space Start with k randomly chosen states
Random‐restart has many points in the landscape Evaluate all successors of all k states
(exploits diversification) Choose the best “k” from the set
Can combine with any previous method!
Stochastic Version
To avoid overconcentration,
stochastically choose
E.g. roulette wheel: each successor has a
section proportional to value, spin k
times.
What if these points could “share” knowledge?
4
A variant of local beam search, that uses a special In Genetic Algorithms
State (solution) is represented by a “genetic code”
mechanism for generating successors
E.g. nqueens: code is position of queens
Mutation changes a solution
Strategy Crossover combines solutions!
▪ k states (“population” of k individuals)
▪ Each individual can generate successors by “mutation” 8‐Queens
▪ But successors can also be generated by combining two
individuals (“cross‐over”)
▪ Idea: Cross‐over enables combining two partial solutions, can
move very far within the landscape (but not blindly)
Inspiration: Evolution by sexual reproduction
What’s important for making this idea work?
Goal: Encode an image using 50 semi‐transparent
polygons (nice compression!)
What is the best you can do to capture the MonaLisa?
http://rogeralsing.com/2008/12/07/genetic-programming-evolution-of-mona-lisa/
5
Pollack’s Group, (Brandeis)
Popular, but still poorly understood/controversial EvoCAD: evolve lego structures that
satify various conditions (bridges,
Good representation is critical and difficult to characterize (not a unique problem, counter balanced cranes)
true for all search problems, but worse for GA).
▪ Schemas => when crossover is useful Hod Lipson (Cornell)
Golem project: evolve simple electro‐
GAs have been applied to a wide and surprising range of problems mechanical systems that can move
▪ Challenges our understanding (and peaks our interest) more so than traditional problems. (Nature 2000)
Related Algorithms HUMIES awards
Evolutionary algorithms, genetic programming, particle swarm optimization, etc….
Human‐competitive results produced by
Bio‐inspiration: is the goal to mimic or exceed nature? genetic/evo algorithms (e.g. NASA
antenna design, 2006)
Interesting feature Although exciting, sill remains a
Ability to represent and search over complex problems difficult tool to use systematically
▪ Evolutionary robotics, genetic programming Represention
Costly “fitness” evaluation
Example Problem: Place three airports in Massachusetts such that Problem Type: Optimization Problems!
we minimize the total sum of distances of cities to nearest airports
State: (x1,y1,x2,y2,x3,y3) Objective function subject to Constraints
Objective function to be minimized: sum of squared distances from each ▪ Recall, the Allocation Problem
city to its closest airport. ▪ Agents+Items+Prefer maximize Happiness
Solutions Solution, not path, is what matters
Discretize space (and use methods we already covered) Large/infinite complex state spaces
Compute Gradients (differentiate the objective function)
Sometimes there are analytical solutions!
“Better” is better than “best”
Constrained Optimization Local search techniques come up routinely
Linear programming
Convex Optimization VLSI design, factory‐floor layout, hubble telescope
scheduling, airline crew and gate assignment, parameters
for dynamical models in robotics, etc.
[board lecture; skim AIMA 4.2]
6
Local Search:
Sometimes the path to the solution doesn’t matter
Complete vs Partial Formulation
Techniques: hill Climbing, simulated annealing
Cooperative Search: local beam, genetic algorithms
Gain: little memory and ability to operate in large landscapes
Lose: optimality/completeness (“black magic”)
Two overarching concepts:
Intensification
▪ increase search effort in promising areas of the search space (e.g. choose
optimally in the neighborhood, cooperativity, etc.)
Diversification
▪ facilitate movement between very different areas of the search space (e.g.
high temperature, random restarts, cross‐over…)
Optimization: Exploration vs Exploitation (occurs often in Nature!)