35
Arc-consistency for alldiff(x,y,...,z) Example: P=(X,D,C) Variables: {w,x,y,z}X Domains: w{b,c,d,e} x{b,c} y{a,b,c,d} z{b,c} Constraints: alldiff(w,x,y,z)C value d for w is supported: alldiff(wd, xb, y a, zc) = true value b for w is not supported!

Arc-consistency for alldiff(x,y,...,z) Example: P=(X,D,C) Variables: {w,x,y,z} X Domains: w {b,c,d,e} x {b,c} y {a,b,c,d} z {b,c} Constraints:

  • View
    233

  • Download
    2

Embed Size (px)

Citation preview

Page 1: Arc-consistency for alldiff(x,y,...,z) Example: P=(X,D,C) Variables: {w,x,y,z}  X Domains: w  {b,c,d,e} x  {b,c} y  {a,b,c,d} z  {b,c} Constraints:

Arc-consistency for alldiff(x,y,...,z)

Example: P=(X,D,C)Variables: {w,x,y,z}XDomains:

w{b,c,d,e} x{b,c}y{a,b,c,d} z{b,c}

Constraints: alldiff(w,x,y,z)C

value d for w is supported: alldiff(wd, xb, y a, zc) = true

value b for w is not supported!

Page 2: Arc-consistency for alldiff(x,y,...,z) Example: P=(X,D,C) Variables: {w,x,y,z}  X Domains: w  {b,c,d,e} x  {b,c} y  {a,b,c,d} z  {b,c} Constraints:

alldiff: value graph

Variables {w,x,y,z}XDomains D(w)={b,c,d,e}, D(x)={b,c},

D(y)={a,b,c,d}, D(z)={b,c}Constraint alldiff(w,x,y,z)C

w

x

y

z

b

c

d

e

a

Page 3: Arc-consistency for alldiff(x,y,...,z) Example: P=(X,D,C) Variables: {w,x,y,z}  X Domains: w  {b,c,d,e} x  {b,c} y  {a,b,c,d} z  {b,c} Constraints:

alldiff: value graph

Variables {w,x,y,z}XDomains D(w)={b,c,d,e}, D(x)={b,c},

D(y)={a,b,c,d}, D(z)={b,c}Constraint alldiff(w,x,y,z)C

w

x

y

z

b

c

d

e

a

Given a graph G=(V,E), a matching is ME such that no two edges of M share a vertex

Page 4: Arc-consistency for alldiff(x,y,...,z) Example: P=(X,D,C) Variables: {w,x,y,z}  X Domains: w  {b,c,d,e} x  {b,c} y  {a,b,c,d} z  {b,c} Constraints:

alldiff: value graph

Variables {w,x,y,z}XDomains D(w)={b,c,d,e}, D(x)={b,c},

D(y)={a,b,c,d}, D(z)={b,c}Constraint alldiff(w,x,y,z)C

w

x

y

z

b

c

d

e

a

Consistent assignment =maximal cardinality matchingcovering all the variables

We want to remove edgesthat do not belong to any max-card matching

Page 5: Arc-consistency for alldiff(x,y,...,z) Example: P=(X,D,C) Variables: {w,x,y,z}  X Domains: w  {b,c,d,e} x  {b,c} y  {a,b,c,d} z  {b,c} Constraints:

AC characterization

Theorem: Let G be a graph and M a maximum-cardinality matching. An edge e belongs to some max-card matching iff e is in M, or e is on an even-length M-alternating circuit e is on an even-length M-alternating path

starting at a M-free vertex

Page 6: Arc-consistency for alldiff(x,y,...,z) Example: P=(X,D,C) Variables: {w,x,y,z}  X Domains: w  {b,c,d,e} x  {b,c} y  {a,b,c,d} z  {b,c} Constraints:

AC Algorithm

1. Compute a maximum-cardinality matching.

2. Compute all even-length M-alternating circuits

3. Compute all even-length M-alternating paths starting at a M-free vertex

4. Remove all edges not identified in the previous 3 steps

Page 7: Arc-consistency for alldiff(x,y,...,z) Example: P=(X,D,C) Variables: {w,x,y,z}  X Domains: w  {b,c,d,e} x  {b,c} y  {a,b,c,d} z  {b,c} Constraints:

Step 1. Find Max-card matching

A matching M covers a vertex v if v belongs to some edge in M

A matching M covers a set SV if it covers all the vertices of S

A vertex v is M-free is M does not cover v

f

a b

c

e d

Page 8: Arc-consistency for alldiff(x,y,...,z) Example: P=(X,D,C) Variables: {w,x,y,z}  X Domains: w  {b,c,d,e} x  {b,c} y  {a,b,c,d} z  {b,c} Constraints:

Paths A path is M-alternating if its edges are are

alternatingly out of and in M A M-alternating path is M-augmenting if

has odd length, Its ends are not covered by M

f

a b

c

e d

Page 9: Arc-consistency for alldiff(x,y,...,z) Example: P=(X,D,C) Variables: {w,x,y,z}  X Domains: w  {b,c,d,e} x  {b,c} y  {a,b,c,d} z  {b,c} Constraints:

Step 1

Finding M-augmenting paths

w

x

y

z

b

c

d

e

a

Page 10: Arc-consistency for alldiff(x,y,...,z) Example: P=(X,D,C) Variables: {w,x,y,z}  X Domains: w  {b,c,d,e} x  {b,c} y  {a,b,c,d} z  {b,c} Constraints:

Step 1

Finding M-augmenting paths

w

x

y

z

b

c

d

e

a Direct the graph

Page 11: Arc-consistency for alldiff(x,y,...,z) Example: P=(X,D,C) Variables: {w,x,y,z}  X Domains: w  {b,c,d,e} x  {b,c} y  {a,b,c,d} z  {b,c} Constraints:

Step 1

Finding M-augmenting paths is easy for bipartite graphs

w

x

y

z

b

c

d

e

a Find a path from anM-free vertex on theleft to an M-free vertex on the right

Page 12: Arc-consistency for alldiff(x,y,...,z) Example: P=(X,D,C) Variables: {w,x,y,z}  X Domains: w  {b,c,d,e} x  {b,c} y  {a,b,c,d} z  {b,c} Constraints:

Step 1

Finding M-augmenting paths is easy for bipartite graphs

w

x

y

z

b

c

d

e

a Find a path from anM-free vertex on theleft to an M-free vertex on the right

Page 13: Arc-consistency for alldiff(x,y,...,z) Example: P=(X,D,C) Variables: {w,x,y,z}  X Domains: w  {b,c,d,e} x  {b,c} y  {a,b,c,d} z  {b,c} Constraints:

Step 1

Finding M-augmenting paths is easy for bipartite graphs

w

x

y

z

b

c

d

e

a Find a path from anM-free vertex on theleft to an M-free vertex on the right

Page 14: Arc-consistency for alldiff(x,y,...,z) Example: P=(X,D,C) Variables: {w,x,y,z}  X Domains: w  {b,c,d,e} x  {b,c} y  {a,b,c,d} z  {b,c} Constraints:

Step 1

w

x

y

z

b

c

d

e

a Find a path from anM-free vertex on theleft to an M-free vertex on the right

n breadth-first traversalsO(n e)

Can be improved toO(n0.5 e)

Page 15: Arc-consistency for alldiff(x,y,...,z) Example: P=(X,D,C) Variables: {w,x,y,z}  X Domains: w  {b,c,d,e} x  {b,c} y  {a,b,c,d} z  {b,c} Constraints:

Step 2:

Compute all even-length M-alternating circuit

w

x

y

z

b

c

d

e

a

Page 16: Arc-consistency for alldiff(x,y,...,z) Example: P=(X,D,C) Variables: {w,x,y,z}  X Domains: w  {b,c,d,e} x  {b,c} y  {a,b,c,d} z  {b,c} Constraints:

Step 2:

Compute all even-length M-alternating circuit

w

x

y

z

b

c

d

e

a Direct the graph

Page 17: Arc-consistency for alldiff(x,y,...,z) Example: P=(X,D,C) Variables: {w,x,y,z}  X Domains: w  {b,c,d,e} x  {b,c} y  {a,b,c,d} z  {b,c} Constraints:

Step 2:

Compute all even-length M-alternating circuit

w

x

y

z

b

c

d

e

a Compute all stronglyConnected components[Tarjan 72] O(e)

Page 18: Arc-consistency for alldiff(x,y,...,z) Example: P=(X,D,C) Variables: {w,x,y,z}  X Domains: w  {b,c,d,e} x  {b,c} y  {a,b,c,d} z  {b,c} Constraints:

Tarjan (Kosaraju’s)

1. Do a DFS

2. Reverse the direction of edges

3. Do a DFS starting with the vertex visited last in the original DFS

4. Each tree in the forest returned is a SCC

O(|V|+|A|)

Page 19: Arc-consistency for alldiff(x,y,...,z) Example: P=(X,D,C) Variables: {w,x,y,z}  X Domains: w  {b,c,d,e} x  {b,c} y  {a,b,c,d} z  {b,c} Constraints:

Step 3:

Compute all even-length M-alternating paths starting at a M-free vertex

w

x

y

z

b

c

d

e

a

Page 20: Arc-consistency for alldiff(x,y,...,z) Example: P=(X,D,C) Variables: {w,x,y,z}  X Domains: w  {b,c,d,e} x  {b,c} y  {a,b,c,d} z  {b,c} Constraints:

Step 3:

Compute all even-length M-alternating paths starting at a M-free vertex

w

x

y

z

b

c

d

e

a Direct the graph

Page 21: Arc-consistency for alldiff(x,y,...,z) Example: P=(X,D,C) Variables: {w,x,y,z}  X Domains: w  {b,c,d,e} x  {b,c} y  {a,b,c,d} z  {b,c} Constraints:

Step 3:

Compute all even-length M-alternating paths starting at a M-free vertex

w

x

y

z

b

c

d

e

a Compute alternating Paths starting from free Vertices

Breadth-first O(e)

Page 22: Arc-consistency for alldiff(x,y,...,z) Example: P=(X,D,C) Variables: {w,x,y,z}  X Domains: w  {b,c,d,e} x  {b,c} y  {a,b,c,d} z  {b,c} Constraints:

Step 4

w

x

y

z

b

c

d

e

a

Remove Edges not identified in previous steps

Page 23: Arc-consistency for alldiff(x,y,...,z) Example: P=(X,D,C) Variables: {w,x,y,z}  X Domains: w  {b,c,d,e} x  {b,c} y  {a,b,c,d} z  {b,c} Constraints:

Step 4

w

x

y

z

b

c

d

e

a

Remove Edges not identified in previous steps

Page 24: Arc-consistency for alldiff(x,y,...,z) Example: P=(X,D,C) Variables: {w,x,y,z}  X Domains: w  {b,c,d,e} x  {b,c} y  {a,b,c,d} z  {b,c} Constraints:

Step 4

w

x

y

z

b

c

d

e

a

Remove Edges not identified in previous steps

Page 25: Arc-consistency for alldiff(x,y,...,z) Example: P=(X,D,C) Variables: {w,x,y,z}  X Domains: w  {b,c,d,e} x  {b,c} y  {a,b,c,d} z  {b,c} Constraints:

Step 4

w

x

y

z

b

c

d

e

a

Remove Edges not identified in previous steps

Page 26: Arc-consistency for alldiff(x,y,...,z) Example: P=(X,D,C) Variables: {w,x,y,z}  X Domains: w  {b,c,d,e} x  {b,c} y  {a,b,c,d} z  {b,c} Constraints:

Step 4

w

x

y

z

b

c

d

e

a

Remove Edges not identified in previous steps

Page 27: Arc-consistency for alldiff(x,y,...,z) Example: P=(X,D,C) Variables: {w,x,y,z}  X Domains: w  {b,c,d,e} x  {b,c} y  {a,b,c,d} z  {b,c} Constraints:

knapsack constraint

Notation: L ≤ ax+by+...+cz ≤ UL, U, a, b, ..., c positive integer constantsx, y,..., z integer variables (posit.

domains) Example:

Variables: x,y,v,zDomains: {0, 1}10 ≤ 2x + 3y + 4v + 5z ≤ 12

Applications: everywhere

Page 28: Arc-consistency for alldiff(x,y,...,z) Example: P=(X,D,C) Variables: {w,x,y,z}  X Domains: w  {b,c,d,e} x  {b,c} y  {a,b,c,d} z  {b,c} Constraints:

knapsack constraint

Example: Variables: x,y,v,zDomains: {0, 1}10 ≤ 2x + 3y + 4v + 5z ≤ 12

Value 0 of x is supported (0+3+4+5=12) Value 1 of x is supported (2+0+4+5=11) Value 0 of z is not supported!!

Page 29: Arc-consistency for alldiff(x,y,...,z) Example: P=(X,D,C) Variables: {w,x,y,z}  X Domains: w  {b,c,d,e} x  {b,c} y  {a,b,c,d} z  {b,c} Constraints:

knapsack: propagation Knapsack graph10 ≤ 2x + 3y + 4v + 5z ≤ 12

x y v z

12

11

10

9

8

7

6

5

4

3

2

1

0

Page 30: Arc-consistency for alldiff(x,y,...,z) Example: P=(X,D,C) Variables: {w,x,y,z}  X Domains: w  {b,c,d,e} x  {b,c} y  {a,b,c,d} z  {b,c} Constraints:

knapsack: propagation Knapsack graph10 ≤ 2x + 3y + 4v + 5z ≤ 12

x y v z

12

11

10

9

8

7

6

5

4

3

2

1

0

Page 31: Arc-consistency for alldiff(x,y,...,z) Example: P=(X,D,C) Variables: {w,x,y,z}  X Domains: w  {b,c,d,e} x  {b,c} y  {a,b,c,d} z  {b,c} Constraints:

knapsack: propagation Knapsack graph10 ≤ 2x + 3y + 4v + 5z ≤ 12

x y v z

12

11

10

9

8

7

6

5

4

3

2

1

0

Page 32: Arc-consistency for alldiff(x,y,...,z) Example: P=(X,D,C) Variables: {w,x,y,z}  X Domains: w  {b,c,d,e} x  {b,c} y  {a,b,c,d} z  {b,c} Constraints:

knapsack: propagation Knapsack graph10 ≤ 2x + 3y + 4v + 5z ≤ 12

x y v z

12

11

10

9

8

7

6

5

4

3

2

1

0

Page 33: Arc-consistency for alldiff(x,y,...,z) Example: P=(X,D,C) Variables: {w,x,y,z}  X Domains: w  {b,c,d,e} x  {b,c} y  {a,b,c,d} z  {b,c} Constraints:

knapsack: propagation Knapsack graph10 ≤ 2x + 3y + 4v + 5z ≤ 12 Reduced graph

Value 0 of z can be removed

x y v z

12

11

10

9

8

7

6

5

4

3

2

1

0

Page 34: Arc-consistency for alldiff(x,y,...,z) Example: P=(X,D,C) Variables: {w,x,y,z}  X Domains: w  {b,c,d,e} x  {b,c} y  {a,b,c,d} z  {b,c} Constraints:

knapsack: propagation Knapsack graph10 ≤ 2x + 3y + 4v + 5z ≤ 12 Reduced graph

Value 0 of z can be removed

x y v z

12

11

10

9

8

7

6

5

4

3

2

1

0

Page 35: Arc-consistency for alldiff(x,y,...,z) Example: P=(X,D,C) Variables: {w,x,y,z}  X Domains: w  {b,c,d,e} x  {b,c} y  {a,b,c,d} z  {b,c} Constraints:

knapsack: propagation Knapsack graph10 ≤ 2x + 3y + 4v + 5z ≤ 12 Reduced graph

Value 0 of z can be removed Complexity: O(nU2)

n is the number of variables Pseudo-polynomial

x y v z

12

11

10

9

8

7

6

5

4

3

2

1

0