43_päges_maximum matching algorithm

download 43_päges_maximum matching algorithm

of 43

Transcript of 43_päges_maximum matching algorithm

  • 8/3/2019 43_pges_maximum matching algorithm

    1/43

    Maximum Weighted

    Matching Algorithm

    Christina Witwer

    Wien 2002

    Institute for Theoretical Biochemistry

    University of Vienna

  • 8/3/2019 43_pges_maximum matching algorithm

    2/43

    Some Definitions(I)

    A graph G consists of a set V of vertices (nodes) and

    a set E of edges

    G = (V, E)

    A weighted graph has a weight wij assigned to each

    edge [vi, vj] E.

    24

    24

    32

    32

    12

    24

    0

    1

    2

    3

    4

    5

    12

    12

    Matching: A subset M E of edges is called a mat-

    ching, if each vertex is contained in no more than one

    edge.

    24

    24

    32

    32

    12

    24

    0

    1

    2

    3

    4

    5

    12 12

  • 8/3/2019 43_pges_maximum matching algorithm

    3/43

    Some Definitions(II)

    Maximum cardinality matching: contains the maxi-

    mum number of edges of a graph that form a mat-

    ching.

    Maximum weighted matching: The sum of the weights

    of the edges forming the matching is maximal.

  • 8/3/2019 43_pges_maximum matching algorithm

    4/43

    Motivation

    View a RNA-sequence with a list of possible basepairs

    as a graph:Nucleotides Vertices

    Basepairs Edges

    Sequence: GUCAUCGA

    V = {1, 2, 3, 4, 5, 6, 7, 8}

    Possible basepairs:

    E = {(1, 3), (1, 5), (1, 6), (2, 4), (2, 7), (2, 8), (3, 7), (5, 7), (5, 8

    G1

    G7

    A8 U2

    A4U5

    C6

    C3

    G1

    G7

    A8 U2

    A4U5

    C6

    C3

    C

    A

    G

    UC

    G AU

  • 8/3/2019 43_pges_maximum matching algorithm

    5/43

    Some Definitions(III)

    Alternating path with respect to a matching M: Or-

    dered list of vertices, so that

    each vertex is contained only once

    the edges connecting the vertices are alternately

    in M and not in M.

    1

    2

    34

    5

    6

  • 8/3/2019 43_pges_maximum matching algorithm

    6/43

    Some Definitions(IV)

    Augmenting path with respect to a matching M: An

    alternating path that starts and ends with an unmat-

    ched edge.

    Symmetric Difference: S1 S2 = (S1 S2) (S1 S2)

    M = {(2, 4), (3, 5)}

    P = {(1, 2), (2, 4), (4, 3), (3, 5), (5, 6)}

    1

    2

    3

    4

    5

    6

    Augment: M = M P

    1

    2

    3

    4

    5

    6

    M = {(1, 2), (4, 3), (5, 6)}

  • 8/3/2019 43_pges_maximum matching algorithm

    7/43

    Berges Lemma: A matched graph (G, M) has an aug-

    menting path if and only if M is not a maximum car-

    dinality matching.

    Sketch for an algorithm

    k-Matching

    search for an augmenting path

    augment

    (k+1)-Matching

    If no more augmenting path exists, the matching is

    maximum

  • 8/3/2019 43_pges_maximum matching algorithm

    8/43

    Maximum Cardinality Matching

    Search for an augmenting path

    Initially all unmatched vertices of the graph are labe-led even (+), all matched vertices are unlabeled (*).

    Starting with an unmatched vertex r+ a tree T is

    grown.

    Let v / T be adjacent to any vertex u+ T. T is

    extended by taking the unmatched edge uv and the

    matched edge vw to T. v is labeled odd (-) and w is

    labeled even (+).

    Grow step

    r

    v w+ * *

    r

    v w+ +

    When an even vertex u+ / T is adjacent to any vertex

    u+ T, an augmenting path p = (v , u , . . . , r) with

    respect to M has been found.

    r n u v

    + + +r n u v

    _+ ++

  • 8/3/2019 43_pges_maximum matching algorithm

    9/43

    Blossoms

    r 1 b

    6

    3

    4

    5

    7 8

    +

    +

    +

    + +

    +

    Shrink step: G = (V, E)

    V = (V \ B) {b}

    E = (V \ B) {ub : uv (B) and u B}

    r 1 b

    6

    3

    4

    5

    7 8

    b+

    +

    + +

  • 8/3/2019 43_pges_maximum matching algorithm

    10/43

    More Definitions

    (S) = {uv E : u S and v S}

    (S) = {uv E : u S and v S}

    1

    5

    23

    4

    6

    7

    B

    8

    (S) = {(3, 7), (4, 6)}

    (S) = {(1, 2), (2, 3), (3, 4), (4, 5), (1, 5)}

  • 8/3/2019 43_pges_maximum matching algorithm

    11/43

    Blossoms can be nested

    0 1

    2

    3

    4 5

    67

    8

    910

    11

    r

    13

    14

    B1B2

    Each vertex is a (trivial) blossom.

    B1 is a subblossom of B2.

    B2 is a (non-trivial) surface blossom.

  • 8/3/2019 43_pges_maximum matching algorithm

    12/43

    Search for an augmenting path (I)

    r 1 2

    3 4

    5 6

    7 8

    9 10 11 +

    *

    * *

    * *

    + * *

    *

    * *

    grow step

    r 1 2

    3 4

    5 6

    7 8

    9 10 11

    + +

    * *

    * *

    * *

    * * +

    grow steps

  • 8/3/2019 43_pges_maximum matching algorithm

    13/43

    Search for an augmenting path (II)

    r 1 2

    3 4

    5 6

    7 8

    9 10 11

    ++

    +

    +

    * *

    +

    +

    shrink step

    r 1 2(b) 7 8

    9 10 11

    + + +

    +* *

    grow steps

  • 8/3/2019 43_pges_maximum matching algorithm

    14/43

    Search for an augmenting path (III)

    r 1 2(b) 7 8

    9 10 11+

    +

    +

    ++

    expand step

    r 1 2

    3 4

    5 6

    7 8

    9 10 11

    Augmenting path!

  • 8/3/2019 43_pges_maximum matching algorithm

    15/43

    Algorithm: Search for an Augmenting Path

    let r be the only vertex of T

    while no edge uv with u+ T and v+ / T exists {

    if an edge uv with u+ T and v / T exists:grow step

    else if an edge uv with u+ T and v+ T exists:

    shrink step

    else terminate,

    T is abandoned since no augmenting path

    for r exists}

    an edge uv with u+ T and v+ / T exists

    expand step augmenting path.

  • 8/3/2019 43_pges_maximum matching algorithm

    16/43

    Algorithm: Maximum Cardinality Matching

    M: Abitrary matching in G

    label all free vertices even, unlabel all matched vertices

    for each vertex r in G {

    if r is matched continue with an other vertexsearch for an augmenting path

    if an augmenting path has been found {

    augment M = M P

    unlabel all vertices contained in T

    delete all blossoms of T

    destroy T

    }

    else T has been abandoned

    continue with another vertex

    }

    M is a maximum cardinality matching

  • 8/3/2019 43_pges_maximum matching algorithm

    17/43

    Linear programming

    Primal Problem:

    Maximizeq

    j=1

    cjxj

    subject toq

    j=1

    aijxj b(i) for all i = 1, . . . , p ,

    xj 0 for all j = 1, . . . , q .

    Dual Problem:

    Minimizep1=1

    b(i)(i)

    subject topi=1

    aij(i) cj for all j = 1, . . . , q ,

    (i) 0 for all i = 1, . . . , p .

    Complementary Slackness Conditions: A pair (x, ) of

    the primal and dual feasible solutions are optimal, if

    they satisfy the following conditions:

    (i) b(i) q

    j=1

    aijxj = 0 for each i = 1, . . . , p .xj

    p

    i=1

    aij(i) cj

    = 0 for each j = 1, . . . , q .

  • 8/3/2019 43_pges_maximum matching algorithm

    18/43

    Linear programming (Example)Maximize 200x1 + 400x2

    subject to 1/40x1 + 1/60x2 11/50x1 + 1/50x2 1xi 0 i = 1, 2

    x2

    x1

    Feasible Region

  • 8/3/2019 43_pges_maximum matching algorithm

    19/43

    LP Formulation of MWM (I)

    integer linear program:

    MaximizeeEw

    exe

    subject to

    e(u)

    xe 1 for all u V

    xe {0, 1} for all e E

    xe = 0 if e M1 ife M

    1 8r 2

    3 4

    5 6

    7

    9

    3224

    28

    24

    28

    28

    16

    20

    24

    28

    we = w(u, v), xe = x(u, v)

    w(r, 1) = 28, w(1, 2) = 32, . . .

    x(1, 2) = 1, x(3, 4) = 1, xe = 0 for the other edgeseE

    wexe = 60

  • 8/3/2019 43_pges_maximum matching algorithm

    20/43

    ad LP Formulation of MWM(II)

    Weighthed graph:

    1

    2 3

    4

    5

    2

    3

    3

    2

    2

    Optimal Solution of the integer linear program:edge 1 2 2 3 3 4 4 5 1 5xe 1 0 0 1 0

    eE

    wexe = 5

    1

    2 3

    4

    5

    2

    3

    3

    2

    2

    Optimal Solution of the linear programing relaxation:edge 1 2 2 3 3 4 4 5 1 5xe 0.5 0.5 0.5 0.5 0.5

    eE

    wexe = 6

  • 8/3/2019 43_pges_maximum matching algorithm

    21/43

    LP Formulation of MWM(II)

    integer linear program:

    MaximizeeE

    wexe

    subject to

    e(u)

    xe 1 for all u V

    xe {0, 1} for all e E

    linear programing relaxation:

    MaximizeeE

    wexe

    subject to

    e(u)

    xe 1 for all u V

    xe 0 for all e E

    linear program:

    MaximizeeE

    wexe

    subject to

    e(u)

    xe 1 for all u Ve(B)

    xe |B|/2 for all B O

    xe 0 for all e E

    O = {B V : |B| is odd and |B| 3}

  • 8/3/2019 43_pges_maximum matching algorithm

    22/43

    More Definitions

    (S) = {uv E : u S and v S}

    (S) = {uv E : u S and v S}

    1

    5

    23

    4

    6

    7

    B

    8

    (S) = {(3, 7), (4, 6)}

    (S) = {(1, 2), (2, 3), (3, 4), (4, 5), (1, 5)}

  • 8/3/2019 43_pges_maximum matching algorithm

    23/43

    Primal-Dual Method for MWM

    Primal:

    Maximize uvE

    wuvxuv

    subject to

    uv(u)

    xuv 1 for all u Vuv(B)

    xuv |B|/2 for all B O

    xuv 0 for all uv E

    Dual:

    MinimizeuV

    yu +BO

    |B|/2zB

    subject to yu 0 for all u V

    zB 0 for all B O

    yu + yv+

    BOuv(B)

    zB wuv for all uv E

    Complementary Slackness Conditions:

    xuv > 0 = uv = 0 for all uv E

    yu > 0 =

    uv(u)

    xuv = 1 for all u V

    zB > 0 = uv(B)

    xuv = |B|/2 for all B O

    Reduced Cost: uv = yu + yv wuv +BO

    uv(B)

    zB

  • 8/3/2019 43_pges_maximum matching algorithm

    24/43

    Initial Solution

    xe = 0 for each edge e E(M = )

    yu = max{we/2 : e (u)} for each vertex u V

    zB = 0 for each B O

    Feasible Solution of the Primal:

    (P1)

    uv(u)

    xuv 1 for all u V

    (P2) uv(B)

    xuv |B|/2 for all B O

    (P3) xuv 0 for all uv E

    Feasible Solution of the Dual:

    (D1) yu 0 for all u V

    (D2) zB 0 for all B O

    (D3) yu + yv+BO

    uv(B)

    zB wuv for all uv E

    Complementary Slackness Conditions:

    (CS1) xuv > 0 = uv = 0 for all uv E

    (CS2) yu > 0 =

    uv(u)xuv = 1 for all u V

    (CS3) zB > 0 =

    uv(B)

    xuv = |B|/2 for all B O

  • 8/3/2019 43_pges_maximum matching algorithm

    25/43

    Reducing Violations of CS 2

    CS 2: yu > 0 = uv(u)

    xuv = 1 for all u V

    Let r be a vertex that violates CS 2

    (i.e. r is unmatched and yr > 0.)

    match r

    or

    adjust the dual solution (y, z) such that y = 0

  • 8/3/2019 43_pges_maximum matching algorithm

    26/43

    Matching a free vertex r

    Search for an augmenting path, but only use tight

    edges (where uv = yu + yv wuv +

    BOuv(B)

    zB = 0).

    Otherwise CS 1 ( xuv > 0 = uv = 0 ) would be

    violated.

    case 1: found an augmenting path

    augment

    case 2: T is abandoned (no further thight edges are

    incident to any vertex u+ T)

    dual adjustment

  • 8/3/2019 43_pges_maximum matching algorithm

    27/43

    Requirements to the Dual Adjustment

    The dual solution (y, z) gets adjusted to (y, z) such

    that

    R1: the objective value (uV

    yu +BO

    |B|/2zB) of the

    dual problem strictly decreases

    R2: the solutions are still feasible to the Primal

    R3: the solutions are still feasible to the Dual

    R4: (CS1) and (CS3) remain true for (y, z)

    R5: yr strictly decreases

  • 8/3/2019 43_pges_maximum matching algorithm

    28/43

    Performing a Dual Adjustment

    > 0

    yv = yv for all v+ T,

    yv = yv + for all v T,

    yv = yv for all v{|+} / T,

    zB = zB + 2 for all B+ T,

    zB = zB 2 for all B T,

    zB = zB for all B{|+} / T,

    zB is only adjusted when B is a non-trivial surface

    blossom.

  • 8/3/2019 43_pges_maximum matching algorithm

    29/43

    Satisfaction of the Requirements (I)

    R1: the objective value (f = uV yu+ BO|B|/2zB) ofthe dual problem strictly decreases

    f = f f

    v+ T : fv+ =

    v T : fv =

    B+ T :

    fB+ = |B|()+|B|/2(2) = |B|+(|B|1) =

    B T :

    fB = |B| + |B|/2(2) = |B| (|B| 1) =

    n+ = n + 1

    f = n+() + n() =

    .

  • 8/3/2019 43_pges_maximum matching algorithm

    30/43

    Satisfaction of the Requirements (II)

    R2: the solutions are still feasible to the Primal

    x is not altered

    R3: the solutions are still feasible to the Dual

    restrictions on the value of :

    (D1) : yu 0 yu for all u+ T

    (D2) : zB 0 zB/2 for all B T

    .

  • 8/3/2019 43_pges_maximum matching algorithm

    31/43

    Satisfaction of the Requirements (III)

    (D3) : uv = yu + yv wuv +

    BOuv(B)

    zB 0

    e = uv : u T or v T

    Case 1: uv = yu + yv wuv 0 e / (B)

    Case 1a: u+ T and v T:

    yu = yu , yv = yv +

    uv = uv

    Case 1b: u+ T and v+ T:

    yu = yu , yv = yv

    uv = uv 2 uv/2

    Case 1c: u+ T and v{|+} / T:

    yu = yu , y

    v = yv

    uv = uv uv

    Case 1d: u T and v T:

    yu = yu + , yv = yv +

    uv = uv + 2

    Case 1e: u T and v{|+} / T:

    yu = yu + , yv = yv

    uv = uv +

  • 8/3/2019 43_pges_maximum matching algorithm

    32/43

    Satisfaction of the Requirements (IV)

    (D3) : uv = yu + yv wuv +

    BOuv(B)

    zB 0

    e = uv : u T or v T

    Case 2: e = uv (B)

    Case 2a: B+ T :

    yu = yu , yv = yv , z

    B = zB + 2

    uv = uv

    Case 2b: B T :

    yu = yu + , yv = yv + , z

    B = zB 2

    uv = uv

    .

  • 8/3/2019 43_pges_maximum matching algorithm

    33/43

    Satisfaction of the Requirements (V)

    R4: (CS1) and (CS3) remain true for (y, z)

    (CS1): xuv > 0 uv = 0

    uv = uv

    (CS3) : zB > 0 uv(B)

    xuv = |B|/2 for all B O

    R5: yr strictly decreases

    r+ T

    .

  • 8/3/2019 43_pges_maximum matching algorithm

    34/43

    Satisfaction of the Requirements (Summary)

    = min{1, 2, 3, 4, }, where

    1 = minuV {yu : u+

    T}2 = min

    uvE{uv : u+ T, v{|+} / T}

    3 = minuvE

    {uv/2 : u+ T, v+ T}

    4 = minBO

    {zB/2 : B T}

    Case = 1 : yu = 0, u+ T

    an even length alternating path p from u to r exists:

    match r by replacing M by M p

    Case = 2 : the responsible edge e = uv becomes

    tight and can be used to extend T

    Case = 3 : the responsible edge e = uv becomes

    tight and can be used to shrink a new blossom

    Case = 4 : zB of B will drop to zero, B cannot

    participate in another dual adjustment expand B

  • 8/3/2019 43_pges_maximum matching algorithm

    35/43

    Expand step for an odd Blossom

    B

    Bj

    +

    +

    2

    3 4

    6

    ru

    Bj

    +

    +

    +

    * *

    2

    3 4

    6

    r

    u

  • 8/3/2019 43_pges_maximum matching algorithm

    36/43

    MWM: Algorithm

    Initial Solution:

    let M be the empty matching

    yu = max{we/2 : e E} for each vertex u G

    label each vertex u g evenfor each vertex r G {

    if r is matched or yr = 0 continue

    let Br be the only blossom of T

    repeat {

    if an vertex u+ T with yu = 0 exists {let P be the alternating path from u to r

    replace M by m Pelse if an edge uv with u+ T and uv = 0

    exists {

    case v / T: grow stepcase v+ T: shrink stepcase v+ / T: augment step

    else if there exists an odd blossom B T

    with zB = 0

    expand step for B

    else {

    determine

    perform dual adjustment}

    } until r is matched or yr = 0

    }

  • 8/3/2019 43_pges_maximum matching algorithm

    37/43

    Example (I)

    Weighthed Graph:

    1 8r 2

    3 4

    5 6

    7

    9

    3224

    28

    24

    28

    28

    16

    20

    24

    28

    node u 1 2 3 4 5 6 7 8 9 ryu 16 16 14 14 14 14 10 10 12 14

    After 4 searches:

    * *

    * *

    * *

    * *

    +

    1 8r 2

    3 4

    5 6

    7

    9

    3224

    2428

    16

    24

    28

    28

    20

    28

    +

  • 8/3/2019 43_pges_maximum matching algorithm

    38/43

    Example (II)

    node u 1 2 3 4 5 6 7 8 9 ryu 16 16 14 14 14 14 10 10 12 14

    * *

    * *

    * *

    * *

    +

    1 8r 2

    3 4

    5 6

    7

    9

    3224

    24

    28

    16

    24

    28

    28

    20

    28

    +

    starting the search with r+ T

    (r+, 1) = 2

    no tight edges are incident to r+ dual adjustment

    1 = 14, 2 = 2, 3 = , 4 =

    = 2

  • 8/3/2019 43_pges_maximum matching algorithm

    39/43

    Example(III)

    yv = yv for all v+ T

    T = {r+

    } = 2

    node u 1 2 3 4 5 6 7 8 9 ryu 16 16 14 14 14 14 10 10 12 14yu 16 16 14 14 14 14 10 10 12 12

    edge (r, 1) becomes tight grow step

    *

    * *

    *

    *

    *

    +

    1 8r 2

    3 4

    5 6

    7

    9

    32

    24

    24

    28

    16

    24

    28

    28

    20

    28

    + +

    (2+, 3) = 6, (2+, 5) = 6

    no tight edges are incident to 2+

    dual adjustment1 = 12, 2 = 6, 3 = , 4 =

    = 6

  • 8/3/2019 43_pges_maximum matching algorithm

    40/43

    Example (IV)

    yv = yv for all v+ Tyv = yv + for all v

    T

    T = {r+, 1, 2+}

    = 6

    node u 1 2 3 4 5 6 7 8 9 ryu 16 16 14 14 14 14 10 10 12 12yu 22 10 14 14 14 14 10 10 12 6

    edge (2+, 3) becomes tight grow step

    edge (2+, 5) becomes tight grow step

    * *

    +

    1 8r 2

    3 4

    5 6

    7

    9

    32

    24

    24

    28

    16

    24

    28

    28

    20

    28

    + +

    +

    +

  • 8/3/2019 43_pges_maximum matching algorithm

    41/43

    Example (V)

    node u 1 2 3 4 5 6 7 8 9 ryu 22 10 14 14 14 14 10 10 12 6

    edge (4+, 6+) is thight shrink step

    +

    * *

    B(2)+

    9

    1 8r 2

    3 4

    5 6

    732

    24

    2428

    16

    28

    28

    20

    28

    + +

    +

    + +

    24

    +

    (5+, 9+) = 2, (6+, 7) = 8

    no tight edges are incident to (B(2))+ dual adjustment

    1 = 6, 2 = 2, 3 = , 4 =

    = 2

  • 8/3/2019 43_pges_maximum matching algorithm

    42/43

    Example (VI)

    yv = yv for all v+ T

    yv = yv + for all v T

    = 2

    node u 1 2 3 4 5 6 7 8 9 ryu 22 10 14 14 14 14 10 10 12 6yu 24 8 12 12 12 12 10 10 12 4

    zB = zB + 2 for all B+ T

    zB(B(2)) = 4

    edge (5+, 9+) is thight, 9+ / T augment step

    * *

    B(2)+

    +

    1 8r 2

    3 4

    5 6

    732

    24

    24 28

    16

    28

    28

    20

    28

    + +

    +

    + +

    24

    +

    9

    expand the blossom and find the even length alterna-

    ting path from vertex 5 to r:

  • 8/3/2019 43_pges_maximum matching algorithm

    43/43

    Example (VII)

    1 8r 2

    3 4

    5 6

    7

    9

    3224

    2428

    16

    24

    28

    28

    20

    28

    uvE

    wuvxuv = 108

    augment

    1 8r 2

    3 4

    5 6

    7

    9

    3224

    2428

    16

    24

    28

    28

    20

    28

    uvEwuvxuv = 124