350 likes | 436 Views
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
E N D
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!
alldiff: value graph Variables {w,x,y,z}X Domains 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 a w b x c y d z e
alldiff: value graph Variables {w,x,y,z}X Domains 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 a w b Given a graph G=(V,E), a matching is ME such that no two edges of M share a vertex x c y d z e
alldiff: value graph Variables {w,x,y,z}X Domains 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 a w b Consistent assignment = maximal cardinality matching covering all the variables We want to remove edges that do not belong to any max-card matching x c y d z e
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
AC Algorithm • Compute a maximum-cardinality matching. • Compute all even-length M-alternating circuits • Compute all even-length M-alternating paths starting at a M-free vertex • Remove all edges not identified in the previous 3 steps
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 a b f c e d
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 a b f c e d
Step 1 • Finding M-augmenting paths a w b x c y d z e
Step 1 • Finding M-augmenting paths a Direct the graph w b x c y d z e
Step 1 • Finding M-augmenting paths is easy for bipartite graphs a Find a path from an M-free vertex on the left to an M-free vertex on the right w b x c y d z e
Step 1 • Finding M-augmenting paths is easy for bipartite graphs a Find a path from an M-free vertex on the left to an M-free vertex on the right w b x c y d z e
Step 1 • Finding M-augmenting paths is easy for bipartite graphs a Find a path from an M-free vertex on the left to an M-free vertex on the right w b x c y d z e
Step 1 a Find a path from an M-free vertex on the left to an M-free vertex on the right n breadth-first traversals O(n e) Can be improved to O(n0.5 e) w b x c y d z e
Step 2: • Compute all even-length M-alternating circuit a w b x c y d z e
Step 2: • Compute all even-length M-alternating circuit a Direct the graph w b x c y d z e
Step 2: • Compute all even-length M-alternating circuit a Compute all strongly Connected components [Tarjan 72] O(e) w b x c y d z e
Tarjan (Kosaraju’s) • Do a DFS • Reverse the direction of edges • Do a DFS starting with the vertex visited last in the original DFS • Each tree in the forest returned is a SCC • O(|V|+|A|)
Step 3: • Compute all even-length M-alternating paths starting at a M-free vertex a w b x c y d z e
Step 3: • Compute all even-length M-alternating paths starting at a M-free vertex a Direct the graph w b x c y d z e
Step 3: • Compute all even-length M-alternating paths starting at a M-free vertex a Compute alternating Paths starting from free Vertices Breadth-first O(e) w b x c y d z e
Step 4 • Remove Edges not identified in previous steps a w b x c y d z e
Step 4 • Remove Edges not identified in previous steps a w b x c y d z e
Step 4 • Remove Edges not identified in previous steps a w b x c y d z e
Step 4 • Remove Edges not identified in previous steps a w b x c y d z e
Step 4 • Remove Edges not identified in previous steps a w b x c y d z e
knapsack constraint • Notation: L≤ax+by+...+cz≤U L, U, a, b, ..., c positive integer constants x, y,..., z integer variables (posit. domains) • Example: • Variables: x,y,v,z • Domains: {0, 1} • 10 ≤ 2x + 3y + 4v + 5z ≤ 12 • Applications: everywhere
knapsack constraint • Example: • Variables: x,y,v,z • Domains: {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!!
knapsack: propagation 12 11 10 9 8 7 6 5 4 3 2 1 0 • Knapsack graph 10 ≤ 2x + 3y + 4v + 5z ≤ 12 x y v z
knapsack: propagation 12 11 10 9 8 7 6 5 4 3 2 1 0 • Knapsack graph 10 ≤ 2x + 3y + 4v + 5z ≤ 12 x y v z
knapsack: propagation 12 11 10 9 8 7 6 5 4 3 2 1 0 • Knapsack graph 10 ≤ 2x + 3y + 4v + 5z ≤ 12 x y v z
knapsack: propagation 12 11 10 9 8 7 6 5 4 3 2 1 0 • Knapsack graph 10 ≤ 2x + 3y + 4v + 5z ≤ 12 x y v z
knapsack: propagation 12 11 10 9 8 7 6 5 4 3 2 1 0 • Knapsack graph 10 ≤ 2x + 3y + 4v + 5z ≤ 12 • Reduced graph • Value 0 of z can be removed x y v z
knapsack: propagation 12 11 10 9 8 7 6 5 4 3 2 1 0 • Knapsack graph 10 ≤ 2x + 3y + 4v + 5z ≤ 12 • Reduced graph • Value 0 of z can be removed x y v z
knapsack: propagation 12 11 10 9 8 7 6 5 4 3 2 1 0 • Knapsack graph 10 ≤ 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