0% found this document useful (0 votes)
8 views

Ai09 Constraint Satisfaction Problems Part I Post Handout

Uploaded by

suresh merugu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Ai09 Constraint Satisfaction Problems Part I Post Handout

Uploaded by

suresh merugu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 44

Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

Artificial Intelligence
09. CSP, Part I: Basics, and Naı̈ve Search
What to Do When Your Problem is to Satisfy All These Constraints

Jana Koehler Álvaro Torralba

Summer Term 2019


Thanks to Prof. Hoffmann for slide sources

Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 1/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

Agenda

1 Introduction

2 Constraint Networks

3 Assignments, Consistency, Solutions

4 Naı̈ve Backtracking

5 Variable- and Value Ordering

6 Conclusion

Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 2/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

A (Constraint Satisfaction) Problem

→ Who’s going to play against who, when and where?


Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 4/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

Constraint Satisfaction Problems

What is a constraint?
A constraint is a condition that every solution must satisfy.

What is a constraint satisfaction problem?


Given:
A set of variables, each associated with its domain.
A set of constraints over these variables.

Find:
An assignment of variables to values (from the respective domains),
so that every constraint is satisfied.

Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 5/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

A Constraint Satisfaction Problem

→ Problem: SuDoKu.

Variables: Content of each cell.


Domains: Numbers 1, . . . , 9.
Constraints: Each number only once in each row, column, block.
Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 6/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

Another Constraint Satisfaction Problem

→ (Our Main Illustrative) Problem: Coloring Australia.

Northern
Territory
Western Queensland
Australia

South
Australia
New South Wales

Victoria

Tasmania

Variables: WA, NT, SA, Q, NSW, V, T.


Domains: red, green, blue.
Constraints: Adjacent states must have different colors.
Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 7/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

Another Constraint Satisfaction Problem

→ Problem: Graph Coloring. NP-hard for k = 3.

Northern
Territory
Western Queensland
Australia

South
Australia
New South Wales

Victoria

Tasmania

Variables: Vertices in a graph.


Domains: k different colors.
Constraints: Adjacent vertices must have different colors.
Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 7/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

Bundesliga Constraints
Variables: vAvs.B where A and B are teams, with domain {1, . . . , 34}:
For each match, the (ID of the) “Spieltag” where it is scheduled.

(Some) Constraints:
For all A, B: vAvs.B ≤ 17 < vBvs.A or
vBvs.A ≤ 17 < vAvs.B (each pairing exactly
once in each half-season).
For all A, B, C, D where
{A, B} ∩ {C, D} = 6 ∅: vAvs.B 6= vCvs.D
(each team only one match per day).
For all A, B, D: vAvs.B + 1 6= vAvs.D (each
team alternates between home matches and
away matches).
...

Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 8/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

How to Solve the Bundesliga Constraints?


Jörg’s personal pre-study attempts:
1 306 nested for-loops (for each of the 306 matches), each ranging from 1 to
306. Within the innermost loop, test whether the current values are (a) a
permutation and, if so, (b) a legal Bundesliga schedule.
→ Estimated runtime (on a Commodore 128): End of this universe, and
the next couple million ones after it . . .
2 Directly enumerate all permutations of the numbers 1, . . . , 306, test for
each whether it’s a legal Bundesliga schedule.
→ Estimated runtime: Maybe only the time span of a few thousand
universes.
3 View this as variables/constraints and use backtracking (This Chapter).
→ Executed runtime: About 1 minute.

How do they actually do it? Modern computers and CSP methods: fractions
of a second. 19th (20th/21st?) century: Combinatorics and manual work.

Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 9/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

Some Applications
Traveling Tournament Problem Scheduling

Timetabling Radio Frequency Assignment

Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 10/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

Our Agenda for This Topic

→ Our treatment of the topic “Constraint Satisfaction Problems”


consists of Chapters 8 and 9.

This Chapter: Basic definitions and concepts; naı̈ve backtracking


search.
→ Sets up the framework. Backtracking underlies many successful
algorithms for solving constraint satisfaction problems (and,
naturally, we start with the simplest version thereof).

Chapter 9: Inference and decomposition methods.


→ Inference reduces the search space of backtracking.
Decomposition methods break the probem into smaller pieces. Both
are crucial for efficiency in practice.

Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 11/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

Our Agenda for This Chapter

Constraint Networks and Assignments, Consistency, Solutions: How


are constraint satisfaction problems defined? What is a solution?
→ Get ourselves on firm ground.

Naı̈ve Backtracking: How does backtracking work? What are its main
weaknesses?
→ Serves to understand the basic workings of this wide-spread algorithm,
and to motivate its enhancements.

Variable- and Value Ordering: How should we give direction to a


backtracking search?
→ Simple methods for making backtracking aware of the structure of the
problem, and thereby reduce search.

Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 12/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

Constraint Networks: Informal


Constraint Networks: Informal Definition
A constraint network is defined by:
A finite set of variables.
A finite domain for each variable.
A set of constraints (here: binary relations).

→ We’re looking for a solution to the network, i.e., an assignment of


variables to values (from the respective domains), so that every
constraint is satisfied.

Terminology:
It is common to say constraint satisfaction problem (CSP) instead of
constraint network.
Strictly speaking, however, “CSP” is the algorithmic problem of
finding solutions to constraint networks.
Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 14/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

Constraint Networks: Formal


Definition (Constraint Network). A (binary) constraint network is a triple
γ = (V, D, C) where:
V = {v1 , . . . , vn } is a finite set of variables.
D = {Dv1 , . . . , Dvn } is a corresponding set of finite domains.
C = {C{u,v} } is a set of binary relations (constraints), where for each
C{u,v} we have u, v ∈ V , u 6= v, and C{u,v} ⊆ Du × Dv .
We require that C{u,v} , C{x,y} ∈ C =⇒ {u, v} = 6 {x, y}. We will write
Cuv instead of C{u,v} for brevity.
Notes:
Cuv = permissible combined assignments to u and v.
Relations are the maximally general formalization of constraints. In
illustrations, we often use abbreviations, e.g. “u 6= v” etc.
0
There is no point in having two constraints Cuv and Cuv constrain the
0
same variables u and v, because we can replace them by Cuv ∩ Cuv .
Cuv is identified by its set {u, v} of variables; the order we choose for the
relation is arbitrary.
Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 15/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

Example: Coloring Australia

Northern
Territory
Western Queensland
Australia

South
Australia
New South Wales

Victoria

Tasmania

Variables: V = {WA, NT , SA, Q, NSW , V , T }.


Domains: For all v ∈ V : Dv = {red , green, blue} =: D.
→ If all variables have the same domain, abusing notation we will
write D to denote that “global” domain.
Constraints: Cuv for adjacent states u and v, with Cuv =”u 6= v”,
i.e., Cuv = {(d, d0 ) ∈ D × D | d 6= d0 }.
Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 16/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

Constraint Networks: Variants


Extensions:
Infinite domains. (E.g., Dv = R in Linear Programming.)
Constraints of higher arity, i.e., relations over k > 2 variables. (E.g.,
propositional CNF satisfiability → Chapters 10 and 11.)

Unary Constraints:
A unary constraint is a relation Cv over a single variable, i.e., a
subset Cv ⊆ Dv of that variable’s domain.
A unary constraint Cv is equivalent to reducing the variable domain,
setting Dv := Cv .
Unary constraints are not needed at the formal level. They are often
convenient for modeling, i.e., to state “exceptions”. (E.g., Australia:
D global as on previous slide, but SA 6= green.)

Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 17/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

Example: SuDoKu

Variables: V = {vij | 1 ≤ i, j ≤ 9}: vij =cell row i column j.


Domains: For all v ∈ V : Dv = D = {1, . . . , 9}.
Unary Constraints: Cvij = {d} if cell i, j is pre-filled with d.
Binary Constraints: Cvij vi0 j 0 =”vij 6= vi0 j 0 ”, i.e.,
Cvij vi0 j 0 = {(d, d0 ) ∈ D × D | d 6= d0 }, for: i = i0 (same row), or
0 0
j = j 0 (same column), or (d 3i e, d 3j e) = (d i3 e, d j3 e) (same block).
Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 18/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

Questionnaire
→ Problem: Place 8 queens so that they don’t attack each other.

Question!
How to encode this into a constraint network? Variables?
Domains? Constraints?
→ E.g.: Variables: V = {v1 , . . . , v8 }: vi =row of queen in i-th column.
Domains: Dv = D = {1, . . . , 8}. Constraints For 1 ≤ i < j ≤ 8:
Cvi vj = {(d, d0 ) ∈ D × D | d 6= d0 and |d − d0 | =
6 |i − j|}.
Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 19/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

CSP and General Problem Solving

(some new constraint-reasoning problem)

describe problem as a constraint network 7→ use off-the-shelf CSP solver

(its solution)

Constraint networks=generic language to describe this kind of


problem.
CSP solvers=generic algorithms solving such problems.
The next time you play SuDoKu, just write the game down in CSP
format and use an off-the-shelf solver.
On the first practical exercise sheet, this is the kind of thing you will
be doing . . .
Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 20/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

Assignments and Consistency

Definition (Assignment). Let γ = (V, D, C) S be a constraint 0network.


0
A partial assignment is a function a : V 7→ v∈V Dv where V ⊆ V and
a(v) ∈ Dv for all v ∈ V 0 . If V 0 = V , then a is a total assignment, or
assignment in short.
→ A partial assignment assigns some variables to values from their
respective domains. A total assignment is defined on all variables.

Definition (Consistency). Let γ = (V, D, C) be a constraint network,


and let a be a partial assignment. We say that a is inconsistent if there
exist variables u, v ∈ V on which a is defined, with Cuv ∈ C and
(a(u), a(v)) 6∈ Cuv . In that case, a violates the constraint Cuv . We say
that a is consistent if it is not inconsistent.
→ Partial assignment inconsistent = “already violates a constraint”.
(Trivially consistent: The empty assignment.)
Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 22/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

Example: Coloring Australia

Is this partial assignment Is this partial assignment


consistent? Yes. consistent? No.

Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 23/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

Solutions

Definition (Solution). Let γ = (V, D, C) be a constraint network. If a


is a total consistent assignment, then a is a solution for γ. If a solution
to γ exists, then γ is solvable; otherwise, γ is inconsistent.

Example “Coloring Australia”:

Variables: V = {WA, NT , SA, Q, NSW , V , T }.


Northern
Domains: All v ∈ V : Dv = D = {red , green, blue}.
Territory
Western
Australia
Queensland
Constraints: Cuv for adjacent states u and v, with
South
Australia Cuv = {(d, d0 ) ∈ D × D | d 6= d0 }.
New South Wales

Victoria
Solution: {WA = red , NT = green, SA = blue,
Tasmania
Q = red , NSW = green, V = red , T = green}.

→ Note: This is not the only solution. E.g., we can permute the colors, and
Tasmania can be assigned an arbitrary color.

Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 24/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

Consistency vs. Extensibility


Definition. Let γ = (V, D, C) be a constraint network, and let a be a
partial assignment. We say that a can be extended to a solution if there
exists a solution a0 that agrees with a on the variables where a is defined.
→ a can be extended to a solution =⇒ a consistent. But not vice versa:
Example “Coloring Australia”:

Can this partial assignment be Can this partial assignment be


extended to a solution? Yes. extended to a solution? No.
Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 25/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

Consistency vs. Extensibility


Definition. Let γ = (V, D, C) be a constraint network, and let a be a
partial assignment. We say that a can be extended to a solution if there
exists a solution a0 that agrees with a on the variables where a is defined.
→ a can be extended to a solution =⇒ a consistent. But not vice versa:
Example “4-Queens”:

Can this partial assignment be


extended to a solution? No.
Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 25/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

Questionnaire
Question!
Which of the following statements imply that the empty
assignment, a0 , can always be extended to a solution?
(A): a0 is consistent. (B): The network is inconsistent.
(C): There are no binary (D): The network is solvable.
constraints.
→ (A): No. Being consistent does not imply being extensible to a solution (cf.
previous slide). For a0 in particular: a0 is always consistent; it can be extended to a
solution if and only if the network is solvable.
→ (B): No. If the network is inconsistent then there are no solutions, so no
assignment can be extended to a solution, in particular not a0 .
→ (C): If one of the unary constraints (variable domains) is empty, then the network is
inconsistent and we are in case (B). Otherwise, the network is solvable and a0 is
extensible to a solution, cf. answer to (A).
→ (D): Yes. The empty assignment can be extended to any solution for the network,
if such a solution does exist.
Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 26/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

Computational Complexity of CSP


Input size vs. solution space size: Assume constraint network γ with n
variables, all with domain size k.
Number of total assignments: k n .
Size of description of γ: nk for variables and domains; at most n2
constraints, each of size at most k 2 =⇒ O(n2 k 2 ).
→ The number of assignments is exponentially bigger than the size of γ.

It is therefore no surprise that:


Theorem (CSP is NP-complete). It is NP-complete to decide whether
or not a given constraint network γ is solvable.
Proof. Membership in NP: Just guess a total assignment a and verify
(in polynomial time) whether a is a solution.
NP-Hardness: The special case of graph coloring (our illustrative
example) is known to be NP-hard.
Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 27/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

Questionnaire

Can this partial assignment be Can this partial assignment be


extended to a solution? No. extended to a solution? Yes.

→ The open cells in the 2nd column → v22 = 1, v32 = 3, v35 = 1,


can only be filled by 1 and 3. Neither v25 = 2, v15 = 3, v11 = 2, v21 = 6.
of these fits into the 2nd row (v22 ). (Compare slide 6.)

Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 28/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

Before We Begin

Basic Concepts
Search: Depth-first enumeration of partial assignments.
Backtracking: Backtrack at inconsistent partial assignments.
Inference: Deducing tighter equivalent constraints to reduce search
space (backtracking will occur earlier on).

Up next: Naı̈ve backtracking, no inference.

Next Chapter: Backtracking with inference.

Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 30/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

Naı̈ve Backtracking
Call with input constraint network γ and the empty assignment a:
function Naı̈veBacktracking(a) returns a solution, or “inconsistent”
if a is inconsistent then return “inconsistent”
if a is a total assignment then return a
select some variable v for which a is not defined
for each d ∈ Dv in some order do
a0 := a ∪ {v = d}
a00 := Naı̈veBacktracking(a0 )
if a00 6= “inconsistent” then return a00
return “inconsistent”

→ Backtracking=Recursively instantiate variables one-by-one, backing up out of


a search branch if the current partial assignment is already inconsistent.

→ Why is this better than enumerating, and solution-checking, all total


assignments (cf. slide 9)? If a partial assignment is already inconsistent, then
backtracking does not enumerate any extensions thereof.
Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 31/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

Example: Coloring Australia

Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 32/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

Naı̈ve Backtracking, Pro and Contra

Pro:
Naı̈ve backtracking is extremely simple. (You can implement it on a
Commodore 128.)
Despite this simplicity, it is much more efficient than enumerating
total assignments. (You can implement it on a Commodore 128,
and solve the Bundesliga.)
Naı̈ve backtracking is complete (if there is a solution, backtracking
will find it).

Contra:
Backtracking does not recognize a that cannot be extended to a
solution, unless a is already inconsistent.
→ Employ inference to improve this! (Chapter 9).

Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 33/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

Naı̈ve backtracking, Pro and Contra: Illustration

Much more efficient than enumerating total as-


signments: “fill cells one-by-one and stop already
when an illegal row/column/block occurs” vs. “fill
all cells, then check whether it’s a solution”.
Does not recognize a that cannot be extended
to a solution, unless a is already inconsistent:
“don’t think at all, just fill in cells and see where you
get to”. In the present example, we would not even
try to see the issue, and instead just keep filling in
values, e.g. trying to put 5 or 8 into the top left cell.
→ ”Human SuDoKu playing” = lots of inference!
(You want to minimize the number of failed attempts
to keep track of on paper . . . )

Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 34/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

Questionnaire
Question!
Say G is a clique of n vertices, and we run backtracking for graph
coloring with n different colors. How big is the search space
(consistent partial assignments) of naı̈ve backtracking?
(A): n (B): n!
Pn−1
(C): 1 + i=0 n ∗ · · · ∗ (n − i) (D): nn

→ (C): 1 for the root. At the first vertex, we have n consistent colors, then n − 1
consistent colors, etc. We need to add up the nodes at each layer of the search tree.

Question!
If G is a line and we order variables left-to-right?
(A): 1 + n−1 (B): 1 + n−1 i
P P
i=0 n ∗ · · · ∗ (n − i) i=0 n ∗ (n − 1)

→ (B): At the first vertex, we have n consistent colors; at each later vertex it’s n − 1.

Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 35/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

Questionnaire, ctd.

Northern
Territory
Western Queensland
Australia

South
Australia
New South Wales

Victoria

Tasmania

Question!
Variable order WA, NT , Q, NSW , V , T , SA. Tightest upper bound
on naı̈ve backtracking search space size?
(A): 145 (B): 382
(C): 433 (D): 37
→ (B): With this variable order, we have: 3 choices for WA (3 nodes); 2 (consistent!)
choices for NT (2 ∗ 3 = 6 new nodes); 2 choices each for Q, NSW , V (12, 24, 48 new
nodes); 3 choices for T (144 new nodes). For each of the 144 leaves, we have either 0
or 1 choices for SA. To get an upper bound, we conservatively assume it’s 1
everywhere, adding another 144 consistent nodes. Plus 1 for the root.
Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 36/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

What to Order, Where, in Naı̈ve Backtracking

function Naı̈veBacktracking(γ, a) returns a solution, or “inconsistent”


if a is inconsistent with γ then return “inconsistent”
if a is a total assignment then return a
select some variable v for which a is not defined
for each d ∈ Dv in some order do
a0 := a ∪ {v = d}
a00 := Naı̈veBacktracking(γ, a0 )
if a00 6= “inconsistent” then return a00
return “inconsistent”

→ The order in which we consider variables and their values may have a
huge impact on search space size!

Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 38/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

Example: Coloring Australia

WA, NT , Q as on slide 32 =⇒ 3 ∗ 2 ∗ 2.
Any ideas for better variable orders? For SA, WA, NT it’s 3 ∗ 2 ∗ 1.
→ The “most important/most restricted variables” up front.
Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 39/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

Variable- and Value Ordering


Variable Ordering:
Naı̈ve backtracking does not specify in which order the variables are
considered.
That ordering often dramatically influences search space size. (Cf.
previous slide, and slide 36 vs. slide 44.)

Value Ordering:
Naı̈ve backtracking does not specify in which order the values of the
chosen variable are considered.
If no solution exists below current node: Doesn’t matter, we will
have to search the whole sub-tree anyway.
If solution does exist below current node: Does matter. If we always
chose a “correct” value (from a solution) then no backtracking is
needed.
Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 40/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

Variable Ordering Strategy, Part I

A commonly used strategy: most constrained variable first. Always


pick a variable v with minimal |{d ∈ Dv | a ∪ {v = d} is consistent}|.

→ By choosing a most constrained variable v first, we reduce the


branching factor (number of sub-trees generated for v) and thus reduce
the size of our search tree.

→ Extreme case: If |{d ∈ Dv | a ∪ {v = d} is consistent}| = 1, then the


value assignment to v is forced by our previous choices.

Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 41/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

Variable Ordering Strategy, Part II


Another commonly used strategy: most constraining variable first.
Always pick v with maximal |{u ∈ V | a(u) is undefined, Cuv ∈ C}|.

→ By choosing a most constraining variable first, we detect


inconsistencies earlier on and thus reduce the size of our search tree.

Commonly used strategy combination: From the set of most


constrained variables, pick a most constraining variable.

Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 42/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

Value Ordering Strategy

A commonly used strategy: least constraining value first. For variable


v, always pick d ∈ Dv with
minimal |{d0 | d0 ∈ Du , a(u) is undefined, Cuv ∈ C, (d0 , d) 6∈ Cuv }|.

Allows 1 value for SA

Allows 0 values for SA

→ By choosing a least constraining value first, we increase the chances


to not rule out the solutions below the current node.

→ Compare slide 40: We want to choose a “correct” value.

Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 43/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

Questionnaire

Northern
Territory
Western Queensland
Australia

South
Australia
New South Wales

Victoria

Tasmania

Question!
Variable order SA, NT , Q, NSW , V , WA, T . Tightest upper bound
on naı̈ve backtracking search space size?
(A): 52 (B): 145
(C): 382 (D): 433
→ (A): With this variable order, we have 3 choices for SA and 2 choices for NT ,
yielding 1 + 3 + 3 ∗ 2 = 10 search nodes and 3 ∗ 2 = 6 tree leaves. For each of
Q, NSW , V , WA, we have only 1 choice, so each adds another layer of 6 nodes. We
have 3 choices for T , adding another 3 ∗ 6 = 18 nodes. This sums up to 52.
→ This is the strategy combination from slide 42. Compare with slide 36!
Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 44/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

Summary

Constraint networks γ consist of variables, associated with finite domains,


and constraints which are binary relations specifying permissible value
pairs.
A partial assignment a maps some variables to values, a total assignment
does so for all variables. a is consistent if it complies with all constraints.
A consistent total assignment is a solution.
The constraint satisfaction problem (CSP) consists in finding a solution for
a constraint network. This has numerous applications including, e.g.,
scheduling and timetabling.
Backtracking instantiates variables one-by-one, pruning inconsistent partial
assignments.
Variable orderings in backtracking can dramatically reduce the size of the
search tree. Value orderings have this potential (only) in solvable sub-trees.
→ Next Chapter: Inference and decomposition, for improved efficiency.

Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 46/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

Reading

Chapter 6: Constraint Satisfaction Problems, Sections 6.1 and 6.3 [Russell


and Norvig (2010)].

Content: Compared to our treatment of the topic “Constraint Satisfaction


Problems” (Chapters 8 and 9), RN covers much more material, but less
formally and in much less detail (in particular, my slides contain many
additional in-depth examples). Nice background/additional reading, can’t
replace the lecture.
Section 6.1: Similar to my “Introduction” and “Constraint Networks”,
less/different examples, much less detail, more discussion of
extensions/variations.
Section 6.3: Similar to my “Naı̈ve Backtracking” and “Variable- and Value
Ordering”, with less examples and details; contains part of what I cover in
Chapter 8 (RN does inference first, then backtracking). Additional
discussion of backjumping.

Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 47/48
Introduction Networks Consistency Backtracking V/V Ordering Conclusion References

References I

Stuart Russell and Peter Norvig. Artificial Intelligence: A Modern Approach (Third
Edition). Prentice-Hall, Englewood Cliffs, NJ, 2010.

Koehler and Torralba Artificial Intelligence Chapter 09: Constraint Satisfaction Problems, Part I 48/48

You might also like