Эффективные алгоритмы, осень 2007: Нахождение максимального потока

Embed Size (px)

Text of Эффективные алгоритмы, осень 2007: Нахождение...

  • / 18:

    .

    Computer Science http://logic.pdmi.ras.ru/infclub/

    . (CS ) 18. 1 / 43

    http://logic.pdmi.ras.ru/~infclub/

  • 1

    2 -

    3

    4 ---

    . (CS ) 18. 2 / 43

  • 1

    2 -

    3

    4 ---

    . (CS ) 18. 2 / 43

  • 1

    2 -

    3

    4 ---

    . (CS ) 18. 2 / 43

  • 1

    2 -

    3

    4 ---

    . (CS ) 18. 2 / 43

  • 1

    2 -

    3

    4 ---

    . (CS ) 18. 3 / 43

  • (flow network) , (u, v) c(u, v)( (u, v) E , c(u, v) = 0), (capacity), , s (source) t (sink). (flow) G = (V ,E ) f : V V R, :

    I : u, v V , f (u, v) c(u, v);I : u, v V , f (u, v) = f (v , u);I : u V {s, t},

    vV f (u, v) = 0.

    (value)

    vV f (s, v). (maximum flow-problem) .

    . (CS ) 18. 4 / 43

  • (flow network) , (u, v) c(u, v)( (u, v) E , c(u, v) = 0), (capacity), , s (source) t (sink).

    (flow) G = (V ,E ) f : V V R, :

    I : u, v V , f (u, v) c(u, v);I : u, v V , f (u, v) = f (v , u);I : u V {s, t},

    vV f (u, v) = 0.

    (value)

    vV f (s, v). (maximum flow-problem) .

    . (CS ) 18. 4 / 43

  • (flow network) , (u, v) c(u, v)( (u, v) E , c(u, v) = 0), (capacity), , s (source) t (sink). (flow) G = (V ,E ) f : V V R, :

    I : u, v V , f (u, v) c(u, v);I : u, v V , f (u, v) = f (v , u);I : u V {s, t},

    vV f (u, v) = 0.

    (value)

    vV f (s, v). (maximum flow-problem) .

    . (CS ) 18. 4 / 43

  • (flow network) , (u, v) c(u, v)( (u, v) E , c(u, v) = 0), (capacity), , s (source) t (sink). (flow) G = (V ,E ) f : V V R, :

    I : u, v V , f (u, v) c(u, v);

    I : u, v V , f (u, v) = f (v , u);I : u V {s, t},

    vV f (u, v) = 0.

    (value)

    vV f (s, v). (maximum flow-problem) .

    . (CS ) 18. 4 / 43

  • (flow network) , (u, v) c(u, v)( (u, v) E , c(u, v) = 0), (capacity), , s (source) t (sink). (flow) G = (V ,E ) f : V V R, :

    I : u, v V , f (u, v) c(u, v);I : u, v V , f (u, v) = f (v , u);

    I : u V {s, t},

    vV f (u, v) = 0.

    (value)

    vV f (s, v). (maximum flow-problem) .

    . (CS ) 18. 4 / 43

  • (flow network) , (u, v) c(u, v)( (u, v) E , c(u, v) = 0), (capacity), , s (source) t (sink). (flow) G = (V ,E ) f : V V R, :

    I : u, v V , f (u, v) c(u, v);I : u, v V , f (u, v) = f (v , u);I : u V {s, t},

    vV f (u, v) = 0.

    (value)

    vV f (s, v). (maximum flow-problem) .

    . (CS ) 18. 4 / 43

  • (flow network) , (u, v) c(u, v)( (u, v) E , c(u, v) = 0), (capacity), , s (source) t (sink). (flow) G = (V ,E ) f : V V R, :

    I : u, v V , f (u, v) c(u, v);I : u, v V , f (u, v) = f (v , u);I : u V {s, t},

    vV f (u, v) = 0.

    (value)

    vV f (s, v).

    (maximum flow-problem) .

    . (CS ) 18. 4 / 43

  • (flow network) , (u, v) c(u, v)( (u, v) E , c(u, v) = 0), (capacity), , s (source) t (sink). (flow) G = (V ,E ) f : V V R, :

    I : u, v V , f (u, v) c(u, v);I : u, v V , f (u, v) = f (v , u);I : u V {s, t},

    vV f (u, v) = 0.

    (value)

    vV f (s, v). (maximum flow-problem) .

    . (CS ) 18. 4 / 43

  • 3 10

    3

    4

    5

    2

    1

    11

    2

    5

    2 0

    1

    4

    5

    2

    1

    01

    2

    5

    . (CS ) 18. 5 / 43

  • . ( , , , ). , , (multicommodity flow).

    . (CS ) 18. 6 / 43

  • .

    ( , , , ). , , (multicommodity flow).

    . (CS ) 18. 6 / 43

  • . ( , , , ).

    , , (multicommodity flow).

    . (CS ) 18. 6 / 43

  • . ( , , , ). , , (multicommodity flow).

    . (CS ) 18. 6 / 43

  • 1

    2 -

    3

    4 ---

    . (CS ) 18. 7 / 43

  • -

    Ford-Fulkerson-Method(G , s, t)1 f 02 while p3 do f p4 return f

    . (CS ) 18. 8 / 43

  • G f .

    u v (residual capacity of(u, v)) cf (u, v) = c(u, v) f (u, v). (residual network) G , f , Gf = (V ,Ef ),

    Ef = {(u, v) V V : cf (u, v) > 0}.

    cf (u, v) c(u, v). .

    . (CS ) 18. 9 / 43

  • G f .

    u v (residual capacity of(u, v)) cf (u, v) = c(u, v) f (u, v).

    (residual network) G , f , Gf = (V ,Ef ),

    Ef = {(u, v) V V : cf (u, v) > 0}.

    cf (u, v) c(u, v). .

    . (CS ) 18. 9 / 43

  • G f .

    u v (residual capacity of(u, v)) cf (u, v) = c(u, v) f (u, v). (residual network) G , f , Gf = (V ,Ef ),

    Ef = {(u, v) V V : cf (u, v) > 0}.

    cf (u, v) c(u, v). .

    . (CS ) 18. 9 / 43

  • G f .

    u v (residual capacity of(u, v)) cf (u, v) = c(u, v) f (u, v). (residual network) G , f , Gf = (V ,Ef ),

    Ef = {(u, v) V V : cf (u, v) > 0}.

    cf (u, v) c(u, v). .

    . (CS ) 18. 9 / 43

  • G f .

    u v (residual capacity of(u, v)) cf (u, v) = c(u, v) f (u, v). (residual network) G , f , Gf = (V ,Ef ),

    Ef = {(u, v) V V : cf (u, v) > 0}.

    cf (u, v) c(u, v).

    .

    . (CS ) 18. 9 / 43

  • G f .

    u v (residual capacity of(u, v)) cf (u, v) = c(u, v) f (u, v). (residual network) G , f , Gf = (V ,Ef ),

    Ef = {(u, v) V V : cf (u, v) > 0}.

    cf (u, v) c(u, v). .

    . (CS ) 18. 9 / 43

  • (augmenting path) Gf . p(residual capacity of f ) , p: cf (p) = min{cf (u, v) : (u, v) p}.

    , .

    . (CS ) 18. 10 / 43

  • (augmenting path) Gf .

    p(residual capacity of f ) , p: cf (p) = min{cf (u, v) : (u, v) p}.

    , .

    . (CS ) 18. 10 / 43

  • (augmenting path) Gf . p(residual capacity of f ) , p: cf (p) = min{cf (u, v) : (u, v) p}.

    , .

    . (CS ) 18. 10 / 43

  • (augmenting path) Gf . p(residual capacity of f ) , p: cf (p) = min{cf (u, v) : (u, v) p}.

    , .

    . (CS ) 18. 10 / 43

  • (cut) S T = V S , s S t T . (cut capacity) S T . (cut flow) , . (minimum cut) .

    , .

    . (CS ) 18. 11 / 43

  • (cut) S T = V S , s S t T .

    (cut capacity) S T . (cut flow) , . (minimum cut) .

    , .

    . (CS ) 18. 11 / 43

  • (cut) S T = V S , s S t T . (cut capacity) S T .

    (cut flow) , . (minimum cut) .

    , .

    . (CS ) 18. 11 / 43

  • (cut) S T = V S , s S t T . (cut capacity) S T . (cut flow) , .

    (minimum cut) .

    , .

    . (CS ) 18. 11 / 43

  • (cut) S T = V S , s S t T . (cut capacity) S T . (cut flow) , . (minimum cut) .

    , .

    . (CS ) 18. 11 / 43

  • (cut) S T = V S , s S t T . (cut capacity) S T . (cut flow) , . (minimum cut) .

    , .

    . (CS ) 18. 11 / 43

  • 3 10

    3

    4

    5

    2

    1

    11

    2

    5

    . (CS ) 18. 12 / 43

  • f G . :

    1 f .2 Gf .3 (S ,T ), |f | = c(S ,T ).

    :

    1 2: , .2 3: , S

    , s .3 1:

    .

    . (CS ) 18. 13 / 43

  • f G . :

    1 f .

    2 Gf .3 (S ,T ), |f | = c(S ,T ).

    :

    1 2: , .2 3: , S

    , s .3 1:

    .

    . (CS ) 18. 13 / 43

  • f G . :

    1 f .2 Gf .

    3 (S ,T ), |f | = c(S ,T ).

    :

    1 2: , .2 3: , S

    , s .3 1:

    .

    . (CS ) 18. 13 / 43

  • f G . :

    1 f .2 Gf .3 (S ,T ), |f | = c(S ,T ).

    :

    1 2: , .2 3: , S

    , s .3 1:

    .

    . (CS ) 18. 13 / 43

  • f G . :

    1 f .2 Gf .3 (S ,T ), |f | = c(S ,T ).

    :

    1 2: , .2 3: , S

    , s .3 1:

    .

    . (CS ) 18. 13 / 43

  • f G . :

    1 f .2 Gf .3 (S ,T ), |f | = c(S ,T ).

    :

    1 2: , .

    2 3: , S , s .

    3 1: .

    . (CS ) 18. 13 / 43

  • f G . :

    1 f .2 Gf .3 (S ,T ), |f | = c(S ,T ).

    :

    1 2: , .2 3: , S

    , s .

    3 1: .

    . (CS ) 18. 13 / 43

  • f G . :

    1 f .2 Gf .3 (S ,T ), |f | = c(S ,T ).

    :

    1 2: , .2 3: , S

    , s .3 1:

    .

    . (CS ) 18. 13 / 43

  • -

    Ford-Fulkerson(G , s, t)1 for (u, v) E2 do f [u, v ] 03 f [v , u] 04 while Gf p s t5 do cf (p) min{cf (u, v) : (u, v) p}6 for (u, v) p7 do f [u, v ] f [u,