CSPs Tamara Berg CS 590-133 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew.

Slides:



Advertisements
Similar presentations
Constraint Satisfaction Problems
Advertisements

Constraint Satisfaction Problems Russell and Norvig: Chapter
Constraint Satisfaction Problems (Chapter 6). What is search for? Assumptions: single agent, deterministic, fully observable, discrete environment Search.
Constraint Satisfaction Problems
Lecture 11 Last Time: Local Search, Constraint Satisfaction Problems Today: More on CSPs.
1 Constraint Satisfaction Problems A Quick Overview (based on AIMA book slides)
This lecture topic (two lectures) Chapter 6.1 – 6.4, except 6.3.3
Artificial Intelligence Constraint satisfaction problems Fall 2008 professor: Luigi Ceccaroni.
Constraint Satisfaction problems (CSP)
Review: Constraint Satisfaction Problems How is a CSP defined? How do we solve CSPs?
Constraint Satisfaction Problems. Constraint satisfaction problems (CSPs) Standard search problem: – State is a “black box” – any data structure that.
Constraint Satisfaction Problems
4 Feb 2004CS Constraint Satisfaction1 Constraint Satisfaction Problems Chapter 5 Section 1 – 3.
Constraint Satisfaction Problems
Constraint Satisfaction
Chapter 5 Outline Formal definition of CSP CSP Examples
Constraint Satisfaction Problems
Constraint Satisfaction Problems
Constraint Satisfaction Problems
ISC 4322/6300 – GAM 4322 Artificial Intelligence Lecture 4 Constraint Satisfaction Problems Instructor: Alireza Tavakkoli September 17, 2009 University.
1 Constraint Satisfaction Problems Slides by Prof WELLING.
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 Chapter 6. Review Agent, Environment, State Agent as search problem Uninformed search strategies Informed (heuristic.
Chapter 5 Section 1 – 3 1.  Constraint Satisfaction Problems (CSP)  Backtracking search for CSPs  Local search for CSPs 2.
CSP Examples Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew.
Constraint Satisfaction CPSC 386 Artificial Intelligence Ellen Walker Hiram College.
CSC 8520 Spring Paula Matuszek Based on Hwee Tou Ng, aima.eecs.berkeley.edu/slides-ppt, which are based on Russell, aima.eecs.berkeley.edu/slides-pdf.
Hande ÇAKIN IES 503 TERM PROJECT CONSTRAINT SATISFACTION PROBLEMS.
Artificial Intelligence CS482, CS682, MW 1 – 2:15, SEM 201, MS 227 Prerequisites: 302, 365 Instructor: Sushil Louis,
1 Constraint Satisfaction Problems Soup Total Cost < $30 Chicken Dish Vegetable RiceSeafood Pork Dish Appetizer Must be Hot&Sour No Peanuts No Peanuts.
Chapter 5: Constraint Satisfaction ICS 171 Fall 2006.
CSCI 5582 Fall 2006 CSCI 5582 Artificial Intelligence Fall 2006 Jim Martin.
1 Chapter 5 Constraint Satisfaction Problems. 2 Outlines  Constraint Satisfaction Problems  Backtracking Search for CSPs  Local Search for CSP  The.
CSC 8520 Spring Paula Matuszek CS 8520: Artificial Intelligence Search 3: Constraint Satisfaction Problems Paula Matuszek Spring, 2013.
CSPs Tamara Berg CS Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew.
Chapter 5 Constraint Satisfaction Problems
CSE 473: Artificial Intelligence Constraint Satisfaction Daniel Weld Slides adapted from Dan Klein, Stuart Russell, Andrew Moore & Luke Zettlemoyer.
Constraint Satisfaction Problems (Chapter 6)
An Introduction to Artificial Intelligence Lecture 5: Constraint Satisfaction Problems Ramin Halavati In which we see how treating.
1 Constraint Satisfaction Problems Chapter 5 Section 1 – 3 Grand Challenge:
CHAPTER 5 SECTION 1 – 3 4 Feb 2004 CS Constraint Satisfaction 1 Constraint Satisfaction Problems.
Constraint Satisfaction Problems University of Berkeley, USA
4/18/2005EE5621 EE562 ARTIFICIAL INTELLIGENCE FOR ENGINEERS Lecture 5, 4/18/2005 University of Washington, Department of Electrical Engineering Spring.
1. 2 Outline of Ch 4 Best-first search Greedy best-first search A * search Heuristics Functions Local search algorithms Hill-climbing search Simulated.
Computing & Information Sciences Kansas State University Friday, 08 Sep 2006CIS 490 / 730: Artificial Intelligence Lecture 7 of 42 Friday, 08 September.
Chapter 5 Team Teaching AI (created by Dewi Liliana) PTIIK Constraint Satisfaction Problems.
EXAMPLE: MAP COLORING. Example: Map coloring Variables — WA, NT, Q, NSW, V, SA, T Domains — D i ={red,green,blue} Constraints — adjacent regions must.
1 Constraint Satisfaction Problems Chapter 5 Section 1 – 3.
Dr. Shazzad Hosain Department of EECS North South University Lecture 01 – Part C Constraint Satisfaction Problems.
1 Constraint Satisfaction Problems (CSP). Announcements Second Test Wednesday, April 27.
Constraint Satisfaction Problems
ARTIFICIAL INTELLIGENCE (CS 461D) Dr. Abeer Mahmoud Computer science Department Princess Nora University Faculty of Computer & Information Systems.
CS 561, Session 8 1 This time: constraint satisfaction - Constraint Satisfaction Problems (CSP) - Backtracking search for CSPs - Local search for CSPs.
Constraint Satisfaction Problems (Chapter 6)
ECE 448, Lecture 7: Constraint Satisfaction Problems
Constraint Satisfaction Problems Lecture # 14, 15 & 16
Advanced Artificial Intelligence
CS 188: Artificial Intelligence
Constraint Satisfaction Problems
Constraint Satisfaction Problems
Artificial Intelligence
Constraint Satisfaction Problems
Constraint satisfaction problems
Constraint Satisfaction Problems. A Quick Overview
CS 8520: Artificial Intelligence
Constraint Satisfaction Problems
Constraint satisfaction problems
Constraint Satisfaction Problems (CSP)
Presentation transcript:

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

Review from last class

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

Constraint satisfaction problems (CSPs) Definition: – X i is a set of variables {X 1,… X n } – D i is a set of domains {D 1,... D n } one for each variable – C is a set of constraints that specify allowable combinations of values – Solution is a complete, consistent assignment How does this compare to the “generic” tree search formulation? – A more structured representation for states, expressed in a formal representation language – Allows useful general-purpose algorithms with more power than standard search algorithms by eliminating large portions of search space (identifying var/val combinations that violate constraints).

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)}

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

Example: Cryptarithmetic Variables: T, W, O, F, U, R X 1, X 2 Domains: {0, 1, 2, …, 9} Constraints: O + O = R + 10 * X 1 W + W + X 1 = U + 10 * X 2 T + T + X 2 = O + 10 * F Alldiff(T, W, O, F, U, R) T ≠ 0, F ≠ 0 X 2 X 1

Example: Sudoku Variables: X ij Domains: {1, 2, …, 9} Constraints: Alldiff(X ij in the same unit) X ij

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.

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

Real-World CSPs Transportation Scheduling – E.g. airline scheduling Flights F 1,F 2 with capacities 165 and 385 – Domains D 1 =[0,165] D 2 =[0,385] – Suppose we have an additional constraint that the two flights must carry 420 people: ie F 1 +F 2 =420 – Then we can reduce the domains to: D 1 =[35,165] D 2 =[255,385] Enforcing Bounds consistency

Real-World CSPs Job-shop scheduling – e.g. assembling a car – Variables – X = tasks {Axle f, Axle b, Wheel rf, Wheel lf, Wheel rb, Wheel lb,Nuts rf, Nuts lf, Nuts lb, Nuts rb, Cap rf, Cap lf, Cap rb, CAP lb, Inspect} – Values – D i time task starts – Constraints – one ask must occur before other, a task takes a certain amount of time to complete. e.g. Axle F + 10 ≤ Wheel rf, Wheel rf +1≤Nuts rf, Nutsrf+2≤Cap rf … 4 workers, but only 1 axle tool: – Axle f +10≤Axle b or Axle b +10≤Axle f For each variable, X, except Inspect: – X+d x ≤ Inspect Want total time less than 30 minutes and inspect takes 3 minutes: – D i = {1,2,3,….,27}

More examples of CSPs:

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 P 1,P 2,P 3,P 4 denote personnel assigned to each task. Constrain is that you only have ≤ 10 people. So Atmost(10,P 1,P 2,P 3,P 4 )

Variations on CSPs Simplest CSPs – discrete, finite domains map coloring, scheduling with time limits, 8-queens Discrete with infinite domain no deadline scheduling Continuous domains scheduling of experiments on Hubble telescope Linear programming problems constraints must be linear equalities or inequalities (can be solved in time polynomial in # vars)

Variables: X ij Domains: {1, 2, …, 9} Constraints: Alldiff(X ij in the same unit) X ij Why are constraints useful? They let us eliminate portions of assignment space By identifying var/val combinations that violate constraints ? ?

Standard search formulation (incremental) States: – Variables and values assigned so far Initial state: – The empty assignment Action: – Choose any unassigned variable and assign to it a value that does not violate any constraints Fail if no legal assignments Goal test: – The current assignment is complete and satisfies all constraints

Standard search formulation (incremental) What is the depth of any solution (assuming n variables)? n (this is good) Given that there are m possible values for any variable, how many paths are there in the search tree? n! · m n (this is bad) How can we reduce the branching factor?

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)

Example

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

Backtracking search algorithm

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

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

Which variable should be assigned next? Most constraining variable: – Choose the variable that imposes the most constraints on the remaining variables

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

Backtracking search algorithm

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

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 Which assignment for Q should we choose?

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

Early detection of failure: Forward checking Keep track of remaining legal values for unassigned variables Terminate search when any variable has no legal values

Early detection of failure: Forward checking Keep track of remaining legal values for unassigned variables Terminate search when any variable has no legal values

Early detection of failure: Forward checking Keep track of remaining legal values for unassigned variables Terminate search when any variable has no legal values

Early detection of failure: Forward checking Keep track of remaining legal values for unassigned variables Terminate search when any variable has no legal values

Early detection of failure: Forward checking Keep track of remaining legal values for unassigned variables Terminate search when any variable has no legal values

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

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 Consistent!

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

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

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 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

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

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

Arc consistency algorithm AC-3

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!

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,P 1,P 2,P 3,P 4 ) If domains are {2,3,4,5,6} can delete {5,6} from all domains b/c inconsistent with min domain values

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

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

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

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

Algorithm for tree-structured CSPs Running time is O(nm 2 ) (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

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

Algorithm for tree-structured CSPs Running time is O(nm 2 ) (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 What about backtracking search for general CSPs? – Worst case O(m n ) Can we do better?

Computational complexity of CSPs The satisfiability (SAT) problem: The satisfiability (SAT) problem – Given a Boolean formula, is there an assignment of the variables that makes it evaluate to true? SAT is NP-complete (Cook, 1971)NP-complete – NP: class of decision problems for which the “yes” answer can be verified in polynomial time – An NP-complete problem is in NP and every other problem in NP can be efficiently reduced to it – Other NP-complete problems: graph coloring, n-puzzle, generalized sudoku – Open question: is P = NP? Open question: is P = NP?

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 h = number of conflicts

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