70
CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore, Percy Liang, Luke Zettlemoyer

CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Embed Size (px)

Citation preview

Page 1: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

CSPs

Tamara BergCS 560 Artificial Intelligence

Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore, Percy Liang, Luke Zettlemoyer

Page 2: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Announcements

• No class on Monday (labor day) • HW1– The system staff have installed the java

development kit on the classroom server.

Page 3: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Review from last class

Page 4: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

What is search for?• Assumptions: single agent,

deterministic, fully observable, discrete environment

• Search for planning– The path to the goal is the

important thing– Paths have various costs, depths

• Search for assignment– Assign values to variables while

respecting certain constraints– The goal (complete, consistent

assignment) is the important thing

Page 5: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Constraint satisfaction problems (CSPs)

• Definition:– Xi is a set of variables {X1 ,… Xn}

– Di is a set of domains {D1 ,... Dn} one for each variable– C is a set of constraints that specify allowable

combinations of values– Solution is a complete, consistent assignment

Page 6: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Example: Map Coloring

• Variables: WA, NT, Q, NSW, V, SA, T • Domains: {red, green, blue}• Constraints: adjacent regions must have different colors

e.g., WA ≠ NT, or (WA, NT) in {(red, green), (red, blue), (green, red), (green, blue), (blue, red), (blue, green)}

Page 7: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Example: Map Coloring

• Solutions are complete and consistent assignments, e.g., WA = red, NT = green, Q = red, NSW = green, V = red, SA = blue, T = green

Page 8: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Example: Cryptarithmetic

• Variables: T, W, O, F, U, R X1, X2

• Domains: {0, 1, 2, …, 9}• Constraints:

O + O = R + 10 * X1

W + W + X1 = U + 10 * X2

T + T + X2 = O + 10 * F

Alldiff(T, W, O, F, U, R)T ≠ 0, F ≠ 0

X2 X1

Page 9: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Example: Sudoku

• Variables: Xij

• Domains: {1, 2, …, 9}

• Constraints:Alldiff(Xij in the same unit)

Xij

Page 10: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Real-World CSPs

• Assignment problems– e.g., who teaches what class– hard constraint - no prof can teach 2 classes at the same

time. – preference constraints – Jan prefers teaching in the

morning while Alex prefers teaching in the afternoon (soft constraints/costs). For example an afternoon slot for Jan can cost 2 points whereas a morning slot costs 1.

Page 11: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Real-World CSPs

• Timetable problems– e.g., which class is offered when and where?– Classroom size & enrollment can put hard constraints on

where a class can be held – Avoiding simultaneous scheduling of two related classes

can be a soft constraint

Page 12: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Real-World CSPs

• Transportation Scheduling– E.g. airline scheduling Flights F1,F2 with capacities 165 and

385– Domains D1=[0,165] D2=[0,385]– Suppose we have an additional constraint that the two

flights must carry 420 people: ie F1+F2=420 – Then we can reduce the domains to:

D1=[35,165] D2=[255,385]

Enforcing Bounds consistency

Page 13: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Real-World CSPs

• Job-shop scheduling– e.g. assembling a car – Variables – X = tasks {Axlef, Axleb, Wheelrf, Wheellf, Wheelrb,

Wheellb,Nutsrf, Nutslf, Nutslb, Nutsrb, Caprf, Caplf, Caprb, CAPlb, Inspect}

– Values – Di time task starts– Constraints – one ask must occur before other, a task takes a certain

amount of time to complete.• e.g. AxleF + 10 ≤ Wheelrf, Wheelrf+1≤Nutsrf, Nutsrf+2≤Caprf…• 4 workers, but only 1 axle tool:

– Axlef+10≤Axleb or Axleb+10≤Axlef

• For each variable, X, except Inspect:– X+dx ≤ Inspect

• Want total time less than 30 minutes and inspect takes 3 minutes:– Di = {1,2,3,….,27}

Page 14: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

More examples of CSPs: http://www.csplib.org/

Page 15: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Types of Constraints• Unary

– restricts value of a single variable, e.g. SA≠green.• Binary

– relates two variables, e.g. SA≠NSW• Higher order

– relates more than two variables, e.g. Between (X,Y,Z)• Global

– arbitrary number of variables– commonly Alldiff – all variables must have different values. e.g. in sudoku all variables

in a unit must satisfy Alldiff.• Preference constraint

– Red is better than green– Often representable by a cost for each variable assignment

• Resource constraint– Atmost constraint. e.g. scheduling P1,P2,P3,P4 denote personnel assigned to each task.

Constrain is that you only have ≤ 10 people. So Atmost(10,P1,P2,P3,P4)

Page 16: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Variations on CSPs

Simplest CSPs – discrete, finite domainsmap coloring, scheduling with time limits, 8-queens

Discrete with infinite domainno deadline scheduling

Continuous domainsscheduling of experiments on Hubble telescope

Linear programming problemsconstraints must be linear equalities or inequalities (can be solved in time polynomial in # vars)

Page 17: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

• Variables: Xij

• Domains: {1, 2, …, 9}

• Constraints:Alldiff(Xij in the same unit)

Xij

Why are constraints useful?

They let us eliminate portions of assignment space • By identifying var/val combinations that violate constraints

?

?

Page 18: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,
Page 19: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Backtracking search

• In CSP’s, variable assignments are commutative– For example, [WA = red then NT = green] is the same as

[NT = green then WA = red]• We only need to consider assignments to a single variable at

each level (i.e., we fix the order of assignments)

Page 20: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Example

Page 21: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Example

Page 22: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Example

Page 23: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Example

Page 24: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Example

Red? Green? Blue?x x x

x

Page 25: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Backtracking search

• In CSP’s, variable assignments are commutative– For example, [WA = red then NT = green] is the same as

[NT = green then WA = red]• We only need to consider assignments to a single variable at

each level (i.e., we fix the order of assignments)• Depth-first search for CSPs with single-variable assignments is

called backtracking search

Page 26: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Backtracking search algorithm

Page 27: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Improving Backtracking Efficiency

• Ordering– How should we order variables for assignment?– How should we order values from the domains?

• Filtering– Can we detect inevitable failures early?

• Structure– Can we exploit problem structure?

Page 28: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Improving Backtracking Efficiency

• Ordering– How should we order variables for assignment?– How should we order values from the domains?

Page 29: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Backtracking search algorithm

Page 30: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Which variable should be assigned next?

• Most constrained variable:– Choose the variable with the fewest legal values– A.k.a. minimum remaining values (MRV) heuristic

Page 31: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Which variable should be assigned next?

• Most constrained variable:– Choose the variable with the fewest legal values– A.k.a. minimum remaining values (MRV) heuristic

Page 32: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Which variable should be assigned next?

• Most constraining variable:– Choose the variable that imposes the most

constraints on the remaining variables

Page 33: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Which variable should be assigned next?

• Most constraining variable:– Choose the variable that imposes the most

constraints on the remaining variables– Tie-breaker among most constrained variables

Page 34: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Backtracking search algorithm

Page 35: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Given a variable, in which order should its values be tried?

• Choose the least constraining value:– The value that rules out the fewest values in the

remaining variables

Page 36: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Given a variable, in which order should its values be tried?

• Choose the least constraining value:– The value that rules out the fewest values in the

remaining variablesWhich assignment

for Q should we choose?

Page 37: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Improving Backtracking Efficiency

• Ordering– How should we order variables for assignment?– How should we order values from the domains?

• Filtering– Can we detect inevitable failures early?

Page 38: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Early detection of failure

Apply inference to reduce the space of possible assignments and detect failure early

Page 39: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Early detection of failure:Forward checking

• Keep track of remaining legal values for unassigned variables• Terminate search when any variable has no legal values

Page 40: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Early detection of failure:Forward checking

• Keep track of remaining legal values for unassigned variables• Terminate search when any variable has no legal values

Page 41: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Early detection of failure:Forward checking

• Keep track of remaining legal values for unassigned variables• Terminate search when any variable has no legal values

Page 42: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Early detection of failure:Forward checking

• Keep track of remaining legal values for unassigned variables• Terminate search when any variable has no legal values

Page 43: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Early detection of failure:Forward checking

• Keep track of remaining legal values for unassigned variables• Terminate search when any variable has no legal values

Page 44: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Constraint propagation

• Forward checking propagates information from assigned to unassigned variables, but doesn't provide early detection for all failures

• NT and SA cannot both be blue!• Constraint propagation repeatedly enforces constraints locally

Page 45: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

• Simplest form of constraint propagation makes each pair of variables consistent:– X Y is consistent iff for every value of X there is some allowed value of Y

Arc consistency

Consistent!

Page 46: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

• Simplest form of propagation makes each pair of variables consistent:– X Y is consistent iff for every value of X there is some allowed value of Y

Arc consistency

Page 47: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

• Simplest form of propagation makes each pair of variables consistent:– X Y is consistent iff for every value of X there is some allowed value of Y– When checking X Y, throw out any values of X for which there isn’t an

allowed value of Y

• If X loses a value, all pairs Z X need to be rechecked

Arc consistency

Page 48: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Arc consistency

• Simplest form of propagation makes each pair of variables consistent:– X Y is consistent iff for every value of X there is some allowed value of Y– When checking X Y, throw out any values of X for which there isn’t an

allowed value of Y

• If X loses a value, all pairs Z X need to be rechecked

Page 49: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Arc consistency

• Simplest form of propagation makes each pair of variables consistent:– X Y is consistent iff for every value of X there is some allowed value of Y– When checking X Y, throw out any values of X for which there isn’t an

allowed value of Y

• If X loses a value, all pairs Z X need to be rechecked

Page 50: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

• Simplest form of propagation makes each pair of variables consistent:– X Y is consistent iff for every value of X there is some allowed value of Y– When checking X Y, throw out any values of X for which there isn’t an

allowed value of Y

Arc consistency

Page 51: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

• Simplest form of propagation makes each pair of variables consistent:– X Y is consistent iff for every value of X there is some allowed value of Y– When checking X Y, throw out any values of X for which there isn’t an

allowed value of Y

• Arc consistency detects failure earlier than forward checking• Can be run before or after each assignment

Arc consistency

Page 52: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Arc consistency algorithm AC-3

Page 53: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,
Page 54: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,
Page 55: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Specialized constraint checking

• Constraints involving an arbitrary number of variables can have special purpose algorithms

• E.g. Alldiff – Remove any variable in the CSP that has a singleton

domain and remove that value from the domains of remaining variables.

– Repeat as long as you have singleton variables. – If at any point an empty domain is produced or you

have more variables than domain values left - inconsistency!

Page 56: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Specialized constraint checking

• Constraints involving an arbitrary number of variables can have special purpose algorithms

• E.g. Atmost – Detect inconsistencies by checking sum of min

values in current domain. – Can also enforce consistencies by deleting max

values of any domain if it’s not consistent with min values in other domains

Atmost(10,P1,P2,P3,P4)If domains are {2,3,4,5,6} can delete {5,6} from all domains b/c inconsistent with min domain values

Page 57: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Improving Backtracking Efficiency

• Ordering– How should we order variables for assignment?– How should we order values from the domains?

• Filtering– Can we detect inevitable failures early?

• Structure– Can we exploit problem structure?

Page 58: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,
Page 59: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Tree-structured CSPs

• Certain kinds of CSPs can be solved without resorting to backtracking search!

• Tree-structured CSP: constraint graph does not have any loops

Source: P. Abbeel, D. Klein, L. Zettlemoyer

Page 60: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Algorithm for tree-structured CSPs• Choose one variable as root, order variables from root to leaves

such that every node's parent precedes it in the ordering

http://cs188ai.wikia.com/wiki/Tree_Structure_CSPs

Page 61: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Algorithm for tree-structured CSPs• Choose one variable as root, order variables from root to leaves

such that every node's parent precedes it in the ordering• Backward removal phase: check arc consistency starting from the

rightmost node and going backwards

http://cs188ai.wikia.com/wiki/Tree_Structure_CSPs

Page 62: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Algorithm for tree-structured CSPs• Choose one variable as root, order variables from root to leaves

such that every node's parent precedes it in the ordering• Backward removal phase: check arc consistency starting from the

rightmost node and going backwards• Forward assignment phase: select an element from the domain of

each variable going left to right. We are guaranteed that there will be a valid assignment because each arc is arc consistent

http://cs188ai.wikia.com/wiki/Tree_Structure_CSPs

Page 63: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Algorithm for tree-structured CSPs

• Running time is O(nm2) (n is the number of variables, m is the domain size)– We have to check arc consistency once for every node

in the graph (every node has one parent), which involves looking at pairs of domain values

Page 64: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Nearly tree-structured CSPs

• Cutset conditioning: find a subset of variables whose removal makes the graph a tree, instantiate that set in all possible ways, prune the domains of the remaining variables and try to solve the resulting tree-structured CSP

Source: P. Abbeel, D. Klein, L. Zettlemoyer

Page 65: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Alternatives to backtracking

Page 66: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Local Search Methods

• Local Search: Improve what you have until you can’t make it better

• Generally much faster and more memory efficient than back-tracking search (but not necessarily complete)

Page 67: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Local search for CSPs• Start with an initial assignment of variables to values • Allow states with unsatisfied constraints• Attempt to improve states by reassigning variable values• Hill-climbing search:

– In each iteration, randomly select any conflicted variable and choose value that violates the fewest constraints

– I.e., attempt to greedily minimize total number of violated constraints

h = number of conflicts

Page 68: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,

Local search for CSPs• Start with “complete” states, i.e., all variables assigned • Allow states with unsatisfied constraints• Attempt to improve states by reassigning variable values• Hill-climbing search:

– In each iteration, randomly select any conflicted variable and choose value that violates the fewest constraints

– I.e., attempt to greedily minimize total number of violated constraints– Problem: local minima

h = 1

Page 69: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,
Page 70: CSPs Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore,