Constraint Satisfaction Problems

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
This lecture topic (two lectures) Chapter 6.1 – 6.4, except
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
CAP 492 Course Dr. Souham Meshoul 1 CONSTRAINT SATISFACTION PROBLEMS Chapter 5.
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,
CSPs Tamara Berg CS Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew.
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.
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.
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.
Chapter 5 Constraint Satisfaction Problems
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
Constraint Satisfaction Problems Chapter 6. Outline CSP? Backtracking for CSP Local search for CSPs Problem structure and decomposition.
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
Constraint Satisfaction Problems
Advanced Artificial Intelligence
Artificial Intelligence 1: Constraint Satis- faction problems
Constraint Satisfaction Problems
Constraint Satisfaction Problems
Artificial Intelligence: Constraint Satisfaction problems
CS 188: Artificial Intelligence Spring 2006
Constraint Satisfaction Problems
Artificial Intelligence
CSP Warm-up Assign Red, Green, or Blue
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:

Constraint Satisfaction Problems Chapter 6

Outline CSP examples Backtracking search for CSPs Problem structure and problem decomposition Local search for CSPs

Constraint satisfaction problems (CSPs) Standard search problem: state is a “black box”—any old data structure that supports goal test, eval, successor CSP: state is defined by variables Xi with values from domain Di goal test is a set of constraints specifying allowable combinations of values for subsets of variables Simple example of a formal representation language Allows useful general-purpose algorithms with more power than standard search algorithms

Example: Map-Coloring Northern Territory Western Australia Queensland South Australia New South Wales Victoria Tasmania Variables W A, N T , Q, N SW , V , SA, T Domains Di = {red, green, blue} Constraints: adjacent regions must have different colors e.g., W A ≠ T (if the language allows this), or (W A, N T ) ∈ {(red, green), (red, blue), (green, red), (green, blue), . . .}

Example: Map-Coloring (cont’d) Northern Territory Western Australia Queensland South Australia New South Wales Victoria Tasmania Solutions are assignments satisfying all constraints, e.g., {W A = red, N T = green, Q = red, N SW = green, V = red, SA = blue, T = green}

Constraint graph Binary CSP: each constraint relates at most two variables Constraint graph: nodes are variables, arcs show constraints NT Q WA SA NSW V T General-purpose CSP algorithms use the graph structure to speed up search. E.g., Tasmania is an independent subproblem!

CSPs with discrete variables finite domains; size d O(dn) complete assignments e.g., Boolean CSPs, incl. Boolean satisfiability (NP-complete) infinite domains (integers, strings, etc.) e.g., job scheduling, variables are start/end days for each job need a constraint language, e.g., StartJ ob1 + 5 ≤ StartJ ob3 linear constraints solvable, nonlinear undecidable

CSPs with continuous variables linear constraints solvable in polynomial time by linear programinf (LP) methods e.g., precise start/end times for Hubble Telescope observations with astronomical, precedence, and power constraints

Varieties of constraints Unary constraints involve a single variable, e.g., SA ≠ green Binary constraints involve pairs of variables, e.g., SA ≠ W A Higher-order constraints involve 3 or more variables, e.g., cryptarithmetic column constraints Preferences (soft constraints), e.g., red is better than green often representable by a cost for each variable assignment → constrained optimization problems

Example: Cryptarithmetic T W O + T W O F T U W R O F O U R X3 X2 X1 (a) Variables: F T U W R O X1 X2 X3 Domains: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} Constraints alldiff(F, T, U, W, R, O) O + O = R + 10 · X1, X1 + W + W = U + 10 . X2 X2 + T + T = O + 10 . X3, X3 = F (b)

Problem b a c e d Consider the constraint graph on the right. The domain for every variable is [1,2,3,4]. There are 2 unary constraints: variable “a” cannot take values 3 and 4. variable “b” cannot take value 4. d There are 8 binary constraints stating that variables connected by an edge cannot have the same value.

Example: 4-Queens Problem {1,2,3,4} X2 X3 X4 1 2 3 4 1 2 3 4 5 Queen's Problem

Real-world CSPs Assignment problems e.g., who teaches what class Timetabling problems e.g., which class is offered when and where? Hardware configuration Spreadsheets Transportation scheduling Factory scheduling Floorplanning Notice that many real-world problems involve real-valued variables

Standard search formulation (incremental) Let’s start with the straightforward, dumb approach, then fix it States are defined by the values assigned so far Initial state: the empty assignment, ∅ Successor function: assign a value to an unassigned variable that does not conflict with current assignment.  fail if no legal assignments (not fixable!) Goal test: the current assignment is complete

Standard search formulation (incremental) This is the same for all CSPs! Every solution appears at depth n with n variables  use depth-first search Path is irrelevant, so can also use complete-state formulation b = (n − ℓ)d at depth ℓ, hence n!dn leaves!!!!

Backtracking search Variable assignments are commutative, i.e., [W A = red then N T = green] same as [N T = green then W A = red] Only need to consider assignments to a single variable at each node  b = d and there are dn leaves Depth-first search for CSPs with single-variable assignments is called backtracking search Backtracking search is the basic uninformed algorithm for CSPs Can solve n-queens for n ≈ 25

Backtracking search function BACKTRACKING-SEARCH (csp) returns a solution, or failure return BACKTRACK({ }, csp)

Backtracking search (cont’d) function BACKTRACK (assignment, csp) returns a solution, or failure if assignment is complete then return assignment var ← SELECT-UNASSIGNED-VAR(csp) for each value in ORDER-DOMAIN-VALUES(var, assignment, csp) do if value is consistent with assignment then add { var = value } to assignment inferences ← INFERENCE(csp, var, value) if inferences ≠ failure then add inferences to assignment result ← BACKTRACK (assignment, csp) if result ≠ failure then return result remove { var = value } and inferences from assignment return failure

Backtracking Example

Backtracking Example

Backtracking Example

Backtracking Example

Improving backtracking efficiency General-purpose methods can give huge gains in speed: Which variable should be assigned next? In what order should its values be tried? Can we detect inevitable failure early? Can we take advantage of problem structure?

Most constrained variable choose the variable with the fewest legal values

Most constraining variable Tie-breaker among most constrained variables Most constraining variable: choose the variable with the most constraints on remaining variables

Least constraining value Given a variable, choose the least constraining value: the one that rules out the fewest values in the remaining variables Allows 1 value for SA Allows 0 value for SA Combining these heuristics makes 1000 queens feasible

Forward checking Idea: Keep track of remaining legal values for unassigned variables Idea: Terminate search when any variable has no legal values WA NT Q NSW V SA T

Forward checking Idea: Keep track of remaining legal values for unassigned variables Idea: Terminate search when any variable has no legal values WA NT Q NSW V SA T

Forward checking Idea: Keep track of remaining legal values for unassigned variables Idea: Terminate search when any variable has no legal values WA NT Q NSW V SA T

Forward checking Idea: Keep track of remaining legal values for unassigned variables Idea: Terminate search when any variable has no legal values WA NT Q NSW V SA T

Constraint propagation Forward checking propagates information from assigned to unassigned variables, but doesn’t provide early detection for all failures: WA NT Q NSW V SA T N T and SA cannot both be blue! Constraint propagation repeatedly enforces constraints locally

Example: 4-Queens Problem {1,2,3,4} X2 X3 X4 1 2 3 4 1 2 3 4

Example: 4-Queens Problem {1,2,3,4} X2 X3 X4 1 2 3 4 1 2 3 4

Example: 4-Queens Problem {1,2,3,4} X2 { , ,3,4} X3 { ,2, ,4} X4 { ,2,3, } 1 2 3 4 1 2 3 4

Example: 4-Queens Problem {1,2,3,4} X2 { , ,3,4} X3 { ,2, ,4} X4 { ,2,3, } 1 2 3 4 1 2 3 4

Example: 4-Queens Problem {1,2,3,4} X2 { , ,3,4} X3 { , , , } X4 { , ,3, } 1 2 3 4 1 2 3 4

Example: 4-Queens Problem {1,2,3,4} X2 { , , ,4} X3 { ,2, ,4} X4 { ,2,3, } 1 2 3 4 1 2 3 4

Example: 4-Queens Problem {1,2,3,4} X2 { , , ,4} X3 { ,2, ,4} X4 { ,2,3, } 1 2 3 4 1 2 3 4

Example: 4-Queens Problem {1,2,3,4} X2 { , , ,4} X3 { ,2, , } X4 { , ,3, } 1 2 3 4 1 2 3 4

Example: 4-Queens Problem {1,2,3,4} X2 { , , ,4} X3 { ,2, , } X4 { , ,3, } 1 2 3 4 1 2 3 4

Example: 4-Queens Problem {1,2,3,4} X2 { , ,3,4} X3 { ,2, , } X4 { , , , } 1 2 3 4 1 2 3 4

Arc consistency Simplest form of propagation makes each arc consistent X → Y is consistent iff for every value x of X there is some allowed y WA NT Q NSW V SA T

Arc consistency Simplest form of propagation makes each arc consistent X → Y is consistent iff for every value x of X there is some allowed y WA NT Q NSW V SA T

Arc consistency Simplest form of propagation makes each arc consistent X → Y is consistent iff for every value x of X there is some allowed y WA NT Q NSW V SA T If X loses a value, neighbors of X need to be rechecked

Arc consistency Simplest form of propagation makes each arc consistent X → Y is consistent iff for every value x of X there is some allowed y WA NT Q NSW V SA T If X loses a value, neighbors of X need to be rechecked Arc consistency detects failure earlier than forward checking Can be run as a preprocessor or after each assignment

Arc consistency algorithm function AC-3 (csp) returns false if an inconsistency is found and true otherwise inputs: csp, a binary CSP with components (X, D, C) local variables: queue, a queue of arcs, initially all the arcs in csp while queue is not empty do (Xi, Xj ) ← REMOVE-FIRST(queue) if REVISE(csp, Xi, Xj ) then if size of Di = 0 then return false for each Xk in Xi.NEIGHBORS-{Xj } do add (Xk , Xi) to queue return true

Arc consistency algorithm (cont’d) function REVISE (csp, Xi, Xj ) returns true iff we revise the domain of Xi revised ← false for each x in Di do if no value y in Dj allows (x, y) to satisfy the constraint between Xi and Xj then delete x from Di then revised ← true return revised O(n2d3), can be reduced to O(n2d2) but cannot detect all failures in polynomial time.

Back-tracking or back-jumping? {Q=red , NSW= green, V= blue, T=red} red green ? blue red blue green

Local search for CSPs Use complete-state representation Initial state = all variables assigned values Successor states = change 1 (or more) values For CSPs allow states with unsatisfied constraints (unlike backtracking) operators reassign variable values hill-climbing with n-queens is an example Variable selection: randomly select any conflicted variable. Value selection: min-conflicts heuristic Select new value that results in a minimum number of conflicts with the other variables

Local search for CSP function MIN-CONFLICTS(csp, max_steps) return solution or failure inputs: csp, a constraint satisfaction problem max_steps, the number of steps allowed before giving up current  an initial complete assignment for csp for i = 1 to max_steps do if current is a solution for csp then return current var  a randomly chosen, conflicted variable from VARIABLES[csp] value  the value v for var that minimize CONFLICTS (var,v,current,csp) set var = value in current return failure

Min-conflicts example 1 h=5 h=3 h=1 Use of min-conflicts heuristic in hill-climbing.

Min-conflicts example 2 A two-step solution for an 8-queens problem using min-conflicts heuristic At each stage a queen is chosen for reassignment in its column The algorithm moves the queen to the min-conflict square breaking ties randomly.

Advantages of local search Local search can be particularly useful in an online setting Airline schedule example  E.g., mechanical problems require than 1 plane is taken out of service  Can locally search for another “close” solution in state-space  Much better (and faster) in practice than finding an entirely new schedule. The runtime of min-conflicts is roughly independent of problem size. Can solve the millions-queen problem in roughly 50 steps. Why?  n-queens is easy for local search because of the relatively high density of solutions in state-space.

Problem structure Tasmania and mainland are independent subproblems Q WA SA NSW V T Tasmania and mainland are independent subproblems Identifiable as connected components of constraint graph

Problem structure contd. Suppose each subproblem has c variables out of n total Worst-case solution cost is n/c · dc, linear in n E.g., n = 80, d = 2, c = 20 280 = 4 billion years at 10 million nodes/sec 4 · 220 = 0.4 seconds at 10 million nodes/sec

Tree-structured CSPs A E B D C F Theorem: if the constraint graph has no loops, the CSP can be solved in O(n d2) time Compare to general CSPs, where worst-case time is O(dn) This property also applies to logical and probabilistic reasoning: an important example of the relation between syntactic restrictions and the complexity of reasoning.

Algorithm for tree-structured CSPs 1. Choose a variable as root, order variables from root to leaves such that every node’s parent precedes it in the ordering A E B D A B C D E F F C For j from n down to 2, apply MAKE-ARC-CONSISTENT(P arent(Xj ), Xj ) (will remove inconsistent values) For i from 1 to n, assign Xi consistently with P arent(Xi)

Algorithm for tree-structured CSPs (cont’d) function TREE-CSP-SOLVER (csp) returns a solution, or failure inputs: csp, a binary CSP with components (X, D, C) n ← number of variables in X assignment ← an empty assignment root ← any variable in X X ← TOPOLOGICALSORT(X, root) for j = n down to 2 do MAKE-ARC-CONSISTENT(P arent(Xj ), Xj ) if it cannot be made consistent then return failure for i = 1 to n do assignment [Xi] ← any consistent value from Di if there is no consistent value then return failure return assignment

Nearly tree-structured CSPs Conditioning: instantiate a variable, prune its neighbors’ domains NT NT Q Q WA WA SA NSW NSW V V T T

Nearly tree-structured CSPs Cutset conditioning: instantiate (in all ways) a set of variables such that the remaining constraint graph is a tree Cutset size c =⇒ runtime O(dc · (n − c)d2), very fast for small c

Summary CSPs are a special kind of problem: states defined by values of a fixed set of variables goal test defined by constraints on variable values Backtracking = depth-first search with one variable assigned per node Variable ordering and value selection heuristics help significantly Forward checking prevents assignments that guarantee later failure

Summary Constraint propagation (e.g., arc consistency) does additional work to constrain values and detect inconsistencies The CSP representation allows analysis of problem structure Tree-structured CSPs can be solved in linear time (Iterative min-conflicts is usually effective in practice)