outline
play

Outline CSP definition Backtracking search for CSPs Constraint - PowerPoint PPT Presentation

Outline CSP definition Backtracking search for CSPs Constraint Satisfaction Problems Constraint propagation by Stuart Russell Problem structure and problem decomposition modified by Jacek Malec for LTH lectures Local search


  1. Outline ♦ CSP definition ♦ Backtracking search for CSPs Constraint Satisfaction Problems ♦ Constraint propagation by Stuart Russell ♦ Problem structure and problem decomposition modified by Jacek Malec for LTH lectures ♦ Local search for CSPs January 26th, 2018 Acknowledgement: slides are based partly on Krzysztof Kuchci´ nski’s lecture notes Chapter 6 of AIMA � Stuart Russell c Chapter 6 of AIMA 1 � Stuart Russell c Chapter 6 of AIMA 2 Constraint satisfaction problems (CSPs) CSP definition A Constraint Satisfaction Problem consists of three components: Standard search problem: X , D and C : state is a “black box”—any “good old” data structure X is a set of variables, { X 1 , . . . , X n } , that supports goal test, eval, successor D is a set of domains, { D 1 , . . . , D n } , one for each variable, CSP: C is a set of constraints that specify allowable combinations of values. state is defined by variables X i with values from domain D i Each constraint C i consists of a pair < scope, rel > . A solution to a CSP is a consistent, complete assignment. 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 � Stuart Russell c Chapter 6 of AIMA 3 � Stuart Russell c Chapter 6 of AIMA 4

  2. Example: 4-Queens as a CSP Example: Map-Coloring Assume one queen in each column. Which row does each one go in? Variables Q 1 , Q 2 , Q 3 , Q 4 Northern Domains D i = { 1 , 2 , 3 , 4 } Territory Western Queensland Australia Constraints South Q i ̸ = Q j (cannot be in same row) Australia | Q i − Q j | ̸ = | i − j | (or same diagonal) New South Wales h = 5 h = 2 h = 0 Translate each constraint into set of allowable values for its variables Victoria E.g., values for ( Q 1 , Q 2 ) are (1 , 3) (1 , 4) (2 , 4) (3 , 1) (4 , 1) (4 , 2) Tasmania Variables WA , NT , Q , NSW , V , SA , T Domains D i = { red, green, blue } Constraints: adjacent regions must have di ff erent colors e.g., WA ̸ = NT (if the language allows this), or ( WA, NT ) ∈ { ( red, green ) , ( red, blue ) , ( green, red ) , ( green, blue ) , . . . } � Stuart Russell c Chapter 6 of AIMA 5 � Stuart Russell c Chapter 6 of AIMA 6 Example: Map-Coloring contd. Constraint graph Binary CSP: each constraint relates at most two variables Constraint graph: nodes are variables, arcs show constraints Northern Territory NT Western Queensland Q Australia WA South Australia New South Wales SA NSW Victoria V Victoria Tasmania T Solutions are assignments satisfying all constraints, e.g., General-purpose CSP algorithms use the graph structure { WA = red, NT = green, Q = red, NSW = green, V = red, SA = blue, T = green } to speed up search. E.g., Tasmania is an independent subproblem! � Stuart Russell c Chapter 6 of AIMA 7 � Stuart Russell c Chapter 6 of AIMA 8

  3. Varieties of CSPs Varieties of constraints Discrete variables Unary constraints involve a single variable, O ( d n ) complete assignments finite domains; size d ⇒ e.g., SA ̸ = green ♦ e.g., Boolean CSPs, incl. Boolean satisfiability (NP-complete) Binary constraints involve pairs of variables, infinite domains (integers, strings, etc.) e.g., SA ̸ = WA ♦ e.g., job scheduling, variables are start/end days for each job ♦ need a constraint language, e.g., StartJob 1 + 5 ≤ StartJob 3 Higher-order constraints involve 3 or more variables, ♦ linear constraints solvable, nonlinear undecidable e.g., cryptarithmetic column constraints, sometimes called (misleadingly) global constraints Continuous variables ♦ e.g., start/end times for Hubble Telescope observations Preferences (soft constraints), e.g., red is better than green ♦ linear constraints solvable in poly time by LP methods often representable by a cost for each variable assignment → constrained optimization problems � Stuart Russell c Chapter 6 of AIMA 9 � Stuart Russell c Chapter 6 of AIMA 10 Example: Cryptarithmetic Real-world CSPs Assignment problems e.g., who teaches what class T W O O F T U W R Timetabling problems + T W O e.g., which class is o ff ered when and where? F O U R Hardware configuration X 3 X 2 X 1 Spreadsheets Transportation scheduling Variables: F T U W R O X 1 X 2 X 3 Domains: { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 } Factory scheduling Constraints Floor-planning alldi ff ( F, T, U, W, R, O ) O + O = R + 10 · X 1 , etc. Notice that many real-world problems involve real-valued variables � Stuart Russell c Chapter 6 of AIMA 11 � Stuart Russell c Chapter 6 of AIMA 12

  4. Backtracking search Standard search formulation (incremental) Variable assignments are commutative, i.e., Let’s start with the straightforward, dumb approach, then fix it [ WA = red then NT = green ] same as [ NT = green then WA = red ] States are defined by the values assigned so far Only need to consider assignments to a single variable at each node ♦ Initial state: the empty assignment, { } b = d and there are d n leaves ⇒ ♦ Successor function: assign a value to an unassigned variable that does not conflict with current assignment. Depth-first search for CSPs with single-variable assignments fail if no legal assignments (not fixable!) ⇒ is called backtracking search ♦ Goal test: the current assignment is complete Backtracking search is the basic uninformed algorithm for CSPs Can solve n -queens for n ≈ 25 1) This is the same for all CSPs! 2) Every solution appears at depth n with n variables ⇒ use depth-first search 3) Path is irrelevant, so can also use complete-state formulation 4) b = ( n − ℓ ) d at depth ℓ , hence n ! d n leaves!!!! � Stuart Russell c Chapter 6 of AIMA 13 � Stuart Russell c Chapter 6 of AIMA 14 Backtracking search Backtracking example function Backtracking-Search ( csp ) returns solution/failure return Backtrack ( { } , csp ) function Backtrack ( assignment , csp ) returns solution/failure if assignment is complete then return assignment var ← Select-Unassigned-Variable ( Variables [ csp ], assignment , csp ) for each value in Order-Domain-Values ( var , assignment , csp ) do if value is consistent with assignment given Constraints [ csp ] then add { var = value } to assignment result ← Backtrack ( assignment , csp ) if result ̸ = failure then return result remove { var = value } from assignment return failure � Stuart Russell c Chapter 6 of AIMA 15 � Stuart Russell c Chapter 6 of AIMA 16

  5. Backtracking example Backtracking example � Stuart Russell c Chapter 6 of AIMA 17 � Stuart Russell c Chapter 6 of AIMA 18 Backtracking example Improving backtracking e ffi ciency General-purpose methods can give huge gains in speed: 1. Which variable should be assigned next? 2. In what order should its values be tried? 3. Can we detect inevitable failure early? 4. Can we take advantage of problem structure? � Stuart Russell c Chapter 6 of AIMA 19 � Stuart Russell c Chapter 6 of AIMA 20

  6. Minimum remaining values Degree heuristic Tie-breaker among MRV variables Minimum remaining values (MRV): choose the variable with the fewest legal values Degree heuristic: choose the variable with the most constraints on remaining variables � Stuart Russell c Chapter 6 of AIMA 21 � Stuart Russell c Chapter 6 of AIMA 22 Least constraining value Forward checking Given a variable, choose the least constraining value: Idea: Keep track of remaining legal values for unassigned variables the one that rules out the fewest values in the remaining variables Terminate search when any variable has no legal values Allows 1 value for SA Allows 0 values for SA WA NT Q NSW V SA T Combining these heuristics makes 1000 queens feasible � Stuart Russell c Chapter 6 of AIMA 23 � Stuart Russell c Chapter 6 of AIMA 24

  7. Forward checking Forward checking Idea: Keep track of remaining legal values for unassigned variables Idea: Keep track of remaining legal values for unassigned variables Terminate search when any variable has no legal values Terminate search when any variable has no legal values WA NT Q NSW V SA T WA NT Q NSW V SA T � Stuart Russell c Chapter 6 of AIMA 25 � Stuart Russell c Chapter 6 of AIMA 26 Forward checking Constraint propagation Idea: Keep track of remaining legal values for unassigned variables Forward checking propagates information from assigned to unassigned vari- Terminate search when any variable has no legal values ables, but doesn’t provide early detection for all failures: WA NT Q NSW V SA T WA NT Q NSW V SA T NT and SA cannot both be blue! Constraint propagation repeatedly enforces constraints locally � Stuart Russell c Chapter 6 of AIMA 27 � Stuart Russell c Chapter 6 of AIMA 28

Recommend


More recommend