Global Constraints. Combinatorial Problem Solving (CPS) Enric Rodríguez-Carbonell (based on materials by Javier Larrosa) February 22, 2019

Similar documents
Matching Theory. Figure 1: Is this graph bipartite?

Number Theory and Graph Theory

PERFECT MATCHING THE CENTRALIZED DEPLOYMENT MOBILE SENSORS THE PROBLEM SECOND PART: WIRELESS NETWORKS 2.B. SENSOR NETWORKS OF MOBILE SENSORS

Section 3.1: Nonseparable Graphs Cut vertex of a connected graph G: A vertex x G such that G x is not connected. Theorem 3.1, p. 57: Every connected

DO NOT RE-DISTRIBUTE THIS SOLUTION FILE

Advanced Algorithms Class Notes for Monday, October 23, 2012 Min Ye, Mingfu Shao, and Bernard Moret

PERFECT MATCHING THE CENTRALIZED DEPLOYMENT MOBILE SENSORS THE PROBLEM SECOND PART: WIRELESS NETWORKS 2.B. SENSOR NETWORKS OF MOBILE SENSORS

Lecture 10,11: General Matching Polytope, Maximum Flow. 1 Perfect Matching and Matching Polytope on General Graphs

Matchings in Graphs. Definition 1 Let G = (V, E) be a graph. M E is called as a matching of G if v V we have {e M : v is incident on e E} 1.

Undirected Graphs. DSA - lecture 6 - T.U.Cluj-Napoca - M. Joldos 1

Lecture 3: Graphs and flows

Approximation slides 1. An optimal polynomial algorithm for the Vertex Cover and matching in Bipartite graphs

Mathematical and Algorithmic Foundations Linear Programming and Matchings

1 Bipartite maximum matching

Exercise set 2 Solutions

Matching Algorithms. Proof. If a bipartite graph has a perfect matching, then it is easy to see that the right hand side is a necessary condition.

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1

Advanced Combinatorial Optimization September 15, Lecture 2

Lecture 4: Primal Dual Matching Algorithm and Non-Bipartite Matching. 1 Primal/Dual Algorithm for weighted matchings in Bipartite Graphs

1 Matchings in Graphs

Adjacent: Two distinct vertices u, v are adjacent if there is an edge with ends u, v. In this case we let uv denote such an edge.

MATH 363 Final Wednesday, April 28. Final exam. You may use lemmas and theorems that were proven in class and on assignments unless stated otherwise.

Topics in Combinatorial Optimization February 5, Lecture 2

Lecture 2 - Graph Theory Fundamentals - Reachability and Exploration 1

Paths, Trees, and Flowers by Jack Edmonds

COL351: Analysis and Design of Algorithms (CSE, IITD, Semester-I ) Name: Entry number:

5.1 Min-Max Theorem for General Matching

Important separators and parameterized algorithms

CS 161: Design and Analysis of Algorithms

1. Lecture notes on bipartite matching

CS 341: Algorithms. Douglas R. Stinson. David R. Cheriton School of Computer Science University of Waterloo. February 26, 2019

Larger K-maps. So far we have only discussed 2 and 3-variable K-maps. We can now create a 4-variable map in the

Graph Algorithms. Tours in Graphs. Graph Algorithms

Pentagon contact representations

AMS /672: Graph Theory Homework Problems - Week V. Problems to be handed in on Wednesday, March 2: 6, 8, 9, 11, 12.

Network flows and Menger s theorem

Notes for Lecture 20

A graph is finite if its vertex set and edge set are finite. We call a graph with just one vertex trivial and all other graphs nontrivial.

Graphs and Network Flows IE411. Lecture 21. Dr. Ted Ralphs

9.5 Equivalence Relations

Characterizing Graphs (3) Characterizing Graphs (1) Characterizing Graphs (2) Characterizing Graphs (4)

LECTURES 3 and 4: Flows and Matchings

1 Variations of the Traveling Salesman Problem

Lecture 10. Elementary Graph Algorithm Minimum Spanning Trees

DFS & STRONGLY CONNECTED COMPONENTS

Graph Theory S 1 I 2 I 1 S 2 I 1 I 2

MATH 682 Notes Combinatorics and Graph Theory II

3.1 Basic Definitions and Applications

6. Lecture notes on matroid intersection

CS473-Algorithms I. Lecture 13-A. Graphs. Cevdet Aykanat - Bilkent University Computer Engineering Department

MC302 GRAPH THEORY Thursday, 10/24/13

r=1 The Binomial Theorem. 4 MA095/98G Revision

Discrete mathematics , Fall Instructor: prof. János Pach

Lecture 8: PATHS, CYCLES AND CONNECTEDNESS

Graph theory - solutions to problem set 1

{ 1} Definitions. 10. Extremal graph theory. Problem definition Paths and cycles Complete subgraphs

Lecture 10 Graph algorithms: testing graph properties

Graph Algorithms Using Depth First Search

1 Connected components in undirected graphs

Lecture 10: Strongly Connected Components, Biconnected Graphs

CSE 417: Algorithms and Computational Complexity. 3.1 Basic Definitions and Applications. Goals. Chapter 3. Winter 2012 Graphs and Graph Algorithms

Definition. Given a (v,k,λ)- BIBD, (X,B), a set of disjoint blocks of B which partition X is called a parallel class.

Theorem 2.9: nearest addition algorithm

Chapter 3: Paths and Cycles

Math 778S Spectral Graph Theory Handout #2: Basic graph theory

Theorem 3.1 (Berge) A matching M in G is maximum if and only if there is no M- augmenting path.

Definition For vertices u, v V (G), the distance from u to v, denoted d(u, v), in G is the length of a shortest u, v-path. 1

Pentagons vs. triangles

Bipartite Roots of Graphs

Graph Algorithms. Andreas Klappenecker. [based on slides by Prof. Welch]

MC 302 GRAPH THEORY 10/1/13 Solutions to HW #2 50 points + 6 XC points

Network Flow and Matching

1 Digraphs. Definition 1

MTL 776: Graph Algorithms Lecture : Matching in Graphs

(a) (b) Figure 1: Bipartite digraph (a) and solution to its edge-connectivity incrementation problem (b). A directed line represents an edge that has

Sources for this lecture. 3. Matching in bipartite and general graphs. Symmetric difference

Matching 4/21/2016. Bipartite Matching. 3330: Algorithms. First Try. Maximum Matching. Key Questions. Existence of Perfect Matching

11.1. Definitions. 11. Domination in Graphs

5 Graphs

Restricted edge connectivity and restricted connectivity of graphs

DO NOT RE-DISTRIBUTE THIS SOLUTION FILE

Math 776 Graph Theory Lecture Note 1 Basic concepts

2. Lecture notes on non-bipartite matching

CS261: Problem Set #1

A step towards the Bermond-Thomassen conjecture about disjoint cycles in digraphs

Key Graph Theory Theorems

The External Network Problem

Graph Algorithms. Chapter 22. CPTR 430 Algorithms Graph Algorithms 1

Outline. 1 The matching problem. 2 The Chinese Postman Problem

Basic Graph Theory with Applications to Economics

Math 170- Graph Theory Notes

Ma/CS 6b Class 4: Matchings in General Graphs

Lecture notes on: Maximum matching in bipartite and non-bipartite graphs (Draft)

Lecture 22 Tuesday, April 10

Algorithms: Lecture 10. Chalmers University of Technology

Constraint Programming. Global Constraints. Amira Zaki Prof. Dr. Thom Frühwirth. University of Ulm WS 2012/2013

Extremal results for Berge-hypergraphs

CPSC 536N: Randomized Algorithms Term 2. Lecture 10

COMP 250 Fall graph traversal Nov. 15/16, 2017

Design and Analysis of Algorithms

Transcription:

Global Constraints Combinatorial Problem Solving (CPS) Enric Rodríguez-Carbonell (based on materials by Javier Larrosa) February 22, 2019

Global Constraints Global constraints are classes o constraints deined by a Boolean ormula o arbitrary arity E.g., the alldi(x 1,...,x n ) constraint orces that all the values o integer variables x 1,...,x n must be dierent E.g., the alo(x 1,...,x n ) constraint orces that at least one o the Boolean variables x 1,...,x n is set to true. E.g., the amo(x 1,...,x n ) constraint orces that at most one o the Boolean variables x 1,...,x n is set to true. The dual graph translation does not work well in practice. 2 / 47

AC or Non-binary Problems Can be naturally extended rom the binary case Value a d i is AC wrt. (non-binary) constraint c C i there exists an assignment τ (the support o a) such that: τ assigns a value to exactly the variables in scope(c) τ[x i ] = a c(τ) holds Constraint c C is AC i every a d i o every x i scope(c) has a support in c A CSP is AC i all its constraints are AC For non-binary constraints, arc consistency is also called hyperarc consistency, generalized arc consistency or domain consistency 3 / 47

Example Consider the constraint 3x+2y +z > 3 over x,y,z {0,1} Value 1 or x is AC: τ = (x 1,y 1,z 1) is a support Value 0 or x is not AC: it does not have any support. Hence, the constraint is not AC 4 / 47

Example Note that AC depends on the syntax Consider x 1 {a,b}, x 2 {a,b}, x 3 {a,c,d} Case 1: constraints are x i x j or all i < j All constraints are arc-consistent Case 2: there is only one constraint alldi(x 1,x 2,x 3 ) Value a or x 1 is AC because τ = (x 1 a,x 2 b,x 3 c) is a support or it. Value a or x 3 is not AC: does not have any support Hence, the constraint is not AC 5 / 47

Enorcing AC: Revise(i, c) Natural extension o binary case Removes domain values o x i without a support in c // Let (x 1,...,x i 1,x i,x i+1...,x k ) be the scope o c unction Revise(i, c) change := alse or each a d i do i a1 d 1,...,a i 1 d i 1,a i+1 d i+1,...,a k d k c(x 1 a 1,...,x i a,...,x k a k ) remove a rom d i change := true return change The time complexity o Revise(i,c) is O(k d 1 d k ) (assuming that evaluating a constraint takes linear time in the arity) 6 / 47

AC-3 The natural extension o binary AC-3 (i,c) Q means that we cannot guarantee that all domain values o x i have a support in c procedure AC3(X, D, C) Q := {(i,c) c C,x i scope(c)} while Q do (i,c) := Fetch(Q) // selects and removes i Revise(i, c) then Q := Q {(j,c ) c C,c c,j i,{x i,x j } scope(c )} Let m = max i { d i }, e = C and k = max c { scope(c) } Time complexity: O(e k 3 m k+1 ) Space complexity: O(e k) 7 / 47

AC or non-binary constraints Enorcing AC with generic algorithms is exponentially expensive in the maximum arity o the CSP Only practical with constraints o very small arity Is it possible to develop constraint-speciic algorithms? procedure Revise(c) // removes every arc-inconsistent value a d i or all x i X(c) endprocedure Next: alldi constraint... but irst a diversion to matching theory 8 / 47

Begin Matching Theory 9 / 47

Deinitions Given a graph G = (V,E), a matching M is a set o pairwise non-incident edges A vertex is matched or covered i it is an endpoint o some e M, and it is ree otherwise A maximum matching is a matching that contains the largest possible number o edges (edges in the matching, in blue) In particular, a perect matching matches all vertices o the graph 10 / 47

Example We have to organize one round o a ootball league. Compatibility relation between teams is given by a graph B D F A C E Perect matchings easible arrangements o matches 11 / 47

Bipartite Matching Graph G = (V,E) is bipartite i there is a partition (L,R) o V (i.e., L R = V,L R = ) such that each e E connects a vertex in L to one in R Now ocus on maximum bipartite matching problem: given a bipartite graph, ind a matching o maximum size From now on, assume V 2 E (isolated vertices can be removed) 12 / 47

Example (I) Assignment problem: n workers, m tasks list o pairs (w,t) meaning: worker w can do task t Maximum matchings tell how to assign tasks to workers so that the maximum number o tasks are carried out A Algebra B Calculus C D Geometry 13 / 47

Example (II) We have n variables x 1,...,x n Variable x i can take values in D i Z inite (1 i n) Constraint alldierent(x 1,...,x n ) imposes that variables should take dierent values pairwise 1 D 1 = {1} D 2 = {1,2,3} D 3 = {4} x 1 x 2 2 3 x 3 4 Matchings covering x 1,...,x n correspond to solutions to alldierent(x 1,...,x n ) 14 / 47

Augmenting Paths Let M be a matching o G = (V,E) (not necessarily bipartite). We view paths as sequences o edges rather than vertices. An alternating path is a simple path in which the edges belong alternatively to M and not to M. An alternating cycle is a cycle in which the edges belong alternatively to M and not to M. An augmenting path is an alternating path that starts and ends at dierent ree vertices. Berge s Lemma. A matching is maximum i and only i it does not have any augmenting path. 15 / 47

Properties (I) An alternating cycle has as many edges in M as not in M An augmenting path has 1 more edge not in M than in M Given two sets A,B X, their symmetric dierence is A B = (A B) (B A) I P is an augmenting path wrt. M, then M P is a matching and M P = M +1 I.e., i we paint edges M in blue and edges M in red, then lipping the colors o P results in a valid matching 16 / 47

Proo o Berge s Lemma (I) Let us prove the contrapositive: G has a matching larger than M i and only i G has an augmenting path wrt. M ( ) Just proved in the last slide. 17 / 47

Proo o Berge s Lemma (II) ( ) Let M be a matching in G larger than M. Each vertex o M M has degree at most two: incident with 1 edge rom M and 1 edge rom M So M M is a vertex-disjoint union o simple paths and cycles. Furthermore, paths and cycles in M M are alternating (wrt. M, and wrt. M ) Edges M, M Edges M, M 18 / 47

Proo o Berge s Lemma (III) ( ) (cont.) Since M > M, M M must contain at least one connected component that has more edges rom M than rom M. Such a component is a simple path in G that starts and ends at dierent vertices with edges M. The extreme vertices are ree. So the path is augmenting. 19 / 47

Aug. Paths in Bipartite Graphs Idea: Starting rom the empty matching, increase the size o the current matching by inding augmenting paths Now assume the graph is bipartite. For inding augmenting paths, do the ollowing: 1. Mark vertices as matched or ree. 2. Start DFS (Depth First Search) or BFS (Breadth First Search) rom each o the ree vertices in L. 3. Traverse edges M rom L to R. 4. Traverse edges M rom R to L. 5. Stop successully i a ree vertex rom R is reached. 6. Stop with ailure i search terminates without inding a ree vertex rom R. Cost: O( E ) 20 / 47

Algorithm int MAX_BIPARTITE_MATCHING(bipartite_graph G) { M = ; P = AUG_PATH(G, M); while (P!= NULL) { M = M P; P = AUG_PATH(G, M); } return M.size(); } Cost: O( V E ) Each iteration costs O( E ) At each iteration 2 new vertices are matched (one rom L and one rom R) So at most min( L, R ) = O( V ) iterations suice 21 / 47

Example Bipartite graph G = (L R,E) Initially matching M is empty. Blue edges: e M Red edges: e M Let us look or an augmenting path using DFS. L R 22 / 47

Example Mark vertices as matched (m) or ree (). Start at a ree vertex in L. Let right: red edges Right let: blue edges 22 / 47

Example Found a ree vertex in R. Found an augmenting path. 22 / 47

Example Flip colors o augmenting path and a new M is obtained 22 / 47

Example Let us look or another augmenting path. By symmetry. 22 / 47

Example Let us look or another augmenting path. Mark vertices as matched (m) or ree (). Start at a ree vertex in L. Let right: red edges Right let: blue edges m m m m 22 / 47

Example m Found a ree vertex in R. Found an augmenting path. m m m 22 / 47

Example Flip colors o augmenting path and a new M is obtained 22 / 47

Example By symmetry. No more augmenting paths, M is a maximum matching 22 / 47

Hopcrot-Karp Algorithm I P 1,...,P k are vertex-disjoint augmenting paths wrt. M, then M (P 1 P k ) is a matching o M +k edges Idea: instead o inding 1 augmenting path per iteration, let us ind a maximal set o vertex-disjoint shortest augmenting paths This reduces the number o iterations rom O( V ) to O( V ) int HOPCROFT_KARP( bipartite_gra G) { M = ; S = MAXIMAL_SET_VD_SHORTEST_AUG_PATHS(G, M ); while (S!= ) { M = M { P P S }; S = MAXIMAL_SET_VD_SHORTEST_AUG_PATHS(G, M ); } return M.size(); } 23 / 47

Max. Vertex-Disjoint Shortest AP Let us ind a maximal set o vertex-disjoint shortest augmenting paths Let l be the length o the shortest augmenting paths wrt. M Goal: compute a maximal (not necessarily maximum) set o vertex-disjoint augmenting paths o length l Phase 1: compute length l and augmenting paths o length l 1. BFS but start simultaneously at all ree vertices in L 2. Traverse edges M rom L to R 3. Traverse edges M rom R to L 4. I a ree vertex is ound in R: current distance is l, the length o the shortest augmenting paths 5. Complete BFS ater inding all ree vertices in R at distance l 24 / 47

Max. Vertex-Disjoint Shortest AP We need augmenting paths to be vertex-disjoint Phase 2: ensure vertex-disjointness and maximality Let X be the set o all ree vertices in R at distance l 1. Compute DFS rom u X to the ree vertices in L, using the BFS distances to guide the search: the DFS is only allowed to ollow edges that lead to an unused vertex in the previous distance layer the DFS must alternate between matched and unmatched edges. 2. Once an augmenting path is ound, mark its vertices as used and continue the DFS rom the next u X. Cost o Phase 1: O( E ) (1 single BFS!) Cost o Phase 2: O( E ) (1 single DFS!) 25 / 47

Progress in Hopcrot-Karp Theorem. Let: l = length o a shortest augmenting path wrt. M P 1,...,P k = a maximal set o vertex-disjoint shortest augmenting paths wrt. M M = M (P 1... P k ) P = a shortest augmenting path with respect to M Then P > l. I.e., rom one iteration to the next one, the length o the shortest augmenting path increases 26 / 47

Progress in Hopcrot-Karp Proo. Let us consider two cases: 1. P is vertex-disjoint rom P 1,...,P k. By contradiction. Since P is an augmenting path wrt. M and is vertex-disjoint rom P 1,...,P k, P is an augmenting path wrt. M. Then P l. I P = l, then P is a shortest augmenting path wrt. M. But this contradicts the maximality o P 1,...,P k. So P > l. 27 / 47

Progress in Hopcrot-Karp 2. P is not vertex-disjoint rom P 1,...,P k. By de., M = M (P 1... P k ). So M M = (M M) (P 1... P k ) = P 1... P k. So H := M M P = (P 1... P k ) P. But H is a set o vertex-disjoint cycles and simple paths. And M P M = M P M + M M = k +1 So there are at least k +1 simple paths in H that use more edges rom M P than rom M. Each o these is an augmenting path wrt. M. So H contains k+1 vertex-disjoint augmenting paths with respect to M, each o which o length l. 28 / 47

Progress in Hopcrot-Karp (cont.) So H = (P 1... P k ) P (k +1)l. Hence (P 1... P k ) P + P (P 1... P k ) (k+1)l As P 1,...,P k are vertex-disjoint and have length l, they contribute to (P 1... P k ) P with at most kl distinct edges. So P (P 1... P k ) contributes with at least l edges to the inequality. I.e., P (P 1... P k ) l. So P = P (P 1... P k ) + P (P 1... P k ) l+ P (P 1... P k ) Now let us see that P (P 1... P k ) 1 Let v be a vertex shared by P and some P i. As P i is an augmenting path wrt. M, there is an edge e P i M with endpoint v. So e M and e is the only edge o M with endpoint v. As v is matched in M, v P and P is an augmenting path wrt. M, there is a unique edge in P M with endpoint v, which must be e. So we have that e P P i, that P (P 1... P k ) 1, and P > l 29 / 47

Complexity o Hopcrot-Karp We already know that each iteration takes O( E ) time. Theorem. Hopcrot-Karp runs in O( V E ) time. (actually, in O( min( L, R ) E ) time) Best known algorithm or bipartite matching. Lema. Hopcrot-Karp takes at most 2 min( L, R ) iterations. Proo. Wlog. let us assume that L R. Ater L iterations: 1. either the algorithm terminated because a maximum matching was ound, or 2. a matching M was obtained or which the shortest augmenting path (wrt. M) has length 2 L +1 30 / 47

Complexity o Hopcrot-Karp Proo. (contd.) Assume 2. Let M be a maximum matching o G. M M contains at least M M vertex-disjoint augmenting paths with respect to M. Each o those paths has length 2 L +1. Since each vertex o M M has degree 2, M M is a vertex-disjoint union o simple paths and cycles. As the graph G is bipartite: 1. In a simple path P M M o odd length, the number o vertices rom L is ( P +1)/2, which is P /2. 2. In a simple path P M M o even length, the number o vertices rom L is P /2 or 1+ P /2, which is P /2. 3. In a cycle C M M (thus, o even length, as it is alternating), the number o vertices rom L is C /2. By vertex-disjointness, there are M M 2 vertices rom L in M M. So in L there are at least M M 2 dierent vertices. 31 / 47

Complexity o Hopcrot-Karp Proo. (contd.) Thus 2 L M M ( M M )(2 L +1) So M M 2 L = 2 L L 2 L +1 2 L +1 (2 L +1) L 2 L +1 = L. Hence, ater another at most L iterations, the algorithm is guaranteed to ind a maximum matching. 32 / 47

Example Bipartite graph G = (L R,E) Initially matching M is empty. Blue edges: e M Red edges: e M Let us look or a maximal set o shortest augmenting paths using BFS. L R 33 / 47

Example Mark vertices as matched (m) or ree (). Start at all ree vertices in L. Let right: red edges Right let: blue edges 33 / 47

Example Shortest augmenting path has length 1. Found all ree vertices in R at distance 1. Found maximal set o shortest aug. paths. (note that it is not maximum) 33 / 47

Example Flip colors o augmenting paths and new M is obtained 33 / 47

Example Another maximal set o shortest augmenting paths? Mark vertices as matched (m) or ree (). Start at all ree vertices in L. Let right: red edges Right let: blue edges m m m m 33 / 47

Example m Shortest augmenting path has length 3. Found all ree vertices in R at distance 3. Found maximal set o shortest aug. paths m m m 33 / 47

Example Flip colors o augmenting path and a new M is obtained No more augmenting paths, M is a maximum matching 33 / 47

End Matching Theory 34 / 47

Arc Consistency or alldi [reminder] Consider x 1 {1,2}, x 2 {2,3}, x 3 {2,3} and the constraint alldi(x 1,x 2,x 3 ) Value 1 or x 1 is AC since τ = (x 1 1,x 2 2,x 3 3) is a support or it. Value 2 or x 1 is not AC: it does not have any support (no room let or x 2,x 3 ) Ater enorcing AC: x 1 {1}, x 2 {2,3}, x 3 {2,3} 35 / 47

Value Graph o alldi Given variables X = {x 1,...,x n } with domains D 1,...,D n, the value graph o alldi(x 1,...,x n ) is the bipartite graph G = (X n i=1 D i,e) where (x i,v) E i v D i alldi(x 1,x 2,x 3 ) D 1 = {1,2} D 2 = {2,3} D 3 = {2,3} x 1 x 2 x 3 1 2 3 36 / 47

Solutions and Matchings We say a matching M covers a set S i every vertex in S is covered (i.e, is an endpoint o an edge in M) Solutions to alldi(x) = matchings covering X alldi(x 1,x 2,x 3 ) D 1 = {1,2} D 2 = {2,3} D 3 = {2,3} x 1 = 1 x 2 = 2 x 3 = 3 x 1 x 2 x 3 1 2 3 37 / 47

Solutions and Matchings We say a matching M covers a set S i every vertex in S is covered (i.e, is an endpoint o an edge in M) Solutions to alldi(x) = matchings covering X alldi(x 1,x 2,x 3 ) D 1 = {1,2} D 2 = {2,3} D 3 = {2,3} x 1 = 1 x 2 = 3 x 3 = 2 x 1 x 2 x 3 1 2 3 37 / 47

Solutions and Matchings We say a matching M covers a set S i every vertex in S is covered (i.e, is an endpoint o an edge in M) Solutions to alldi(x) = matchings covering X alldi(x 1,x 2,x 3 ) D 1 = {1,2} D 2 = {2,3} D 3 = {2,3} x 1 = 1 x 2 = 3 x 3 = 2 x 1 x 2 x 3 1 2 3 A matching covering X is a maximum matching There are solutions to alldi(x) i size o maximum matchings is X 37 / 47

Solutions and Matchings Algorithm or checking easibility o alldi(x): (with Hopcrot-Karp, in time O(dn n), where n = X, d = max i { D i }) // Returns true i there is a solution to alldi(x) // G is the value graph o alldi(x) M = COMPUTE MAXIMUM MATCHING(G) i ( M < X ) return alse return true 38 / 47

Solutions and Matchings Algorithm or checking easibility o alldi(x): (with Hopcrot-Karp, in time O(dn n), where n = X, d = max i { D i }) // Returns true i there is a solution to alldi(x) // G is the value graph o alldi(x) M = COMPUTE MAXIMUM MATCHING(G) i ( M < X ) return alse else REMOVE EDGES FROM GRAPH(G, M) return true But rather than checking easibility we want to ind arc-inconsistent values I alldi(x) has a solution then: value v rom the domain o variable x is arc-inconsistent i there is no solution to alldi(x) that assigns value v to x i there is no matching covering X that contains edge (x,v) i there is no maximum matching that contains edge (x,v) So we have to remove the edges not belonging to any maximum matching Next: we ll extend the algorithm to do so by using the matching M 38 / 47

Filtering A vital edge belongs to any maximum matching Theorem. Let M be an arbitrary maximum matching. An edge belongs to a maximum matching i it is vital; or it belongs to an alternating cycle wrt. M; or it belongs to an even-length simple alternating path starting at a ree vertex wrt. M x 1 x 2 x 3 1 2 3 39 / 47

Filtering A vital edge belongs to any maximum matching Theorem. Let M be an arbitrary maximum matching. An edge belongs to a maximum matching i it is vital; or it belongs to an alternating cycle wrt. M; or it belongs to an even-length simple alternating path starting at a ree vertex wrt. M x 1 x 2 x 3 1 2 3 39 / 47

Filtering Proo: ) Let us consider all cases: I edge e is vital, then by deinition it belongs to a maximum matching I e belongs to an alternating cycle P wrt. maximum matching M, then M and M P are maximum matchings, one contains e and the other does not Similary i e belongs to an even-length path starting at a ree vertex that is alternating wrt. maximum matching M 40 / 47

Filtering Proo: ) Let e be an edge that belongs to a maximum matching. Let us assume that e is not vital. Two cases: Suppose e M. Since e is not vital, there exists a maximum matching M such that e M. Then e M M. But M M is a vertex-disjoint union o: 41 / 47

Filtering Proo: ) Let e be an edge that belongs to a maximum matching. Let us assume that e is not vital. Two cases: Suppose e M. Since e is not vital, there exists a maximum matching M such that e M. Then e M M. But M M is a vertex-disjoint union o: Recall that M,M are maximum matchings 41 / 47

Filtering Proo: ) Let e be an edge that belongs to a maximum matching. Let us assume that e is not vital. Two cases: Suppose e M. Let M be a maximum matching such that e M (which exists by hypothesis). Then the same argument as beore applies. 41 / 47

Orienting Edges It simpliies things to orient edges: Matching edges are oriented rom let to right Free edges are oriented rom right to let x 1 x 2 x 3 1 2 3 42 / 47

Orienting Edges Corollary. Let M be an arbitrary maximum matching. An edge belongs to a maximum matching i it belongs to a cycle wrt. M; or it belongs to a simple path starting at a ree vertex wrt. M; or it is vital in the oriented graph. x 1 x 2 x 3 1 2 3 43 / 47

Removing Arc-Inconsistent Edges We will actually identiy AC edges, and the remaining ones will be non-ac An edge (u,v) belongs to a cycle in a digraph G i u,v belong to the same strongly connected component o G REMOVE EDGES FROM GRAPH(G, M) 0) Mark all edges in G as UNUSED 1) Compute SCCs, mark as USED edges with vertices in same SCC 2) Look or all edges that belong to a simple path starting at a ree vertex with graph traversal (DFS/BFS) rom ree vertices, and mark them as USED 3) Mark UNUSED edges o M as VITAL 4) Remove remaining UNUSED edges Time complexity: linear in the size o the value graph 44 / 47

Computing SCC s Given a directed graph G = (V,E), its SCC s can be computed in time O( V + E ): Tarjan s algorithm Path-based strong component algorithm Kosaraju s algorithm 1. Do a DFS 2. Reverse the direction o the edges 3. Do a DFS in reverse chronological order wrt. irst DFS 4. Each tree in the previous DFS orest is a SCC 45 / 47

Example Variables {w,x,y,z} Domains d(w) = {b,c,d,e}, d(x) = {b,c}, d(y) = {a,b,c,d}, d(z) = {b,c} w x y z a b c d e 46 / 47

Example We assume we already have a maximum matching All variables are covered w x y z a b c d e 46 / 47

Example Direct the edges w x y z a b c d e 46 / 47

Example Compute SCC s w x y z a b c d e 46 / 47

Example Compute all simple paths starting at a ree vertex w x y z a b c d e 46 / 47

Example Remove unused edges that are not vital Ater enorcing arc consistency: d(w) = {d,e}, d(x) = {b,c}, d(y) = {a,d}, d(z) = {b,c} w x y z a b c d e 46 / 47

Complexity Consider CSP with a single constraint alldi(x 1,...,x k ) where m = max i { D i } Cost o enorcing AC with AC-3: O(k 3 m k+1 ) Cost o enorcing AC with bipartite matching: O(km k) Cost o constructing maximum matching: O(km k) Cost o removing edges: O(km) 47 / 47