chapter graph algorithms -...

33
Chapter 5 Graph Algorithms Matching Algorithm Theory WS 2012/13 Fabian Kuhn

Upload: others

Post on 19-Oct-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

  • Chapter 5Graph Algorithms

    Matching

    Algorithm TheoryWS 2012/13

    Fabian Kuhn

  • Algorithm Theory, WS 2012/13 Fabian Kuhn 2

    Circulation: Demands and Lower BoundsGiven: Directed network  , with• Edge capacities  0 and lower bounds  ℓ for  ∈• Node demands  ∈ for all  ∈

    – 0: node needs flow and therefore is a sink– 0: node has a supply of  and is therefore a source– 0: node is neither a source nor a sink

    Flow: Function  : → satisfying• Capacity Conditions: ∀ ∈ :ℓ

    • Demand Conditions: ∀ ∈ :

    Objective: Does a flow  satisfying all conditions exist?If yes, find such a flow  .

  • Algorithm Theory, WS 2012/13 Fabian Kuhn 3

    IntegralityTheorem: Consider a circulation problem with integral capacities, flow lower bounds, and node demands. If the problem is feasible, then it also has an integral solution.

    Proof:• Graph  ′ has only integral capacities and demands• Thus, the flow network used in the reduction to solve 

    circulation with demands and no lower bounds has only integral capacities

    • The theorem now follows because a max flow problem with integral capacities also has an optimal integral solution

    • It also follows that with the max flow algorithms we studied, we get an integral feasible circulation solution.

  • Algorithm Theory, WS 2012/13 Fabian Kuhn 4

    Matrix Rounding• Given: matrix  , of real numbers• row  sum:  ∑ , ,     column  sum:  ∑ ,• Goal: Round each  , , as well as  and  up or down to the 

    next integer so that the sum of rounded elements in each row (column) equals the rounded row (column) sum

    • Original application: publishing census data

    Example:

    3.14 6.80 7.30 17.249.60 2.40 0.70 12.703.60 1.20 6.50 11.3016.34 10.40 14.50

    3 7 7 1710 2 1 133 1 7 1116 10 15

    original data possible rounding

  • Algorithm Theory, WS 2012/13 Fabian Kuhn 5

    Matrix RoundingTheorem: For any matrix, there exists a feasible rounding. 

    Remark: Just rounding to the nearest integer doesn’t work

    0.35 0.35 0.35 1.050.55 0.55 0.55 1.650.90 0.90 0.90

    0 0 0 01 1 1 31 1 1

    0 0 1 11 1 0 21 1 1

    original data

    feasible roundingrounding to nearest integer

  • Algorithm Theory, WS 2012/13 Fabian Kuhn 6

    Reduction to Circulation

    3.14 6.80 7.30 17.249.60 2.40 0.70 12.703.60 1.20 6.50 11.3016.34 10.40 14.50

    rows:

    columns:3,4

    2,312,13 10,11

    Matrix elements and row/column sumsgive a feasible circulation that satisfiesall lower bound, capacity, and demandconstraints

    all demands  0

  • Algorithm Theory, WS 2012/13 Fabian Kuhn 7

    Matrix RoundingTheorem: For any matrix, there exists a feasible rounding.

    Proof:• The matrix entries  , and the row and column sums  and 

    give a feasible circulation for the constructed network

    • Every feasible circulation gives matrix entries with corresponding row and column sums (follows from demand constraints)

    • Because all demands, capacities, and flow lower bounds are integral, there is an integral solution to the circulation problem

    gives a feasible rounding!

  • Algorithm Theory, WS 2012/13 Fabian Kuhn 8

    Matching

  • Algorithm Theory, WS 2012/13 Fabian Kuhn 9

    Gifts‐Children Graph• Which child likes which gift can be represented by a graph

  • Algorithm Theory, WS 2012/13 Fabian Kuhn 10

    MatchingMatching: Set of pairwise non‐incident edges

    Maximal Matching: A matching s.t. no more edges can be added

    Maximum Matching: A matching of maximum possible size

    Perfect Matching:Matching of size  ⁄ (every node is matched)

  • Algorithm Theory, WS 2012/13 Fabian Kuhn 11

    Bipartite GraphDefinition: A graph  , is called bipartite iff its node set can be partitioned into two parts  ∪ such that for each edge  u, v ∈ ,

    , ∩ 1.

    • Thus, edges are only between the two parts

  • Algorithm Theory, WS 2012/13 Fabian Kuhn 12

    Santa’s ProblemMaximum Matching in Bipartite Graphs:

    Every child can get a giftiff there is a matchingof size #children

    Clearly, every matchingis at most as big

    If #children #gifts,there is a solution iffthere is a perfect matching

  • Algorithm Theory, WS 2012/13 Fabian Kuhn 13

    Reducing to Maximum Flow• Like edge‐disjoint paths…

    all capacities are 

  • Algorithm Theory, WS 2012/13 Fabian Kuhn 14

    Reducing to Maximum FlowTheorem: Every integer solution to the max flow problem on the constructed graph induces a maximum bipartite matching of  .

    Proof:1. An integer flow  of value | | induces a matching of size | |

    – Left nodes (gifts) have incoming capacity 1– Right nodes (children) have outgoing capacity 1– Left and right nodes are incident to  1 edge  of  with  1

    2. A matching of size  implies a flow  of value – For each edge  , of the matching:

    , , , 1

    – All other flow values are 0

  • Algorithm Theory, WS 2012/13 Fabian Kuhn 15

    Running Time of Max. Bipartite MatchingTheorem: A maximum matching of a bipartite graph can be computed in time 

  • Algorithm Theory, WS 2012/13 Fabian Kuhn 16

    Perfect Matching?• There can only be a perfect matching if both sides of the 

    partition have size  ⁄ .

    • There is no perfect matching, iff there is an  ‐ cut ofsize  ⁄ in the flow network.

    2 2

  • Algorithm Theory, WS 2012/13 Fabian Kuhn 17

    ‐ Cuts

    Partition  , of node set such that  ∈ and  ∈

    • If  ∈ : edge  , is in cut  ,

    • If  ∈ : edge  , is in cut  ,

    • Otherwise (if  ∈ ,  ∈ ), all edges from  to some ∈ are in cut  ,

  • Algorithm Theory, WS 2012/13 Fabian Kuhn 18

    Hall’s Marriage TheoremTheorem: A bipartite graph  ∪ , for which  | |has a perfect matching if and only if

    ∀ ⊆ : ,where  ⊆ is the set of neighbors of nodes in  ′.

    Proof:  No perfect matching ⟺ some  ‐ cut has capacity 1. Assume there is  ′ for which  |U |:

  • Algorithm Theory, WS 2012/13 Fabian Kuhn 19

    Hall’s Marriage TheoremTheorem: A bipartite graph  ∪ , for which  | |has a perfect matching if and only if

    ∀ ⊆ : ,where  ⊆ is the set of neighbors of nodes in  ′.

    Proof:  No perfect matching ⟺ some  ‐ cut has capacity 2. Assume that there is a cut  , of capacity 

  • Algorithm Theory, WS 2012/13 Fabian Kuhn 20

    Hall’s Marriage TheoremTheorem: A bipartite graph  ∪ , for which  | |has a perfect matching if and only if

    ∀ ⊆ : ,where  ⊆ is the set of neighbors of nodes in  ′.

    Proof:  No perfect matching ⟺ some  ‐ cut has capacity 2. Assume that there is a cut  , of capacity 

  • Algorithm Theory, WS 2012/13 Fabian Kuhn 21

    What About General Graphs• Can we efficiently compute a maximum matching if  is not 

    bipartitie?

    • How good is a maximal matching?– A matching that cannot be extended…

    • Vertex Cover: set  ⊆ of nodes such that∀ , ∈ , , ∩ ∅.

    • A vertex cover covers all edges by incident nodes

  • Algorithm Theory, WS 2012/13 Fabian Kuhn 22

    Vertex Cover vs MatchingConsider a matching  and a vertex cover 

    Claim: | |

    Proof: • At least one node of every edge  , ∈ is in • Needs to be a different node for different edges from 

  • Algorithm Theory, WS 2012/13 Fabian Kuhn 23

    Vertex Cover vs MatchingConsider a matching  and a vertex cover 

    Claim: If  is maximal and  is minimum,  2

    Proof: • is maximal: for every edge  , ∈ , either  or  (or both) 

    are matched 

    • Every edge  ∈ is “covered” by at least one matching edge• Thus, the set of the nodes of all matching edges gives a vertex 

    cover  of size  2| |.

  • Algorithm Theory, WS 2012/13 Fabian Kuhn 24

    Maximal Matching ApproximationTheorem: For any maximal matching  and any maximum matching ∗, it holds that

    2 .

    Proof:

    Theorem: The set of all matched nodes of a maximal matching  is a vertex cover of size at most twice the size of a min. vertex cover.

  • Algorithm Theory, WS 2012/13 Fabian Kuhn 25

    Augmenting PathsConsider a matching  of a graph  , :• A node  ∈ is called free iff it is not matched

    Augmenting Path: A (odd‐length) path that starts and ends at a free node and visits edges in  ∖ and edges in  alternatingly.

    • Matching  can be improved using an augmenting path by switching the role of each edge along the path

    free nodes

    alternating path

  • Algorithm Theory, WS 2012/13 Fabian Kuhn 26

    Augmenting PathsTheorem: A matching  of  , is maximum if and only if there is no augmenting path.Proof:• Consider non‐max. matching  and max. matching  ∗ and define

    ≔ ∖ ∗, ∗ ≔ ∗ ∖

    • Note that  ∩ ∗ ∅ and  | ∗|• Each node  ∈ is incident to at most one edge in both  and  ∗

    • ∪ ∗ induces even cycles and paths

  • Algorithm Theory, WS 2012/13 Fabian Kuhn 27

    Finding Augmenting Paths

    free nodes

    augmenting path

    odd cycle

  • Algorithm Theory, WS 2012/13 Fabian Kuhn 28

    Blossoms• If we find an odd cycle…

    free node

    blossom

    stem

    ′ ′

    contracted blossom

    contract blossom

    Graph 

    Graph  ′

    root

    Matching 

    Matching  ∖ ,is a matching of  .

  • Algorithm Theory, WS 2012/13 Fabian Kuhn 29

    Lemma: Graph  has an augmenting path w.r.t. matching  iff ′has an augmenting path w.r.t. matching  ′

    Also: The matching  can be computed efficiently from  ′.

    Contracting Blossoms

    ′ ′

    ′ ′

    ′ ′

    Note: If stem has length 0,root  of blossom if freeand thus also the node is free in  ′.

  • Algorithm Theory, WS 2012/13 Fabian Kuhn 30

    Edmond’s Blossom AlgorithmAlgorithm Sketch:1. Build a tree for each free node2. Starting from an explored node  at even distance from a free 

    node  in the tree of  , explore some unexplored edge  , :

    1. If  is an unexplored node,  is matched to some neighbor  :add  to the tree ( is now explored)

    2. If  is explored and in the same tree:at odd distance from root  ignore and move onat even distance from root  blossom found

    3. If  is explored and in another treeat odd distance from root  ignore and move onat even distance from root  augmenting path found

  • Algorithm Theory, WS 2012/13 Fabian Kuhn 31

    Running TimeFinding a Blossom: Repeat on smaller graph

    Finding an Augmenting Path: Improve matching

    Theorem: The algorithm can be implemented in time  .

  • Algorithm Theory, WS 2012/13 Fabian Kuhn 32

    Matching AlgorithmsWe have seen:• time alg. to compute a max. matching in bipartite graphs• time alg. to compute a max. matching in general graphs

    Better algorithms:

    • Best known running time (bipartite and general gr.): 

    Weighted matching:• Edges have weight, find a matching of maximum total weight• Bipartite graphs: flow reduction works in the same way• General graphs: can also be solved in polynomial time

    (Edmond’s algorithms is used as blackbox)

  • Algorithm Theory, WS 2012/13 Fabian Kuhn 33

    Happy Holidays!