Constraint Networksprofs.sci.univr.it/~posenato/courses/temporalConstraints/slides... · Constraint...

76
Constraint Networks Lesson 3: Consistency-Enforcing and Constraint Propagation https://tinyurl.com/vhep2hc Roberto Posenato Department of Computer Science, University of Verona Acknowledgment These slides were originally written by Malte Helmert, University of Basel Stefan Wölfl, formerly University of Freiburg Bernhard Nebel, University of Freiburg November 2019 Roberto Posenato Constraint Networks 1 / 55

Transcript of Constraint Networksprofs.sci.univr.it/~posenato/courses/temporalConstraints/slides... · Constraint...

Constraint NetworksLesson 3: Consistency-Enforcing and Constraint Propagation

https://tinyurl.com/vhep2hc

Roberto Posenato

Department of Computer Science, University of Verona

AcknowledgmentThese slides were originally written by

Malte Helmert, University of BaselStefan Wölfl, formerly University of Freiburg

Bernhard Nebel, University of Freiburg

November 2019

Roberto Posenato Constraint Networks 1 / 55

Outline

1 Motivation

2 Arc Consistency

3 Path Consistency

4 Higher Levels of Local Consistency

5 Extensions of Arc Consistency

Roberto Posenato Constraint Networks 2 / 55

Outline

1 Motivation

2 Arc Consistency

3 Path Consistency

4 Higher Levels of Local Consistency

5 Extensions of Arc Consistency

Roberto Posenato Constraint Networks 3 / 55

Enforcing consistency

The more explicit and tight constraint networks are, the morerestricted is the search space of partial solutions.Idea: tighten the domains of variables or infer new constraints (bymethods called (local) consistency enforcing, constraintpropagation).Consistency-enforcing algorithms aim at assisting search: Howcan we extend a given partial solution of a small subnetwork toa partial solution of a larger subnetwork?

Roberto Posenato Constraint Networks 4 / 55

Enforcing consistency

Primary characteristic of consistency inference: size of thesubnetwork involved in the inference

Arc-consistency: algorithms that infer constraints based on pairsof variablesPath-consistency: algorithms that infer constraints based onsubnetworks of size 3i-consistency: algorithms that infer constraints based onsubnetworks of size i

any consistent instantiation of i − 1 variables is extensible to anyi-th variable

If a network is i-consistent for all i, it is globally consistent

Roberto Posenato Constraint Networks 5 / 55

Enforcing consistency

The time and space cost of enforcing i-consistency isexponential in iIn this lesson we focus on arc- and path-consistency, whichare inherently binary network concepts

Roberto Posenato Constraint Networks 6 / 55

Some useful conventions

In what follows we will always assume that the variables of aconstraint network appear in some order.Further, we assume that C does not contain unary constraints,i.e., constraints in C are always relations with arity k > 1 (but weallow that the domains Di are possibly empty).This is no restriction, since we can rewrite Di :

Di ← Di ∩ Rvi

and then remove Rvi from the network.Di will be referred to as domains, unary constraint, or domainconstraint.We assume networks to be normalized, i.e., they contain at mostone constraint for each subset of variables. We write constraintswith scope vi1 , . . . , vik in the form Ri1...ik .

Roberto Posenato Constraint Networks 7 / 55

Outline

1 Motivation

2 Arc Consistency

3 Path Consistency

4 Higher Levels of Local Consistency

5 Extensions of Arc Consistency

Roberto Posenato Constraint Networks 8 / 55

Arc consistency

Definition 1Let N = 〈V ,D ,C〉 be a constraint network.

Given Rij exists in C, variable vi is called arc-consistent relativeto variable vj if for each value ai ∈ Di , there exists an aj ∈ Dj with(ai ,aj) ∈ Rij .An “arc constraint” Rij is arc-consistent if

vi is arc-consistent relative to vj andvj is arc-consistent relative to vi .

A network N is arc-consistent if all its arc constraints arearc-consistent.

Lemma 2 (Complexity arc-consistency)Checking whether a network N = 〈V ,D ,C〉 is arc-consistentrequires at most e · k2 operations (where e is the number of itsbinary constraints and k is an upper bound of its domain sizes).

Roberto Posenato Constraint Networks 9 / 55

Arc consistencyExample

Consider a constraint network with two variables v1 and v2, domainsD1 = D2 = 1,2,3, and the binary constraint expressed by v1 < v2.

Matching diagram(microstructure) 6= NOconstraint network graphThe constraint network is notarc-consistent.

1

2

3

1

2

3

v1 v2

Roberto Posenato Constraint Networks 10 / 55

Arc consistencyRevising a single domain

A binary constraint can be made arc-consistent by shrinking thedomains of the variables in its scopeProcedure Revise(vi , vj) does the job

Algorithm 1: Revise(vi , vj )Input: a network with two variables vi , vj , domains Di and Dj , and

constraint RijOutput: a network with refined Di such that vi is arc-consistent relative

to vjforeach ai ∈ Di do

if there is no aj ∈ Dj with (ai ,aj) ∈ Rij thenremove ai from Di ;

This is equivalent to applying: Di ← Di ∩ πi(Rij on Dj)

Roberto Posenato Constraint Networks 11 / 55

Arc consistencyRevising a single domain

Lemma 3 (Complexity of Revise )The complexity of Revise is O(k2), where k is an upper bound ofthe domain sizes.

Note: With a simple modification of the Revise algorithm one couldimprove to O(t), where t is the maximal number of tuples occurring inone of the binary constraints in the network.

1

2

3

1

2

3

v1 v2

1

2

3

1

2

3

v1 v2

1

2

3

1

2

3

v1 v2

1

2

3

1

2

3

v1 v2

Roberto Posenato Constraint Networks 12 / 55

Arc consistencyEnforcing arc consistency: AC1

Algorithm 2: AC1(N)Input: a constraint network N = 〈V ,D ,C〉Output: N-equivalent, arc-consistent networkrepeat

foreach arc vi , vj with Rij ∈ C doRevise(vi , vj);Revise(vj , vi);

until no domain is changed;

Arc-consistency-1 (AC1) is a brute-force algorithm thatenforces arc-consistency over the network

Roberto Posenato Constraint Networks 13 / 55

Arc consistencyExample: AC1

Consider a constraint network with three variables v1, v2, and v3,domains D1 = D2 = D3 = 1,2,3, and the binary constraintsexpressed by v1 < v2 and v2 < v3.

1

2

3

1

2

3

1

2

3

v1 v2 v3Matching Diagram

1

2

3

1

2

3

1

2

3

v1 v2 v3arc (v1, v2):Revise(v1, v2)

1

2

3

1

2

3

1

2

3

v1 v2 v3arc (v1, v2):Revise(v1, v2)

Roberto Posenato Constraint Networks 14 / 55

Arc consistencyExample: AC1

Consider a constraint network with three variables v1, v2, and v3,domains D1 = D2 = D3 = 1,2,3, and the binary constraintsexpressed by v1 < v2 and v2 < v3.

1

2

3

1

2

3

1

2

3

v1 v2 v3Matching Diagram

1

2

3

1

2

3

1

2

3

v1 v2 v3arc (v1, v2):Revise(v2, v1)

1

2

3

1

2

3

1

2

3

v1 v2 v3arc (v1, v2):Revise(v2, v1)

Roberto Posenato Constraint Networks 14 / 55

Arc consistencyExample: AC1

Consider a constraint network with three variables v1, v2, and v3,domains D1 = D2 = D3 = 1,2,3, and the binary constraintsexpressed by v1 < v2 and v2 < v3.

1

2

3

1

2

3

1

2

3

v1 v2 v3Matching Diagram

1

2

3

1

2

3

1

2

3

v1 v2 v3arc (v1, v3): no arc

1

2

3

1

2

3

1

2

3

v1 v2 v3arc (v2, v3):Revise(v2, v3)

Roberto Posenato Constraint Networks 14 / 55

Arc consistencyExample: AC1

Consider a constraint network with three variables v1, v2, and v3,domains D1 = D2 = D3 = 1,2,3, and the binary constraintsexpressed by v1 < v2 and v2 < v3.

1

2

3

1

2

3

1

2

3

v1 v2 v3Matching Diagram

1

2

3

1

2

3

1

2

3

v1 v2 v3arc (v2, v3):Revise(v2, v3)

1

2

3

1

2

3

1

2

3

v1 v2 v3arc (v2, v3):Revise(v3, v2)

Roberto Posenato Constraint Networks 14 / 55

Arc consistencyExample: AC1

Consider a constraint network with three variables v1, v2, and v3,domains D1 = D2 = D3 = 1,2,3, and the binary constraintsexpressed by v1 < v2 and v2 < v3.

1

2

3

1

2

3

1

2

3

v1 v2 v3Matching Diagram

1

2

3

1

2

3

1

2

3

v1 v2 v3arc (v2, v3):Revise(v3, v2)

1

2

3

1

2

3

1

2

3

v1 v2 v3arc (v1, v2):Revise(v1, v2)

Roberto Posenato Constraint Networks 14 / 55

Arc consistencyExample: AC1

Consider a constraint network with three variables v1, v2, and v3,domains D1 = D2 = D3 = 1,2,3, and the binary constraintsexpressed by v1 < v2 and v2 < v3.

1

2

3

1

2

3

1

2

3

v1 v2 v3Matching Diagram

1

2

3

1

2

3

1

2

3

v1 v2 v3arc (v1, v2):Revise(v1, v2)

NoteEnforcing arc consistency may already be sufficient to show that aconstraint network is inconsistent. For example, add the constraintv3 < v1 to the network just considered.

Roberto Posenato Constraint Networks 14 / 55

Arc consistencyEnforcing arc consistency: AC1

Lemma 4 (Complexity of AC1)Let N be a constraint network with n variables, each with a domainof size ≤ k, and e binary constraints.Applying AC1 on the network runs in time O(e · n · k3).

Proof.One cycle through all binary constraints takes O(e · k2). In the worstcase, one cycle just removes one value from one domain. Moreover,there are at most n · k values. This results in an upper bound ofO(e · n · k3).

Note: If the input network is already arc-consistent, then AC1 runs intime O(e · k2).

Roberto Posenato Constraint Networks 15 / 55

Arc consistencyEnforcing arc consistency: AC3

IdeaNo need to process all constraints if only a few domains have changed.Operate on a queue of constraints to be processed.Algorithm 3: AC3(N)Input: a constraint network N = 〈V ,D ,C〉Output: N-equivalent, arc-consistent networkqueue = (vi , vj), (vj , vi) | vi , vj scope of some constraint in N;while queue is not empty do

select and remove (vi , vj) from queue;Revise(vi , vj);if Revise(vi , vj) changes Di then

queue = queue ∪ (vk, vi) | k 6= i;

Roberto Posenato Constraint Networks 16 / 55

Arc consistencyExample AC3

Consider a constraint network with 3 variables v1, v2, v3 with domainsD1 = 2,4 and D2 = D3 = 2,5, and two constraints expressed byv3|v1 and v3|v2 (“divides”).

Constraint Network

2,4v1 2,5 v2

2,5v3

Queue

Roberto Posenato Constraint Networks 17 / 55

Arc consistencyExample AC3

Consider a constraint network with 3 variables v1, v2, v3 with domainsD1 = 2,4 and D2 = D3 = 2,5, and two constraints expressed byv3|v1 and v3|v2 (“divides”).

After queue creation

2,4v1 2,5 v2

2,5v3Queue

(v1, v3)(v3, v1)(v2, v3)(v3, v2)

Roberto Posenato Constraint Networks 17 / 55

Arc consistencyExample AC3

Consider a constraint network with 3 variables v1, v2, v3 with domainsD1 = 2,4 and D2 = D3 = 2,5, and two constraints expressed byv3|v1 and v3|v2 (“divides”).

Red tuple is selectedand removed from thequeue

2,4v1 2,5 v2

2,5v3Queue

(v1, v3)(v3, v1)(v2, v3)(v3, v2)

Roberto Posenato Constraint Networks 17 / 55

Arc consistencyExample AC3

Consider a constraint network with 3 variables v1, v2, v3 with domainsD1 = 2,4 and D2 = D3 = 2,5, and two constraints expressed byv3|v1 and v3|v2 (“divides”).

Red tuple is selectedand removed from thequeue

2,4v1 2,5 v2

2,5v3 Queue

(v1, v3)(v3, v1)(v2, v3)

Roberto Posenato Constraint Networks 17 / 55

Arc consistencyExample AC3

Consider a constraint network with 3 variables v1, v2, v3 with domainsD1 = 2,4 and D2 = D3 = 2,5, and two constraints expressed byv3|v1 and v3|v2 (“divides”).

Red tuple is selectedand removed from thequeueSince 5 divides neither 2nor 4, it will removed 2,4v1 2,4v1 2,5 v2

2,5v3 Queue

(v1, v3)(v3, v1)

Roberto Posenato Constraint Networks 17 / 55

Arc consistencyExample AC3

Consider a constraint network with 3 variables v1, v2, v3 with domainsD1 = 2,4 and D2 = D3 = 2,5, and two constraints expressed byv3|v1 and v3|v2 (“divides”).

Domain D3 changed,v2, v3 has to be addedto the queue

2,4v1 2,5 v2

2v3Queue

(v1, v3)

Roberto Posenato Constraint Networks 17 / 55

Arc consistencyExample AC3

Consider a constraint network with 3 variables v1, v2, v3 with domainsD1 = 2,4 and D2 = D3 = 2,5, and two constraints expressed byv3|v1 and v3|v2 (“divides”).

Domain D3 changed,v2, v3 has to be addedto the queue

2,4v1 2,5 v2

2v3 Queue

(v1, v3)(v2, v3)

Roberto Posenato Constraint Networks 17 / 55

Arc consistencyExample AC3

Consider a constraint network with 3 variables v1, v2, v3 with domainsD1 = 2,4 and D2 = D3 = 2,5, and two constraints expressed byv3|v1 and v3|v2 (“divides”).

Red tuple is selectedand removed from thequeueSince 2 does not divides5, 5 will removedDomain D2 will change,but no constraint has tobe added to the queue

2,4v1 2,5 v2

2v3 Queue

(v1, v3)(v2, v3)

Roberto Posenato Constraint Networks 17 / 55

Arc consistencyExample AC3

Consider a constraint network with 3 variables v1, v2, v3 with domainsD1 = 2,4 and D2 = D3 = 2,5, and two constraints expressed byv3|v1 and v3|v2 (“divides”).

Red tuple is selectedand removed from thequeueNo more modifications 2,4v1 2 v2

2v3

Queue

(v1, v3)

Roberto Posenato Constraint Networks 17 / 55

Arc consistencyEnforcing arc consistency: AC3

Lemma 5 (Complexity of AC3)Let N be a constraint network with n variables, each with a domainof size ≤ k, and e binary constraints.Applying AC3 on the network runs in time O(e · k3).

Proof.Consider a single constraint. It is reintroduced into the queue whenthe domain of one of its variables has been reduced by one element.Since there are at most 2 · k values in the two domains, AC3processes each constraint at most 2 · k times. Each of e constraintsrequires O(k2) to be processed by Revise. So, the time isO(e · k3).

Note: If the input network is arc-consistent, then AC3 runs in timeO(e · k2).

Roberto Posenato Constraint Networks 18 / 55

Arc consistencyEnforcing arc consistency: AC4

To verify that a network is arc-consistent needs e · k2 operations.The following algorithm AC4 achieves optimal performance,at the cost of “best case performance”, which is Ω(e · k2).

IdeaAssociate to each value ai in the domain of variable vi theamount of support from variable vj (i.e., the number of values inDj that are consistent with ai);remove a value ai if it looses support from any other variable

Details:Q: queue of unsupported variable-value pairs;counter(vi ,ai , vj): amount of support for ai from vj ;S[vj ,aj ]: set containing variable-value pairs (vi ,ai) (with i 6= j)supported by (vj ,aj).

Roberto Posenato Constraint Networks 19 / 55

Arc consistencyEnforcing arc consistency: AC4

Algorithm 4: AC4(N)Input: a constraint network N = 〈V ,D ,C〉Output: N-equivalent, arc-consistent networkQ = ∅;S[vj , aj ] = ∅; counter(vi , ai , vj) = 0 for all Rij ∈ C, ai ∈ Di , aj ∈ Dj ;foreach Rij ∈ C, ai ∈ Di do

foreach aj ∈ Dj doif (ai , aj) ∈ Rij then

counter(vi , ai , vj)++;S[vj , aj ] = S[vj , aj ] ∪ (vi , ai);

if counter(vi , ai , vj) == 0 then Q = Q ∪ (vi , ai) and remove ai from Di ;while Q 6= ∅ do

select and remove (vj , aj) from Q;foreach (vi , ai) in S[vj , aj ] do

if ai ∈ Di then counter(vi , ai , vj)−− ;if counter(vi , ai , vj) == 0 then Q = Q ∪ (vi , ai) and remove ai from Di ;

Roberto Posenato Constraint Networks 20 / 55

Arc consistencyExample AC4

Consider the same network as for AC3.Constraints: v3|v1 and v3|v2.

2,4v1 2,5v2

2,5v3

Roberto Posenato Constraint Networks 21 / 55

Arc consistencyExample AC4

Consider the same network as for AC3.Constraints: v3|v1 and v3|v2.

2,4v1 2,5v2

2,5v3

The initialization steps yield:

S[v3,2] = (v1,2), (v1,4), (v2,2) S[v3,5] = (v2,5)S[v2,2] = (v3,2) S[v2,5] = (v3,5)S[v1,2] = (v3,2) S[v1,4] = (v3,2)

Roberto Posenato Constraint Networks 21 / 55

Arc consistencyExample AC4

The initialization steps yield:

S[v3,2] = (v1,2), (v1,4), (v2,2) S[v3,5] = (v2,5)S[v2,2] = (v3,2) S[v2,5] = (v3,5)S[v1,2] = (v3,2) S[v1,4] = (v3,2)

Furthermore:

counter(v3,2, v1) = 2 and counter(v3,5, v1) = 0.

All other counters are 1 (note: we only need consider countersbetween connected variables).

Q = (v3,5) and D3 = 2.

When (v3,5) is selected (and removed) from Q, we obtaincounter(v2,5, v3) = 0. (v2,5) is added to Q and 5 deleted from D2.Then (v2, 5) is selected from Q. (v2, 5) has only support for (v3, 5), but5 has already been removed from D3, . . .

Roberto Posenato Constraint Networks 22 / 55

Arc consistencyEnforcing arc consistency: AC2001

Fine-grained algorithms (like AC4) directly propagate theremoval of a value (vi ,ai) to values (vj ,aj) which were supportedby (vi ,ai)while coarse-grained algorithms (like AC3) propagate changeson the level of the domains onlyNevertheless coarse-grained algorithms have advantages:no need for additional data structures S[vj ,aj ] (costs forinitialization and maintenance)AC2001 is a coarse-grained method: works like AC3, but with adifferent revise function: achieves optimal run time O(e · k2).

Roberto Posenato Constraint Networks 23 / 55

Arc consistencyRevise2001 in AC2001

Assume orderings on each of the domains (use dummy value nilsmaller than all domain values)

AC2001 first initializes and maintains pointers Last(vi ,ai , vj) = nil

Algorithm 5: Revise2001(vi , vj )Input: A network with two variables vi , vj , domains Di and Dj , and

constraint RijOutput: A network with a refined domain Diforeach ai in Di with Last(vi ,ai , vj) /∈ Dj do

aj = the smallest value a∈Dj with a>Last(vi ,ai , vj) and (ai ,a)∈Rij ;if aj exists then

Last(vi ,ai , vj) = aj ;else

remove ai from Di ;

Roberto Posenato Constraint Networks 24 / 55

Outline

1 Motivation

2 Arc Consistency

3 Path Consistency

4 Higher Levels of Local Consistency

5 Extensions of Arc Consistency

Roberto Posenato Constraint Networks 25 / 55

Beyond arc consistency

Sometimes “enforcing arc consistency” is sufficient for detectinginconsistent (unsolvable) networks; but . . .enforcing arc consistency is not complete for deciding thesatisfiability of networks; because . . .inferences rely only on domain constraints and single binaryconstraints defined on the domains.

⇒ We consider further concepts of local consistency

Roberto Posenato Constraint Networks 26 / 55

Path consistency

Let N = 〈V ,D ,C〉 be a normalized constraint network.

Definition 61 Given pairwise distinct variables vi , vj , vk such that the

constraints Rij ,Rik,Rkj exist in N, the binary constraint Rij (thevariables vi , vj , resp.) is called path-consistent relative tovariable vk if for every pair (ai ,aj) ∈ Rij , there exists an ak ∈ Dksuch that (ai ,ak) ∈ Rik and (ak,aj) ∈ Rkj .

2 A set of distinct variables vi , vj , vk is path-consistent if any pairof these variables is path-consistent relative to the omitted thirdvariable.

3 A constraint network is path-consistent if all its three-elementsubsets of variables are path-consistent.

Roberto Posenato Constraint Networks 27 / 55

Path consistencyAn example

redblue

v1

redblue

v2

redbluev3

6= 6=

6=

This network is arc-consistent, but not path-consistent.

Roberto Posenato Constraint Networks 28 / 55

Path consistencyRevising a path

Algorithm 6: Revise3(vi , vj, vk)

Input: A binary network 〈V ,D ,C〉 with variables vi , vj , vkOutput: A revised constraint Rij path-consistent with vkforeach (ai ,aj) ∈ Rij do

if there is no ak ∈ Dk such that (ai ,ak) ∈ Rik and (aj ,ak) ∈ Rjk thenremove (ai ,aj) from Rij ;

This is equivalent to applying:

Rij = Rij ∩ πij(Rik on Dk on Rkj)

Roberto Posenato Constraint Networks 29 / 55

Path consistencyRevising a path: Properties

Lemma 7 (Soundness Revise3)When applied to a constraint network N, procedureRevise3(vi , vj, vk):

does not do anything if the pair vi, vj is path-consistent relativeto vk, and otherwisetransforms the network into an equivalent one where the pair vi,vj is path-consistent relative to vk.

Proof.From the definition of path consistency.

Roberto Posenato Constraint Networks 30 / 55

Path consistencyRevising a path: Complexity

Lemma 8 (Complexity of Revise3)Let t be the maximal number of tuples in one of the binaryconstraints, and let k be an upper bound for the domain sizes.The worst-case runtime of Revise3 is O(t · k).The best-case runtime of Revise3 is Ω(t).

With respect to k, the complexity of Revise3 can also be expressed asO(k3) in the worst and Ω(k2) in the best case.

Roberto Posenato Constraint Networks 31 / 55

Path consistencyEnforcing path consistency: PC1

Algorithm 7: PC1(N)

Input: A constraint network N = 〈V ,D ,C〉Output: An equivalent, path-consistent networkrepeat

foreach (ordered) triple of variables vi , vj , vk doRevise3(vi , vj, vk);

until no constraint is changed;

Lemma 9 (Soundness of PC1)When applied to a constraint network N, the PC1 algorithmcomputes a path-consistent constraint network which is equivalentto N.

Proof.Follows directly from the properties of Revise3.

Roberto Posenato Constraint Networks 32 / 55

Path consistencyEnforcing path consistency: Complexity of PC1

Lemma 10 (Complexity of PC1)Let N be a constraint network with n variables, each with a domainof size ≤ k. Let t be an upper bound of the number of tuples in oneof the binary constraints in C.The worst-case runtime of PC1 is O(n5 · t2 · k) while the best-caseis Ω(n3 · t).

Considering k, O(n5 · k5) and Ω(n3 · k2), respectively.

Proof.Each foreach costs O(n3 · t · k). Each foreach may eliminate only onepair of values. The number of foreach is n2 · t at most. Therefore, thetotal cost is O(n5 · t2 · k).

Roberto Posenato Constraint Networks 33 / 55

Path consistencyEnforcing path consistency: PC2

Algorithm 8: PC2(N)

Input: A constraint network N = 〈V ,D ,C〉Output: An equivalent, path-consistent network N′queue = (i, k, j) | 1 ≤ i < j ≤ n,1 ≤ k ≤ n, k 6= i, k 6= j;while queue is not empty do

select and remove a triple (i, k, j) from queue;Revise3(vi , vj, vk);if Rij has changed then

queue = queue ∪(l, i, j), (i, j, l) | 1 ≤ l ≤ n, l 6= i, l 6= j;

Roberto Posenato Constraint Networks 34 / 55

Path consistencyEnforcing path consistency: Soundness of PC2

Lemma 11 (Soundness of PC2)When applied to a constraint network N, the PC2 algorithmcomputes a path-consistent constraint network which is equivalentto N.

Proof.Equivalence follows directly from the properties of Revise3.To see that the remaining constraint network is path-consistent, verifythe following invariant:

Before and after each iteration of the while-loop, for eachpair vi , vj which is not path-consistent relative to vk, one ofthe triples (i, k, j) and (j, k, i) is contained in the queue.

Roberto Posenato Constraint Networks 35 / 55

Path consistencyEnforcing path consistency: Complexity of PC2

Lemma 12 (Complexity of PC2)Let N be a constraint network with n variables, each with a domainof size ≤ k. Let t be an upper bound of the number of tuples in oneof the binary constraints in N.

The worst-case runtime of PC2 on such networks is O(n3 · t2 · k).The best-case runtime of PC2 on such networks is Ω(n3 · t).

Because of t ≤ k2, the runtime bounds can also be stated asO(n3 · k5) and Ω(n3 · k2), respectively.

Roberto Posenato Constraint Networks 36 / 55

Path consistencyEnforcing path consistency: Complexity of PC2

Proof (worst case).There are initially O(n3) elements in the queue. Whenever someconstraint Rij is reduced, O(n) elements are added to the queue.There are n(n−1)

2 constraints at most. Each constraint can be reducedt times at most. Thus, the total number of elements added to thequeue is bounded by O(n3) +O(n · n(n−1)

2 · t) = O(n3 · t).Each Revise3 requires time O(t · k). Thus, the total runtime isO(n3 · t2 · k).

Proof (best case).Similar to PC1.

Roberto Posenato Constraint Networks 37 / 55

Path consistencyArc and path consistency: Overview

Worst Case Best CaseAC1 O(n · k · e · t) Ω(e · k)

AC3 O(e · k · t) Ω(e · k)

AC4 O(e · k2) Ω(e · k2)

PC1 O(n5 · t2 · k) Ω(n3 · t)PC2 O(n3 · t2 · k) Ω(n3 · t)PC4∗ O(n3 · t · k) Ω(n3 · t · k)∗not discussed in this lecture

Remark: O(n3 · t · k) is the optimal (worst-case) runtime for enforcingpath consistency, i.e., there are constraint networks for which nobetter algorithm exists (problem complexity!).

Roberto Posenato Constraint Networks 38 / 55

Outline

1 Motivation

2 Arc Consistency

3 Path Consistency

4 Higher Levels of Local Consistency

5 Extensions of Arc Consistency

Roberto Posenato Constraint Networks 39 / 55

Higher levels of local consistency

The local consistency notions presented so far can be roughlysummarized as follows:

Arc consistency:Every consistent assignment to a single variable can beconsistently extended to any second variable.Path consistency:Every consistent assignment to two variables can be consistentlyextended to any third variable.

Side remarkThis is a bit of an oversimplification because we just considerednormalized, binary networks and ignored k-ary constraints with k ≥ 3so far.

Roberto Posenato Constraint Networks 40 / 55

i-Consistency

Let N = 〈V ,D ,C〉 be a constraint network.

Definition 13N is called i-consistent if any consistent instantiation of i − 1 (distinct)variables x1, . . . , xi−1 of the network can be extended to a consistentinstantiation of the variables x1, . . . , xi , where xi is any variable in Vdistinct from x1, . . . , xi−1.

Roberto Posenato Constraint Networks 41 / 55

i-ConsistencyGlobal consistency

Definition 14A network N is strongly i-consistent if it is j-consistent for eachj ≤ i.A network N with n variables is globally consistent if it is stronglyn-consistent.

Note: Solutions to globally consistent networks can be found withoutsearch.

Roberto Posenato Constraint Networks 42 / 55

i-ConsistencyArc/path consistency vs. 2/3-consistency

Note that for binary (normalized) networks:2-consistency coincides with arc consistency.3-consistency coincides with path consistency.

But, e.g., for networks with constraints of arity ≥ 3, 3-consistency is(in general) stricter than path consistency.

Roberto Posenato Constraint Networks 43 / 55

i-Consistency3-Consistency: Examples

Example 1Consider a network where

V = v1, v2, v3D1 = D2 = D3 = 0,1

R123 = (0,0,0)The network is already path-consistent, but it is not 3-consistent.The assignment (〈v1,1〉, 〈v2,1〉) cannot be extended to v3.

Example 2Consider a network where

V = v1, v2, v3D1 = D2 = D3 = 0,1

R123 = (0,0,0), (0,1,1), (1,0,1), (1,1,0)R12 = R13 = R23 = (0,1), (1,0), (1,1)

Is it path-consistent? 3-consistent?Roberto Posenato Constraint Networks 44 / 55

i-ConsistencyRevise-i

Algorithm 9: Revise-i(x1, . . . , xi−1, xi)Input: A normalized network 〈V ,D ,C〉 and a constraint RS with scope

S = x1, . . . , xi−1Output: A constraint RS which is i-consistent relative to xiforeach a ∈ RS do

if there is no ai ∈ Di such that (a,ai) is consistent thenremove a from RS;

Each (a,ai) has to be checked w.r.t. all possible constraints of thenetwork.

There are ki different a at most.

If the input network is binary, there may be O(i2) different constraints.Revise-i runs in time O(i2ki) = O(ki).

More generally, considering i variables, there may be O(2i) differentconstraints. Therefore, Revise-i runs in time O((2 · k)i).

Roberto Posenato Constraint Networks 45 / 55

i-ConsistencyAlgorithm

Algorithm 10: i-Consistency(N)

Input: A normalized constraint network N = 〈V ,D ,C〉Output: A revised network equivalent to Nrepeat

foreach S = x1, . . . , xi−1 ⊆ V of size i − 1 and each xi /∈ S doRevise-i(x1, . . . , xi−1, xi);

until no constraint is changed;

The Revise-i call can equivalently be stated as follows:Let S be the set of all subsets of x1, . . . , xi where each contains xiand occur as scope of some constraint in the network. Then,

RS ← RS ∩ πS(onS′∈S RS′).

Roberto Posenato Constraint Networks 46 / 55

i-ConsistencyAlgorithm Complexity

Lemma 15Let N be a constraint network with n variables, each with a domainof size ≤ k. When applied to N, the i-Consistency algorithm runs intime O(2i · (n · k)2i−1).

Proof.Each call to Revise-i requires time O((2 · k)i). In each iteration of the outerloop, O(ni) combinations of S and vi need to be processed. If only onetuple is removed from one constraint in each iteration up to the final one,the outer loop may need to iterate O(ni−1 · ki−1) times on each constraint.This leads to an overall runtime of O(2i · (n · k)2i−1).

Note: Improvements similar to AC4 and PC4 exist and achieve aworst-case runtime of O(ni · ki).

Roberto Posenato Constraint Networks 47 / 55

i-ConsistencyAlgorithm Complexity

Lemma 15Let N be a constraint network with n variables, each with a domainof size ≤ k. When applied to N, the i-Consistency algorithm runs intime O(2i · (n · k)2i−1).

Proof.Each call to Revise-i requires time O((2 · k)i). In each iteration of the outerloop, O(ni) combinations of S and vi need to be processed. If only onetuple is removed from one constraint in each iteration up to the final one,the outer loop may need to iterate O(ni−1 · ki−1) times on each constraint.This leads to an overall runtime of O(2i · (n · k)2i−1).

Note: Improvements similar to AC4 and PC4 exist and achieve aworst-case runtime of O(ni · ki).

Roberto Posenato Constraint Networks 47 / 55

i-ConsistencyComparison to ACx and PCx

Worst Casei-consistency, i = 2 O(n3 · k3)

AC1 O(n · k · e · t) = O(n3 · k3)

AC3 O(e · k · t) = O(n2 · k3)

AC4 O(n2 · k2)

improved i-consistency∗, i = 2 O(n2 · k2)

i-consistency, i = 3 O(n5 · k5)

PC1 O(n5 · t2 · k) = O(n5 · k5)

PC2 O(n3 · t2 · k) = O(n3 · k5)

PC4∗ O(n3 · k3)

improved i-consistency∗, i = 3 O(n3 · k3)∗not discussed in this lecture

Remark: O(ni · ki) is the optimal (worst-case) runtime for enforcingi-consistency, i.e., there are constraint networks (at any size) forwhich no better algorithm exists.

Roberto Posenato Constraint Networks 48 / 55

Outline

1 Motivation

2 Arc Consistency

3 Path Consistency

4 Higher Levels of Local Consistency

5 Extensions of Arc Consistency

Roberto Posenato Constraint Networks 49 / 55

Extensions of arc consistency

General i-consistency is powerful, but expensive to enforce.Usually, arc consistency and path consistency offer a goodcompromise between pruning power and computationaloverhead.However, they are of limited usefulness for constraints on morethan two variables.

Example 3Consider a constraint network with three integer variablesv1, v2, v3 ≥ 0 and the constraints v3 ≥ 13 and v1 + v2 + v3 ≤ 15.We should be able to infer v1 ≤ 2 and v2 ≤ 2, but (binary) arcconsistency is not enough!

Consider generalizations of arc consistency to non-binaryconstraints.

Roberto Posenato Constraint Networks 50 / 55

Generalized arc consistency

Definition 16Let N = 〈V ,D ,C〉 be a (non-normalized, non-binary) constraintnetwork.

1 A variable xi is generalized arc-consistent (GAC) relative to aconstraint (s,R) ∈ C with xi in s = (x1, . . . , xk) if for every valueai ∈ Di there exists a tuple a ∈ R ∩ πs(D1 × · · · × Dn) witha[i] = ai , i.e.,

Di ⊆ πi(R ∩ πs(D1 × · · · × Dn)).

2 A constraint (x,R) ∈ C is (generalized) arc-consistent if allvariables in its scope x are generalized arc-consistent relative toR.

3 A network N is (generalized) arc-consistent if all its constraintsare generalized arc-consistent.

Roberto Posenato Constraint Networks 51 / 55

Generalized arc consistency: Update ruleTo enforce generalized arc consistency, repeatedly apply

Di ← Di ∩ πi(Rs on Ds−vi)Note how this generalizes the usual arc consistency update rule:

Di ← Di ∩ πi(Rij on Dj)

ExampleConstraint network with variables v1, v2, v3, domains D1 = 2,4 andD2 = D3 = 2,5, constraints v3|v1 and v3|v2 (“divides”), andv1 + v2 + v3 ≥ 8.

Constraint Network

2,4v1 2,5 v2

2,5v3

Roberto Posenato Constraint Networks 52 / 55

Generalized arc consistency: Update ruleTo enforce generalized arc consistency, repeatedly apply

Di ← Di ∩ πi(Rs on Ds−vi)Note how this generalizes the usual arc consistency update rule:

Di ← Di ∩ πi(Rij on Dj)

ExampleConstraint network with variables v1, v2, v3, domains D1 = 2,4 andD2 = D3 = 2,5, constraints v3|v1 and v3|v2 (“divides”), andv1 + v2 + v3 ≥ 8.

Values 2 and 4 of v1 are okbecause v3 divides themand exists (5,5) in R2,3.

2,4v1 2,5 v2

2,5v3

Roberto Posenato Constraint Networks 52 / 55

Generalized arc consistency: Update ruleTo enforce generalized arc consistency, repeatedly apply

Di ← Di ∩ πi(Rs on Ds−vi)Note how this generalizes the usual arc consistency update rule:

Di ← Di ∩ πi(Rij on Dj)

ExampleConstraint network with variables v1, v2, v3, domains D1 = 2,4 andD2 = D3 = 2,5, constraints v3|v1 and v3|v2 (“divides”), andv1 + v2 + v3 ≥ 8.

Values 2 and 5 of v2 are okbecause v3 divides themand exists (4,2) in R1,3.

2,4v1 2,5 v2

2,5v3

Roberto Posenato Constraint Networks 52 / 55

Generalized arc consistency: Update ruleTo enforce generalized arc consistency, repeatedly apply

Di ← Di ∩ πi(Rs on Ds−vi)Note how this generalizes the usual arc consistency update rule:

Di ← Di ∩ πi(Rij on Dj)

ExampleConstraint network with variables v1, v2, v3, domains D1 = 2,4 andD2 = D3 = 2,5, constraints v3|v1 and v3|v2 (“divides”), andv1 + v2 + v3 ≥ 8.

Value 5 of v3 must bedeleted because it doesnot divide any value in v1.

2,4v1 2,5 v2

2,5v3

Roberto Posenato Constraint Networks 52 / 55

Generalized arc consistency: Update ruleTo enforce generalized arc consistency, repeatedly apply

Di ← Di ∩ πi(Rs on Ds−vi)Note how this generalizes the usual arc consistency update rule:

Di ← Di ∩ πi(Rij on Dj)

ExampleConstraint network with variables v1, v2, v3, domains D1 = 2,4 andD2 = D3 = 2,5, constraints v3|v1 and v3|v2 (“divides”), andv1 + v2 + v3 ≥ 8.

Values 2 in v1 must bedeleted because (5,5) inR2,3 is not available!

2,4v1 2,5 v2

2v3

Roberto Posenato Constraint Networks 52 / 55

Generalized arc consistency: Update ruleTo enforce generalized arc consistency, repeatedly apply

Di ← Di ∩ πi(Rs on Ds−vi)Note how this generalizes the usual arc consistency update rule:

Di ← Di ∩ πi(Rij on Dj)

ExampleConstraint network with variables v1, v2, v3, domains D1 = 2,4 andD2 = D3 = 2,5, constraints v3|v1 and v3|v2 (“divides”), andv1 + v2 + v3 ≥ 8.

Value 5 of v2 must bedeleted because it notdivisible by v3 value.

4v1 2,5 v2

2v3

Roberto Posenato Constraint Networks 52 / 55

Generalized arc consistency: Update ruleTo enforce generalized arc consistency, repeatedly apply

Di ← Di ∩ πi(Rs on Ds−vi)Note how this generalizes the usual arc consistency update rule:

Di ← Di ∩ πi(Rij on Dj)

ExampleConstraint network with variables v1, v2, v3, domains D1 = 2,4 andD2 = D3 = 2,5, constraints v3|v1 and v3|v2 (“divides”), andv1 + v2 + v3 ≥ 8.

Done!

4v1 2 v2

2v3

Roberto Posenato Constraint Networks 52 / 55

Alternatives to generalized arc consistency

Like arc consistency, generalized arc consistency propagatesconstraints by considering a single constraint at a time.In particular, it considers how assignments to each individualvariable are restricted by the values allowed for the othervariables participating in the constraint.Alternatively, we can consider how each individual variablerestricts the values allowed for the other variables participating inthe constraint:

Rs−vi ← Rs−vi ∩ πs−vi(Rs on Di)

(relational arc consistency)Note that in the case of binary constraints, these two cases arethe same, so both approaches are natural generalizations of(binary) arc consistency.

Roberto Posenato Constraint Networks 53 / 55

Generalizations of arc consistency: Comparison

AC: Di ← Di ∩ πi(Rij on Dj)generalized AC: Di ← Di ∩ πi(Rs on Ds−vi)

relational AC: Rs−vi ← Rs−vi ∩ πs−vi(Rs on Di)

Example 4Consider a constraint network with three integer variablesv1, v2, v3 ≥ 0 and the constraints v3 ≥ 13 and v1 + v2 + v3 ≤ 15.

Generalized AC infers v1 ≤ 2, v2 ≤ 2.Relational AC infers v1 + v2 ≤ 2.

Roberto Posenato Constraint Networks 54 / 55

Literature

Christian Bessiere.Constraint propagation,Chapter 3 of Handbook of Constraint Programming, 2006

Rina Dechter.Constraint Processing,Chapter 3, Morgan Kaufmann, 2003

Alan K. Mackworth.Constraint satisfaction.In S. C. Shapiro, editor, Encyclopedia of Artificial Intelligence, pages205–211. Wiley, Chichester, England, 1987.

Alan K. Mackworth.Consistency in networks of relations.Artificial Intelligence, 8:99–118, 1977.

Ugo Montanari.Networks of constraints: fundamental properties and applications topicture processing.Information Science, 7:95–132, 1974.

Roberto Posenato Constraint Networks 55 / 55