Lecture 6: Constraint Satisfaction Problems (CSPs)

Similar documents
Constraint Satisfaction

Constraint Satisfaction Problems

Constraint Satisfaction Problems

Constraint Satisfaction Problems

Example: Map-Coloring. Constraint Satisfaction Problems Western Australia. Example: Map-Coloring contd. Outline. Constraint graph

Constraint Satisfaction Problems. Chapter 6

Constraint Satisfaction Problems

Australia Western Australia Western Territory Northern Territory Northern Australia South Australia South Tasmania Queensland Tasmania Victoria

Constraint Satisfaction. AI Slides (5e) c Lin

Constraint Satisfaction Problems (CSPs)

Chapter 6 Constraint Satisfaction Problems

CSE 473: Artificial Intelligence

CS 188: Artificial Intelligence Fall 2008

Announcements. CS 188: Artificial Intelligence Fall Large Scale: Problems with A* What is Search For? Example: N-Queens

Constraint Satisfaction Problems. A Quick Overview (based on AIMA book slides)

Constraint Satisfaction Problems

What is Search For? CSE 473: Artificial Intelligence. Example: N-Queens. Example: N-Queens. Example: Map-Coloring 4/7/17

Artificial Intelligence

CS 188: Artificial Intelligence. Recap: Search

Announcements. CS 188: Artificial Intelligence Spring Today. A* Review. Consistency. A* Graph Search Gone Wrong

Constraint Satisfaction Problems

CS 188: Artificial Intelligence Spring Announcements

CS 188: Artificial Intelligence Fall 2011

Space of Search Strategies. CSE 573: Artificial Intelligence. Constraint Satisfaction. Recap: Search Problem. Example: Map-Coloring 11/30/2012

CS 4100 // artificial intelligence

CS 188: Artificial Intelligence Fall 2011

Announcements. CS 188: Artificial Intelligence Fall 2010

CS W4701 Artificial Intelligence

Outline. Best-first search

CS 188: Artificial Intelligence Spring Announcements

Recap: Search Problem. CSE 473: Artificial Intelligence. Space of Search Strategies. Constraint Satisfaction. Example: N-Queens 4/9/2012

Reading: Chapter 6 (3 rd ed.); Chapter 5 (2 nd ed.) For next week: Thursday: Chapter 8

CS 343: Artificial Intelligence

10/11/2017. Constraint Satisfaction Problems II. Review: CSP Representations. Heuristic 1: Most constrained variable

What is Search For? CS 188: Artificial Intelligence. Constraint Satisfaction Problems

Announcements. Homework 4. Project 3. Due tonight at 11:59pm. Due 3/8 at 4:00pm

CS 188: Artificial Intelligence. What is Search For? Constraint Satisfaction Problems. Constraint Satisfaction Problems

What is Search For? CS 188: Artificial Intelligence. Example: Map Coloring. Example: N-Queens. Example: N-Queens. Constraint Satisfaction Problems

Announcements. Homework 1: Search. Project 1: Search. Midterm date and time has been set:

Announcements. Reminder: CSPs. Today. Example: N-Queens. Example: Map-Coloring. Introduction to Artificial Intelligence

Constraint Satisfaction Problems

Announcements. CS 188: Artificial Intelligence Fall Reminder: CSPs. Today. Example: 3-SAT. Example: Boolean Satisfiability.

CS 188: Artificial Intelligence Fall 2008

Iterative improvement algorithms. Today. Example: Travelling Salesperson Problem. Example: n-queens

Week 8: Constraint Satisfaction Problems

Announcements. CS 188: Artificial Intelligence Spring Today. Example: Map-Coloring. Example: Cryptarithmetic.

Artificial Intelligence Constraint Satisfaction Problems

Constraint Satisfaction Problems Part 2

DIT411/TIN175, Artificial Intelligence. Peter Ljunglöf. 30 January, 2018

Constraints. CSC 411: AI Fall NC State University 1 / 53. Constraints

CS 188: Artificial Intelligence

CS 188: Artificial Intelligence

Foundations of Artificial Intelligence

CS 771 Artificial Intelligence. Constraint Satisfaction Problem

Announcements. CS 188: Artificial Intelligence Spring Production Scheduling. Today. Backtracking Search Review. Production Scheduling

Material. Thought Question. Outline For Today. Example: Map-Coloring EE562 ARTIFICIAL INTELLIGENCE FOR ENGINEERS

Constraint Satisfaction Problems

Constraint Satisfaction Problems. slides from: Padhraic Smyth, Bryan Low, S. Russell and P. Norvig, Jean-Claude Latombe

Today. CS 188: Artificial Intelligence Fall Example: Boolean Satisfiability. Reminder: CSPs. Example: 3-SAT. CSPs: Queries.

Spezielle Themen der Künstlichen Intelligenz

Constraint Satisfaction Problems. Chapter 6

Constraint Satisfaction Problems

Lecture 18. Questions? Monday, February 20 CS 430 Artificial Intelligence - Lecture 18 1

Constraint Satisfaction Problems Chapter 3, Section 7 and Chapter 4, Section 4.4 AIMA Slides cstuart Russell and Peter Norvig, 1998 Chapter 3, Section

CS 188: Artificial Intelligence Spring Today

ARTIFICIAL INTELLIGENCE (CS 370D)

Constraint satisfaction problems. CS171, Winter 2018 Introduction to Artificial Intelligence Prof. Richard Lathrop

Constraint Satisfaction Problems

Constraint Satisfaction Problems (CSPs) Introduction and Backtracking Search

Lars Schmidt-Thieme, Information Systems and Machine Learning Lab (ISMLL), University of Hildesheim, Germany, Course on Artificial Intelligence,

CS 188: Artificial Intelligence

Map Colouring. Constraint Satisfaction. Map Colouring. Constraint Satisfaction

Constraint Satisfaction Problems

Constraint Satisfaction Problems

Outline. Best-first search

What is Search For? CS 188: Ar)ficial Intelligence. Constraint Sa)sfac)on Problems Sep 14, 2015

K-Consistency. CS 188: Artificial Intelligence. K-Consistency. Strong K-Consistency. Constraint Satisfaction Problems II

Games and Adversarial Search II Alpha-Beta Pruning (AIMA 5.3)

CONSTRAINT SATISFACTION

Artificial Intelligence

Artificial Intelligence

Example: Map coloring

Solving Problems by Searching: Constraint Satisfaction Problems

Constraint Satisfaction. CS 486/686: Introduction to Artificial Intelligence

Constraint Satisfaction Problems

Constraint Satisfaction Problems

CMU-Q Lecture 7: Searching in solution space Constraint Satisfaction Problems (CSPs) Teacher: Gianni A. Di Caro

DIT411/TIN175, Artificial Intelligence. Peter Ljunglöf. 6 February, 2018

Mathematical Programming Formulations, Constraint Programming

CS 4100/5100: Foundations of AI

Artificial Intelligence, CS, Nanjing University Spring, 2018, Yang Yu. Lecture 5: Search 4.

CSE 573: Artificial Intelligence

Discussion Section Week 1

CS 188: Artificial Intelligence. Recap Search I

General Methods and Search Algorithms

Moving to a different formalism... SEND + MORE MONEY

CONSTRAINT SATISFACTION

AI Fundamentals: Constraints Satisfaction Problems. Maria Simi

Set 5: Constraint Satisfaction Problems

Local Search for CSPs

Transcription:

Lecture 6: Constraint Satisfaction Problems (CSPs) CS 580 (001) - Spring 2018 Amarda Shehu Department of Computer Science George Mason University, Fairfax, VA, USA February 28, 2018 Amarda Shehu (580) 1

1 Outline of Today s Class 2 CSP Examples 3 Backtracking Search for CSPs 4 Problem Structure and Problem Decomposition 5 Local Search for CSPs 6 Take-home Problem 7 CSP Summary Amarda Shehu (580) Outline of Today s Class 2

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 X i with values from domain D i 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 Amarda Shehu (580) CSP Examples 3

Example: Map-Coloring Variables WA, NT, Q, NSW, V, SA, T Domains D i = {red, green, blue} Constraints: adjacent regions must have different colors e.g., WA NT (if the language allows this), or (WA, NT ) {(red, green), (red, blue), (green, red), (green, blue),...} Amarda Shehu (580) CSP Examples 4

Example: Map-Coloring Continued Solutions are assignments satisfying all constraints, e.g., {WA = red, NT = green, Q = red, NSW = green, V = red, SA = blue, T = green} Amarda Shehu (580) CSP Examples 5

Constraint Graph Binary CSP: each constraint relates at most two variables Constraint graph: nodes are variables, arcs show constraints General-purpose CSP algorithms use the graph structure to speed up search. E.g., Tasmania is an independent subproblem! Amarda Shehu (580) CSP Examples 6

Varieties of CSPs Discrete variables finite domains; size d = O(d n ) 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., StartJob 1 + 5 StartJob 3 linear constraints solvable, nonlinear undecidable Continuous variables e.g., start/end times for Hubble Telescope observations linear constraints solvable in polynomial time by linear programming (LP) Amarda Shehu (580) CSP Examples 7

Varieties of Constraints Unary constraints involve a single variable e.g., SA green Binary constraints involve pairs of variables e.g., SA WA Higher-order constraints involve 3 or more variables e.g., cryptarithmetic column constraints Strong vs. soft constraints Preferences (soft constraints) e.g., red is better than green often representable by a cost for each variable assignment constrained optimization problems Amarda Shehu (580) CSP Examples 8

Example: Cryptarithmetic Variables: F T U W R O X 1 X 2 X 3 Domains: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} Constraints alldiff(f, T, U, W, R, O) O + O = R + 10 X 1, etc. Amarda Shehu (580) CSP Examples 9

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 Real-world problems almost always involve real-valued variables Amarda Shehu (580) CSP Examples 10

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 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 l)d at depth l, hence n!d n leaves!!!! Amarda Shehu (580) Backtracking Search for CSPs 11

Backtracking Search Variable assignments are commutative, i.e., [WA = red then NT = green] same as [NT = green then WA = red] Only need to consider assignments to a single variable at each node = b = d and there are d n 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 Amarda Shehu (580) Backtracking Search for CSPs 12

Backtracking Search function Backtracking-Search(csp) returns solution/failure return Backtrack({ }, csp) function Backtrack(assignment, csp) returns soln/failure if assignment is complete then return assignment var Select-Unassigned-Variable(csp, assignment) 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(var, assignment, csp) 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 Amarda Shehu (580) Backtracking Search for CSPs 13

Backtracking Example Amarda Shehu (580) Backtracking Search for CSPs 14

Backtracking Example Amarda Shehu (580) Backtracking Search for CSPs 15

Backtracking Example Amarda Shehu (580) Backtracking Search for CSPs 16

Backtracking Example Amarda Shehu (580) Backtracking Search for CSPs 17

Improving Backtracking Efficiency General-purpose methods can give huge gains in speed: 1 Which variable should be assigned next? [SELECT-UNASSIGNED-VARIABLE] 2 In what order should its values be tried? [ORDER-DOMAIN-VALUES] 3 Can we detect inevitable failure early? [INFERENCE] 4 Can we take advantage of problem structure? Amarda Shehu (580) Backtracking Search for CSPs 18

Minimum Remaining Values Minimum remaining values (MRV) for var SELECT-UNASSIGNED-VAR(csp, assignment): choose the variable with the fewest legal values also called most constrained variable or fail-first heuristic to prune search tree... but MRV heuristic does not help in selecting the first variable Amarda Shehu (580) Backtracking Search for CSPs 19

Minimum Remaining Values Minimum remaining values (MRV) for var SELECT-UNASSIGNED-VAR(csp, assignment): choose the variable with the fewest legal values also called most constrained variable or fail-first heuristic to prune search tree... but MRV heuristic does not help in selecting the first variable Amarda Shehu (580) Backtracking Search for CSPs 19

Degree Heuristic Tie-breaker among MRV variables Degree heuristic: choose the variable with the most constraints on remaining variables called degree heuristic because can get this information from constraint graph attempts to reduce branching factor on future choices Amarda Shehu (580) Backtracking Search for CSPs 20

Least Constraining Value Heuristic Least Constraining Value Heuristic for: var ORDER-DOMAIN-VALUES(var, assignment, csp) Given a variable, choose the least constraining value: selects value that rules out the fewest values in the remaining variables Goal is to reach one complete assignment fast Combining above heuristics makes 1000 queens feasible When all solutions/complete assignments needed, LCV is irrelevant Amarda Shehu (580) Backtracking Search for CSPs 21

Inference Idea: Infer reductions in the domain of variables When: Before and/or during the backtracking search itself How: Constraint propagation Algorithms: Forward Checking, AC-3 Amarda Shehu (580) Backtracking Search for CSPs 22

Simplest Form of Inference: Forward Checking Idea: Keep track of remaining legal values for unassigned variables Idea: Terminate search when any variable has no legal values Amarda Shehu (580) Backtracking Search for CSPs 23

Forward Checking Idea: Keep track of remaining legal values for unassigned variables Idea: Terminate search when any variable has no legal values Amarda Shehu (580) Backtracking Search for CSPs 24

Forward Checking Idea: Keep track of remaining legal values for unassigned variables Idea: Terminate search when any variable has no legal values Amarda Shehu (580) Backtracking Search for CSPs 25

Constraint Propagation Forward checking propagates information from assigned to unassigned variables: Forward checking establishes arc consistency whenever a var X is assigned, domains of neighbors Y of X in constraint graph are reduced for each unassigned var Y that is connected to X by a constraint, delete from Y s domain any value that is inconsistent with the value chosen for X Amarda Shehu (580) Backtracking Search for CSPs 26

Constraint Propagation Forward checking propagates information from assigned to unassigned variables, but doesn t provide early detection for all failures: BUT: NT and SA cannot both be blue! Constraint propagation repeatedly enforces constraints locally, and does not chase arc consistency When the domain of a neighbor Y of X is reduced, domains of neighbors of Y may also become inconsistent (e.g.: NT and SA ) Amarda Shehu (580) Backtracking Search for CSPs 27

Back to Arc Consistency Simplest form of constraint propagation makes each arc consistent X Y is consistent iff for every value x of X there is some allowed value y of Y Amarda Shehu (580) Backtracking Search for CSPs 28

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 value y of Y Amarda Shehu (580) Backtracking Search for CSPs 29

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 value y of Y If a variable loses a value, its neighbors in the constraint graph need to be rechecked Amarda Shehu (580) Backtracking Search for CSPs 30

Maintaining Arc Consistency More powerful idea than forward checking: If a variable loses a value, its neighbors in the constraint graph need to be rechecked Recursively propagates constraints when changes are made to domains of variables This recursive constraint propagation approach detects failure earlier than forward checking Can be preprocessing or run after each assignment (INFERENCE) in the backtracking search algorithm Algorithm: Maintaining Arc Consistency (MAC), also known as AC-3 Amarda Shehu (580) Backtracking Search for CSPs 31

Maintaining Arc Consistency (MAC) Algorithm function AC-3( csp) returns the CSP, possibly with reduced domains inputs: csp, a binary CSP with variables {X 1, X 2,..., X n } local variables: queue, a queue of arcs, initially all the arcs in csp while queue is not empty do (X i, X j ) Remove-First(queue) if Remove-Inconsistent-Values(X i, X j ) then for each X k in Neighbors[X i ] do add (X k, X i ) to queue function Remove-Inconsistent-Values( X i, X j ) returns true iff succeeds removed false for each x in Domain[X i ] do if no value y in Domain[X j ] allows (x,y) to satisfy the constraint X i X j then delete x from Domain[X i ] removed true return removed Amarda Shehu (580) Backtracking Search for CSPs 32

Time Complexity Arc Consistency Algorithm Given: c constraints, d values in the domain of each variable X i How many (X k, X i ) arces will be added to the queue when pruning domain of some X i? Amarda Shehu (580) Backtracking Search for CSPs 33

Time Complexity Arc Consistency Algorithm Given: c constraints, d values in the domain of each variable X i How many (X k, X i ) arces will be added to the queue when pruning domain of some X i? at most deg(x i ) Amarda Shehu (580) Backtracking Search for CSPs 33

Time Complexity Arc Consistency Algorithm Given: c constraints, d values in the domain of each variable X i How many (X k, X i ) arces will be added to the queue when pruning domain of some X i? at most deg(x i ) How many is this over all variables? Amarda Shehu (580) Backtracking Search for CSPs 33

Time Complexity Arc Consistency Algorithm Given: c constraints, d values in the domain of each variable X i How many (X k, X i ) arces will be added to the queue when pruning domain of some X i? at most deg(x i ) How many is this over all variables? sum over all degrees is O(E) of constraint graph Amarda Shehu (580) Backtracking Search for CSPs 33

Time Complexity Arc Consistency Algorithm Given: c constraints, d values in the domain of each variable X i How many (X k, X i ) arces will be added to the queue when pruning domain of some X i? at most deg(x i ) How many is this over all variables? sum over all degrees is O(E) of constraint graph which is O(c) Amarda Shehu (580) Backtracking Search for CSPs 33

Time Complexity Arc Consistency Algorithm Given: c constraints, d values in the domain of each variable X i How many (X k, X i ) arces will be added to the queue when pruning domain of some X i? at most deg(x i ) How many is this over all variables? sum over all degrees is O(E) of constraint graph which is O(c) How often will the domain of each variable be pruned? Amarda Shehu (580) Backtracking Search for CSPs 33

Time Complexity Arc Consistency Algorithm Given: c constraints, d values in the domain of each variable X i How many (X k, X i ) arces will be added to the queue when pruning domain of some X i? at most deg(x i ) How many is this over all variables? sum over all degrees is O(E) of constraint graph which is O(c) How often will the domain of each variable be pruned? cannot be more than the actual size of the domain Amarda Shehu (580) Backtracking Search for CSPs 33

Time Complexity Arc Consistency Algorithm Given: c constraints, d values in the domain of each variable X i How many (X k, X i ) arces will be added to the queue when pruning domain of some X i? at most deg(x i ) How many is this over all variables? sum over all degrees is O(E) of constraint graph which is O(c) How often will the domain of each variable be pruned? cannot be more than the actual size of the domain...so...o(d) times Amarda Shehu (580) Backtracking Search for CSPs 33

Time Complexity Arc Consistency Algorithm Given: c constraints, d values in the domain of each variable X i How many (X k, X i ) arces will be added to the queue when pruning domain of some X i? at most deg(x i ) How many is this over all variables? sum over all degrees is O(E) of constraint graph which is O(c) How often will the domain of each variable be pruned? cannot be more than the actual size of the domain...so...o(d) times In total, how many arces (X k, X i ) will be added to the queue over all variables? Amarda Shehu (580) Backtracking Search for CSPs 33

Time Complexity Arc Consistency Algorithm Given: c constraints, d values in the domain of each variable X i How many (X k, X i ) arces will be added to the queue when pruning domain of some X i? at most deg(x i ) How many is this over all variables? sum over all degrees is O(E) of constraint graph which is O(c) How often will the domain of each variable be pruned? cannot be more than the actual size of the domain...so...o(d) times In total, how many arces (X k, X i ) will be added to the queue over all variables? O(cd) Amarda Shehu (580) Backtracking Search for CSPs 33

Time Complexity Arc Consistency Algorithm Given: c constraints, d values in the domain of each variable X i How many (X k, X i ) arces will be added to the queue when pruning domain of some X i? at most deg(x i ) How many is this over all variables? sum over all degrees is O(E) of constraint graph which is O(c) How often will the domain of each variable be pruned? cannot be more than the actual size of the domain...so...o(d) times In total, how many arces (X k, X i ) will be added to the queue over all variables? O(cd) How long does it take to check consistency of an arc? Amarda Shehu (580) Backtracking Search for CSPs 33

Time Complexity Arc Consistency Algorithm Given: c constraints, d values in the domain of each variable X i How many (X k, X i ) arces will be added to the queue when pruning domain of some X i? at most deg(x i ) How many is this over all variables? sum over all degrees is O(E) of constraint graph which is O(c) How often will the domain of each variable be pruned? cannot be more than the actual size of the domain...so...o(d) times In total, how many arces (X k, X i ) will be added to the queue over all variables? O(cd) How long does it take to check consistency of an arc? O(d 2 ) Amarda Shehu (580) Backtracking Search for CSPs 33

Time Complexity Arc Consistency Algorithm Given: c constraints, d values in the domain of each variable X i How many (X k, X i ) arces will be added to the queue when pruning domain of some X i? at most deg(x i ) How many is this over all variables? sum over all degrees is O(E) of constraint graph which is O(c) How often will the domain of each variable be pruned? cannot be more than the actual size of the domain...so...o(d) times In total, how many arces (X k, X i ) will be added to the queue over all variables? O(cd) How long does it take to check consistency of an arc? O(d 2 ) So, putting it all together: T (AC 3) O(cd 3 ) Amarda Shehu (580) Backtracking Search for CSPs 33

Time Complexity Arc Consistency Algorithm Given: c constraints, d values in the domain of each variable X i How many (X k, X i ) arces will be added to the queue when pruning domain of some X i? at most deg(x i ) How many is this over all variables? sum over all degrees is O(E) of constraint graph which is O(c) How often will the domain of each variable be pruned? cannot be more than the actual size of the domain...so...o(d) times In total, how many arces (X k, X i ) will be added to the queue over all variables? O(cd) How long does it take to check consistency of an arc? O(d 2 ) So, putting it all together: T (AC 3) O(cd 3 ) Amarda Shehu (580) Backtracking Search for CSPs 33

Problem Structure Tasmania and mainland are independent subproblems Identifiable as connected components of constraint graph Amarda Shehu (580) Problem Structure and Problem Decomposition 34

Problem Structure continued Suppose each subproblem has c variables out of n total Worst-case solution cost is n/c d c, linear in n E.g., n = 80, d = 2, c = 20 2 80 = 4 billion years at 10 million nodes/sec 4 2 20 = 0.4 seconds at 10 million nodes/sec Amarda Shehu (580) Problem Structure and Problem Decomposition 35

Tree-structured CSPs Theorem: if the constraint graph has no cycles (so, it s a tree), the CSP can be solved in O(n d 2 ) time Compare to general CSPs, where worst-case time is O(d n ) This property also applies to logical and probabilistic reasoning: an important example of the relation between syntactic restrictions and the complexity of reasoning. Amarda Shehu (580) Problem Structure and Problem Decomposition 36

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 2. For j from n down to 2, apply RemoveInconsistent(Parent(X j ), X j ) 3. For j from 1 to n, assign X j consistently with Parent(X j ) Amarda Shehu (580) Problem Structure and Problem Decomposition 37

Nearly Tree-structured CSPs Conditioning: instantiate a variable, prune its neighbors domains Cutset conditioning: instantiate (in all ways) a set of variables such that the remaining constraint graph is a tree Cutset size c = runtime O(d c (n c)d 2 ), very fast for small c Amarda Shehu (580) Problem Structure and Problem Decomposition 38

Iterative Algorithms for CSPs Hill-climbing, simulated annealing typically work with complete states, i.e., all variables assigned To apply to CSPs: allow states with unsatisfied constraints operators reassign variable values Variable selection: randomly select any conflicted variable Value selection by min-conflicts heuristic: choose value that violates the fewest constraints i.e., hill-climber with h(n) = total number of violated constraints Take-home: Propose a simple EA for 4-queens CSP Amarda Shehu (580) Local Search for CSPs 39

Example: 4-Queens as CSP States: Amarda Shehu (580) Local Search for CSPs 40

Example: 4-Queens as CSP States: 4 queens in 4 columns (4 4 = 256 states) Amarda Shehu (580) Local Search for CSPs 40

Example: 4-Queens as CSP States: 4 queens in 4 columns (4 4 = 256 states) Operators: Amarda Shehu (580) Local Search for CSPs 40

Example: 4-Queens as CSP States: 4 queens in 4 columns (4 4 = 256 states) Operators: move queen in column Amarda Shehu (580) Local Search for CSPs 40

Example: 4-Queens as CSP States: 4 queens in 4 columns (4 4 = 256 states) Operators: move queen in column Goal test: Amarda Shehu (580) Local Search for CSPs 40

Example: 4-Queens as CSP States: 4 queens in 4 columns (4 4 = 256 states) Operators: move queen in column Goal test: no attacks Amarda Shehu (580) Local Search for CSPs 40

Example: 4-Queens as CSP States: 4 queens in 4 columns (4 4 = 256 states) Operators: move queen in column Goal test: no attacks Evaluation: Amarda Shehu (580) Local Search for CSPs 40

Example: 4-Queens as CSP States: 4 queens in 4 columns (4 4 = 256 states) Operators: move queen in column Goal test: no attacks Evaluation: h(n) = number of attacks Amarda Shehu (580) Local Search for CSPs 40

Example: 4-Queens as CSP States: 4 queens in 4 columns (4 4 = 256 states) Operators: move queen in column Goal test: no attacks Evaluation: h(n) = number of attacks Amarda Shehu (580) Local Search for CSPs 40

Performance of Min-conflicts Given random initial state, can solve n-queens in almost constant time for arbitrary n with high probability (e.g., n = 10,000,000) The same appears to be true for any randomly-generated CSP except in a narrow range of the ratio R = number of constraints number of variables Amarda Shehu (580) Local Search for CSPs 41

4-Queens as a CSP Work through the 4-queens as CSP in greater detail Assume one queen in each column. Which row does each one go in? Amarda Shehu (580) Take-home Problem 42

4-Queens as a CSP Work through the 4-queens as CSP in greater detail Assume one queen in each column. Which row does each one go in? Variables Q 1, Q 2, Q 3, Q 4 Amarda Shehu (580) Take-home Problem 42

4-Queens as a CSP Work through the 4-queens as CSP in greater detail Assume one queen in each column. Which row does each one go in? Variables Q 1, Q 2, Q 3, Q 4 Domains D i = {1, 2, 3, 4} Amarda Shehu (580) Take-home Problem 42

4-Queens as a CSP Work through the 4-queens as CSP in greater detail Assume one queen in each column. Which row does each one go in? Variables Q 1, Q 2, Q 3, Q 4 Domains D i = {1, 2, 3, 4} Constraints Q i Q j (cannot be in same row) Q i Q j i j (or same diagonal) Amarda Shehu (580) Take-home Problem 42

4-Queens as a CSP Work through the 4-queens as CSP in greater detail Assume one queen in each column. Which row does each one go in? Variables Q 1, Q 2, Q 3, Q 4 Domains D i = {1, 2, 3, 4} Constraints Q i Q j (cannot be in same row) Q i Q j i j (or same diagonal) Translate each constraint into set of allowable values for its variables Amarda Shehu (580) Take-home Problem 42

4-Queens as a CSP Work through the 4-queens as CSP in greater detail Assume one queen in each column. Which row does each one go in? Variables Q 1, Q 2, Q 3, Q 4 Domains D i = {1, 2, 3, 4} Constraints Q i Q j (cannot be in same row) Q i Q j i j (or same diagonal) Translate each constraint into set of allowable values for its variables E.g., values for (Q 1, Q 2) are (1, 3) (1, 4) (2, 4) (3, 1) (4, 1) (4, 2) Amarda Shehu (580) Take-home Problem 42

CSP Summary CSPs are a special kind of search problems: 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 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 Amarda Shehu (580) CSP Summary 43