0% found this document useful (0 votes)
17 views166 pages

Constraint Satisfaction Problems

The document discusses Constraint Satisfaction Problems (CSPs), which are a class of search problems focused on assigning values to variables under specific constraints. It highlights the importance of CSPs in various real-world applications such as scheduling and assignment problems, and outlines methods for solving them, including backtracking search and filtering techniques. Examples such as map coloring, Sudoku, and N-Queens illustrate the concepts and techniques used in CSPs.

Uploaded by

egemen06292
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views166 pages

Constraint Satisfaction Problems

The document discusses Constraint Satisfaction Problems (CSPs), which are a class of search problems focused on assigning values to variables under specific constraints. It highlights the importance of CSPs in various real-world applications such as scheduling and assignment problems, and outlines methods for solving them, including backtracking search and filtering techniques. Examples such as map coloring, Sudoku, and N-Queens illustrate the concepts and techniques used in CSPs.

Uploaded by

egemen06292
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 166

1

Constraint Satisfaction
Problems
Artificial Intelligence

Slides are mostly adapted from AIMA, MIT Open Courseware


Svetlana Lazebnik (UIUC) and Manuela Veloso (CMU)
2
3

What is Search For?


• Planning: sequences of actions
– The path to the goal is the important thing
– Paths have various costs, depths
– Heuristics give problem-specific guidance

• Identification: assignments to variables


– Assign values to variables while respecting certain constraints
– The goal is a complete, consistent assignment
– All paths the same depth (for some formulations)
– The goal itself is important, not the path

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


4

Constraint Satisfaction Problems


CSP is a special class of search problems
 Mostly identification problems
 Have specialized algorithms for them
Standard search problems:
 State is an arbitrary data structure
 Goal test can be any function over states
Constraint satisfaction problems (CSPs):
 State is defined by variables Xi with values
from a domain D (sometimes D depends on i)
 Goal test is a set of constraints specifying
allowable combinations of values for subsets
of variables
 Solution is a complete, consistent assignment

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


6

Why study CSPs?

Many real-world problems can be formulated as CSPs


 Assignment problems: e.g., who teaches what class
 Timetabling problems: e.g., which class is offered when and where?
 Hardware configuration
 Transportation scheduling
 Factory scheduling
 Circuit layout
 Fault diagnosis
 … lots more!

 Sometimes involve real-valued variables…

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


7
8

Graph Coloring
10

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

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


11

Example: Map Coloring

• Solutions are complete and consistent assignments assignments


satisfying all constraints, e.g
• WA = red, NT = green, Q = red, NSW = green,
V = red, SA = blue, T = green

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


12

Constraint Graphs

 Binary CSP: each constraint relates (at most) two


variables

 Binary 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!

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


13

Varieties of CSPs and Constraints

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


14

Example: N-Queens
• Formulation 1:
– Variables:
– Domains:
– Constraints

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


15

Example: N-Queens

• Formulation 2:
– Variables:

– Domains:

– Constraints:

Implicit:

Explicit:

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


21

Example: Sudoku

• Variables: Each
(open) square

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

• Constraints:
9-way alldiff for each column
9-way alldiff for each row
9-way alldiff for each region
(or can have a bunch
of pairwise inequality
constraints)

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


23

Varieties of CSPs
• Discrete Variables
– Finite domains
• Size d means O(dn) complete assignments
• E.g., Boolean CSPs, including Boolean satisfiability (NP-complete)
– Infinite domains (integers, strings, etc.)
• E.g., job scheduling, variables are start/end times for each job
• Linear constraints solvable, nonlinear undecidable

• Continuous variables
– E.g., start/end times for Hubble Telescope observations
– Linear constraints solvable in polynomial time

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


24

Varieties of Constraints

Varieties of Constraints
– Unary constraints involve a single variable
(equivalent to reducing domains), e.g.:

– Binary constraints involve pairs of variables, e.g.:

– Higher-order constraints involve 3 or more


variables:

• Preferences (soft constraints):


• E.g., red is better than green
• Often representable by a cost for each variable assignment
• Gives constrained optimization problems

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


29

Example: Cryptarithmetic

• Variables: T, W, O, F, U, R
X1, X2 X2 X 1
• 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
30

Example: Line drawing interpretation

An example polyhedron:

Variables: edges

Domains: +, –, , 

Desired output:

David Waltz, 1975


31

Example: Line drawing interpretation

Constraints imposed by each vertex type:

Four vertex types:

David Waltz, 1975


32
33

Real-world CSPs

• Assignment problems
– e.g., who teaches what class
• Timetable problems
– e.g., which class is offered when and where?
• Transportation scheduling
• Factory scheduling

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


34
39
40

Slide credit : HarvardX CS50AICS50's Introduction to Artificial Intelligence with Python,


David J. Malan and Brian Yu
41

Slide credit : HarvardX CS50AICS50's Introduction to Artificial Intelligence with Python,


David J. Malan and Brian Yu
42

Slide credit : HarvardX CS50AICS50's Introduction to Artificial Intelligence with Python,


David J. Malan and Brian Yu
43

Slide credit : HarvardX CS50AICS50's Introduction to Artificial Intelligence with Python,


David J. Malan and Brian Yu
44

Slide credit : HarvardX CS50AICS50's Introduction to Artificial Intelligence with Python,


David J. Malan and Brian Yu
45

Slide credit : HarvardX CS50AICS50's Introduction to Artificial Intelligence with Python,


David J. Malan and Brian Yu
unary constraint involving only one variable 46

{A ≠ Monday}
• node consistency when all the values in a variable's domain
satisfy the variable's unary constraints

Slide credit : HarvardX CS50AICS50's Introduction to Artificial Intelligence with Python,


David J. Malan and Brian Yu
binary constraint involving two variables 47

{A ≠ B}
• arc consistency when all the values in a variable's domain
satisfy the variable's binary constraints

• To make X arc-consistent with respect to Y, remove elements


from X's domain until every choice for X has a possible choice
for Y

Slide credit : HarvardX CS50AICS50's Introduction to Artificial Intelligence with Python,


David J. Malan and Brian Yu
48
49

Slide credit : HarvardX CS50AICS50's Introduction to Artificial Intelligence with Python,


David J. Malan and Brian Yu
50
51
52

Slide credit : HarvardX CS50AICS50's Introduction to Artificial Intelligence with Python,


David J. Malan and Brian Yu
53

Solving CSPs

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


54

Standard Search Formulation

• Standard search formulation of CSPs

• States defined by the values assigned


so far (partial assignments)
– Initial state: the empty assignment, {}
– Successor function: assign a value to
an unassigned variable
– Goal test: the current assignment is
complete and satisfies all constraints

• We’ll start with the straightforward,


naïve approach, then improve it

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


55

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
56

Depth First Search

• At each node, assign a


value from the domain
to the variable
• Check feasibility
(constraints) when the
assignment is complete

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


57

Poll 1: Search for CSPs

Should we use BFS or DFS?

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


58

CSP as a Standard search problem


59

CSP as a Standard search problem


60
61
62

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! · mn (this is bad)

• How can we reduce the branching factor?


64

Backtracking Search

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


65

Backtracking Search
Backtracking search is the basic uninformed algorithm for
solving CSPs
Backtracking search = DFS + two improvements

Idea 1: One variable at a time


– Variable assignments are commutative
• [WA = red then NT = green] same as [NT = green then WA = red]
– Only need to consider assign value to a single variable at each step

Idea 2: Check constraints as you go


– Consider only values which do not conflict previous assignments
– May need some computation to check the constraints
– “Incremental goal test”
Can solve n-queens for n  25

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


66

Backtracking Search

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


67

Backtracking DFS

For every possible value x in D:


– If assigning x to the next unassigned variable
Vk+1 does not violate any constraint with the k
already assigned variables:
• Set the variable Vk+1 to x
• Evaluate the successors of the current state with this variable assignment
• If no valid assignment is found:
Backtrack to previous state
• Stop as soon as a solution is found
68
69

Backtracking search algorithm


74

Backtracking Example

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


75
76
77
78
79
80

Slide credit : HarvardX CS50AICS50's Introduction to Artificial Intelligence with Python,


David J. Malan and Brian Yu
81

Slide credit : HarvardX CS50AICS50's Introduction to Artificial Intelligence with Python,


David J. Malan and Brian Yu
82

Slide credit : HarvardX CS50AICS50's Introduction to Artificial Intelligence with Python,


David J. Malan and Brian Yu
83

Slide credit : HarvardX CS50AICS50's Introduction to Artificial Intelligence with Python,


David J. Malan and Brian Yu
84

Slide credit : HarvardX CS50AICS50's Introduction to Artificial Intelligence with Python,


David J. Malan and Brian Yu
85

Slide credit : HarvardX CS50AICS50's Introduction to Artificial Intelligence with Python,


David J. Malan and Brian Yu
86

Slide credit : HarvardX CS50AICS50's Introduction to Artificial Intelligence with Python,


David J. Malan and Brian Yu
87

Slide credit : HarvardX CS50AICS50's Introduction to Artificial Intelligence with Python,


David J. Malan and Brian Yu
88

Slide credit : HarvardX CS50AICS50's Introduction to Artificial Intelligence with Python,


David J. Malan and Brian Yu
89

Slide credit : HarvardX CS50AICS50's Introduction to Artificial Intelligence with Python,


David J. Malan and Brian Yu
90

Slide credit : HarvardX CS50AICS50's Introduction to Artificial Intelligence with Python,


David J. Malan and Brian Yu
91

Slide credit : HarvardX CS50AICS50's Introduction to Artificial Intelligence with Python,


David J. Malan and Brian Yu
92

Slide credit : HarvardX CS50AICS50's Introduction to Artificial Intelligence with Python,


David J. Malan and Brian Yu
93

Slide credit : HarvardX CS50AICS50's Introduction to Artificial Intelligence with Python,


David J. Malan and Brian Yu
94

Slide credit : HarvardX CS50AICS50's Introduction to Artificial Intelligence with Python,


David J. Malan and Brian Yu
95

Slide credit : HarvardX CS50AICS50's Introduction to Artificial Intelligence with Python,


David J. Malan and Brian Yu
96

Slide credit : HarvardX CS50AICS50's Introduction to Artificial Intelligence with Python,


David J. Malan and Brian Yu
97

Slide credit : HarvardX CS50AICS50's Introduction to Artificial Intelligence with Python,


David J. Malan and Brian Yu
98

Slide credit : HarvardX CS50AICS50's Introduction to Artificial Intelligence with Python,


David J. Malan and Brian Yu
99

Slide credit : HarvardX CS50AICS50's Introduction to Artificial Intelligence with Python,


David J. Malan and Brian Yu
100

Slide credit : HarvardX CS50AICS50's Introduction to Artificial Intelligence with Python,


David J. Malan and Brian Yu
101

Slide credit : HarvardX CS50AICS50's Introduction to Artificial Intelligence with Python,


David J. Malan and Brian Yu
102

Slide credit : HarvardX CS50AICS50's Introduction to Artificial Intelligence with Python,


David J. Malan and Brian Yu
103

Slide credit : HarvardX CS50AICS50's Introduction to Artificial Intelligence with Python,


David J. Malan and Brian Yu
104

Slide credit : HarvardX CS50AICS50's Introduction to Artificial Intelligence with Python,


David J. Malan and Brian Yu
105

Improving Backtracking

• General-purpose ideas give huge gains in speed

• Filtering: Can we detect inevitable failure


early?

• Ordering:
– Which variable should be assigned next?
– In what order should its values be tried?

• Structure: Can we exploit the problem structure?

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


106

Filtering

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


107

Filtering: Forward Checking

Filtering: Keep track of domains for unassigned


variables and cross off bad options

Forward checking: A simple way for filtering


– After a variable is assigned a value, check related constraints
and cross off values of unassigned variables which violate the
constraints
– Failure detected if some variables have no values remaining

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


109

Improving Backtracking Efficiency


• Making backtracking search efficient:
– Can we detect inevitable failure early?
– Which variable should be assigned next?
– In what order should its values be tried?
110

Early detection of failure

Apply inference to reduce the space of possible


assignments and detect failure early
111

Early detection of failure: Forward checking

• Keep track of remaining legal values for unassigned variables


• Terminate search when any variable has no legal values
112

Early detection of failure

Apply inference to reduce the space of possible


assignments and detect failure early
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
143

Filtering: Forward Checking


• Filtering: Keep track of domains for unassigned variables and cross off bad options
• Forward checking: A simple way for filtering
– After a variable is assigned a value, check related constraints
and cross off values of unassigned variables which violate the
constraints
– Failure detected if some variables have no values remaining

NT
Q
WA
SA
NSW

V
T

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


144

Filtering: Forward Checking


• Filtering: Keep track of domains for unassigned variables and cross off bad options
• Forward checking: A simple way for filtering
– After a variable is assigned a value, check related constraints
and cross off values of unassigned variables which violate the
constraints
– Failure detected if some variables have no values remaining

Recall: Binary constraint graph for a binary CSP (i.e., each constraint has
most two variables): nodes are variables, edges show constraints

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


145

Filtering: Forward Checking


• Filtering: Keep track of domains for unassigned variables and cross off bad options
• Forward checking: A simple way for filtering
– After a variable is assigned a value, check related constraints
and cross off values of unassigned variables which violate the
constraints
– Failure detected if some variables have no values remaining

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


146

Filtering: Forward Checking


• Filtering: Keep track of domains for unassigned variables and cross off bad options
• Forward checking: A simple way for filtering
– After a variable is assigned a value, check related constraints
and cross off values of unassigned variables which violate the
constraints
– Failure detected if some variables have no values remaining

FAIL – variable with no possible values

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


147

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
148

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

Consistent!
150

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


151

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


152

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


153

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
154

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


155

Arc consistency algorithm AC-3


156

Filtering: Constraint Propagation

• Limitations of simple 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! Why didn’t we detect this yet?
• Constraint propagation: reason from constraint to constraint

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


157

Consistency of A Single Arc

(Remove values from the tail!)

Recall: Binary constraint graph for a binary CSP (i.e., each constraint has
most two variables): nodes are variables, edges show constraints

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


158

Consistency of A Single Arc

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


159

How to Enforce Arc Consistency of Entire CSP

• A simplistic algorithm: Cycle over the pairs of variables, enforcing arc-consistency,


repeating the cycle until no domains change for a whole cycle
• AC-3 (short for Arc Consistency Algorithm #3): A more efficient algorithm ignoring
constraints that have not been modified since they were last analyzed

NT
Q
WA
SA
NSW

V
T

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


161

AC-3: Enforce Arc Consistency of Entire


CSP

Queue:
NT
Q
SA->WA
WA NT->WA
SA
NSW

V
T

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


162

AC-3: Enforce Arc Consistency of Entire


CSP

Queue:
NT
Q
NT->WA
WA WA->SA
SA
NSW NT->SA
V Q->SA
T
NSW->SA
V->SA

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


163

AC-3: Enforce Arc Consistency of Entire


CSP

Queue:
NT
Q
WA->SA
WA NT->SA
SA
NSW Q->SA
V NSW->SA
T
V->SA
WA->NT
SA->NT
Q->NT

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


164

AC-3: Enforce Arc Consistency of Entire


CSP

Queue:
NT
Q
WA->SA
WA NT->SA
SA
NSW Q->SA
V NSW->SA
T
V->SA
WA->NT
SA->NT
Q->NT

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


165

AC-3: Enforce Arc Consistency of Entire


CSP

Queue:
NT
Q
NT->SA
WA Q->SA
SA
NSW NSW->SA
V V->SA
T
WA->NT
SA->NT
Q->NT

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


166

AC-3: Enforce Arc Consistency of Entire


CSP

Queue:
NT
Q
Q->SA
WA NSW->SA
SA
NSW V->SA
V WA->NT
T
SA->NT
Q->NT

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


167

AC-3: Enforce Arc Consistency of Entire


CSP

Queue:
NT
Q
NSW->SA
WA V->SA
SA
NSW WA->NT
V SA->NT
T
Q->NT

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


168

AC-3: Enforce Arc Consistency of Entire


CSP

Queue:
NT
Q
WA
SA
NSW

V
T

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


169

Poll 2: After assigning Q to Green,


what gets added to the Queue?

Queue:
NT
Q
WA
SA
NSW

V
T

A: NSW->Q, SA->Q, NT->Q


B: Q->NSW, Q->SA, Q->NT

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


170

AC-3: Enforce Arc Consistency of Entire


CSP

Queue:
NT
Q
NT->Q
WA SA->Q
SA
NSW NSW->Q
V
T

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


171

AC-3: Enforce Arc Consistency of Entire


CSP

Queue:
NT
Q
SA->Q
WA NSW->Q
SA
NSW WA->NT
V SA->NT
T
Q->NT

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


172

AC-3: Enforce Arc Consistency of Entire


CSP

Queue:
NT
Q
NSW->Q
WA WA->NT
SA
NSW SA->NT
V Q->NT
T
WA->SA
NT->SA
Q->SA
NSW->SA
V->SA

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


173

AC-3: Enforce Arc Consistency of Entire


CSP

Queue:
WA->NT
NT
SA->NT
WA
Q Q->NT
SA
NSW
WA->SA
V NT->SA
T Q->SA
NSW->SA
V->SA
V->NSW
Q->NSW
SA->NSW

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


174

AC-3: Enforce Arc Consistency of Entire


CSP

Queue:
WA->NT
NT
SA->NT
WA
Q Q->NT
SA
NSW
WA->SA
V NT->SA
T Q->SA
NSW->SA
V->SA
V->NSW
Q->NSW
SA->NSW

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


175

AC-3: Enforce Arc Consistency of Entire


CSP

Queue:
SA->NT
NT
Q->NT
WA
Q WA->SA
SA
NSW
NT->SA
V Q->SA
T NSW->SA
!!! V->SA
V->NSW
Q->NSW
SA->NSW

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


176

AC-3: Enforce Arc Consistency of Entire


CSP

Queue:
SA->NT
NT
Q->NT
WA
Q WA->SA
SA
NSW
NT->SA
V Q->SA
T NSW->SA
!!! V->SA
V->NSW
Q->NSW
• Backtrack on the assignment of Q SA->NSW
• Arc consistency detects failure earlier than forward checking
• Can be run as a preprocessor or after each assignment
• What’s the downside of enforcing arc consistency?

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


183

Ordering

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


184
185
186
187
188
189
190
191
192

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
193

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
194

Given a variable, what should be the order of values?

• Choose the least constraining value:


– The value that rules out the fewest values in the remaining
variables
Which
assignment for
Q should we
choose?
195

Ordering: Minimum Remaining Values

• Variable Ordering: Minimum remaining values (MRV):


– Choose the variable with the fewest legal left values in its domain

• Why min rather than max?


• Also called “most constrained variable”
• “Fail-fast” ordering

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


196

Ordering: Least Constraining Value

• Value Ordering: Least Constraining Value


– Given a choice of variable, choose the least
constraining value
– i.e., the one that rules out the fewest values in
the remaining variables
– Note that it may take some computation to
determine this! (E.g., rerunning filtering)

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


197

Ordering: Least Constraining Value

• Value Ordering: Least Constraining Value


– Given a choice of variable, choose the least
constraining value
– i.e., the one that rules out the fewest values in the
remaining variables
– Note that it may take some computation to
determine this! (E.g., rerunning filtering)

• Why least rather than most?

• Combining these ordering ideas makes


1000 queens feasible

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


198

Summary: CSPs

Slide credit : Tuomas Sandholm and Vincent Conitzer (CMU), CS 15-281


199
200

You might also like