chapter 6 graph algorithms - uni-freiburg.deac.informatik.uni-freiburg.de/teaching/ws18_19/...ย ยท...

Post on 05-Jul-2020

3 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Chapter 6

Graph Algorithms

Algorithm TheoryWS 2018/19

Fabian Kuhn

Algorithm Theory, WS 2018/19 Fabian Kuhn 2

Example: Flow Network

๐‘  ๐‘ก

๐‘ข

๐‘ฃ

20

20

10

10

30

Algorithm Theory, WS 2018/19 Fabian Kuhn 3

Network Flow: Definition

Flow: function ๐’‡: ๐‘ฌ โ†’ โ„โ‰ฅ๐ŸŽ

โ€ข ๐‘“(๐‘’) is the amount of flow carried by edge ๐‘’

Capacity Constraints:

โ€ข For each edge ๐‘’ โˆˆ ๐ธ, ๐‘“ ๐‘’ โ‰ค ๐‘๐‘’

Flow Conservation:

โ€ข For each node ๐‘ฃ โˆˆ ๐‘‰ โˆ– ๐‘ , ๐‘ก ,

๐‘’ into ๐‘ฃ

๐‘“ ๐‘’ =

๐‘’ out of ๐‘ฃ

๐‘“ ๐‘’

Flow Value:

|๐‘“| โ‰”

๐‘’ out of ๐‘ 

๐‘“ ๐‘ , ๐‘ข =

๐‘’ into ๐‘ก

๐‘“ ๐‘ฃ, ๐‘ก

Algorithm Theory, WS 2018/19 Fabian Kuhn 4

The Maximum-Flow Problem

Maximum Flow:

Given a flow network, find a flow of maximum possible value

โ€ข Classical graph optimization problem

โ€ข Many applications (also beyond the obvious ones)

โ€ข Requires new algorithmic techniques

Algorithm Theory, WS 2018/19 Fabian Kuhn 5

Residual Graph

Given a flow network ๐บ = ๐‘‰, ๐ธ with capacities ๐‘๐‘’ (for ๐‘’ โˆˆ ๐ธ)

For a flow ๐‘“ on ๐บ, define directed graph ๐บ๐‘“ = (๐‘‰๐‘“ , ๐ธ๐‘“) as follows:

โ€ข Node set ๐‘‰๐‘“ = ๐‘‰

โ€ข For each edge ๐‘’ = (๐‘ข, ๐‘ฃ) in ๐ธ, there are two edges in ๐ธ๐‘“:

โ€“ forward edge ๐‘’ = (๐‘ข, ๐‘ฃ) with residual capacity ๐‘๐‘’ โˆ’ ๐‘“(๐‘’)

โ€“ backward edge ๐‘’โ€ฒ = (๐‘ฃ, ๐‘ข) with residual capacity ๐‘“(๐‘’)

๐‘  ๐‘ก

๐‘ข

๐‘ฃ

20

20

10

10

30

๐Ÿ๐ŸŽ

๐Ÿ๐ŸŽ

๐Ÿ๐ŸŽ

Algorithm Theory, WS 2018/19 Fabian Kuhn 6

Residual Graph: Example

๐‘ 

๐‘ฅ

๐‘ข

๐‘ฆ

๐‘ฃ

๐‘ค

๐‘ž

๐‘ง

๐‘ก

1520

20

15

10

10

20

15

20

15

15

15

10

5

20

20

Algorithm Theory, WS 2018/19 Fabian Kuhn 7

Residual Graph: Example

Flow ๐’‡

๐‘ 

๐‘ฅ

๐‘ข

๐‘ฆ

๐‘ฃ

๐‘ค

๐‘ž

๐‘ง

๐‘ก

1520

20

15

10

10

20

15

20

15

15

15

10

5

20

20๐Ÿ๐ŸŽ

๐Ÿ“

๐Ÿ๐ŸŽ

๐Ÿ“

๐Ÿ๐Ÿ“

๐Ÿ“

๐Ÿ๐ŸŽ

๐Ÿ๐ŸŽ

๐Ÿ๐ŸŽ

๐Ÿ๐ŸŽ

๐Ÿ๐ŸŽ

๐Ÿ๐ŸŽ

๐Ÿ๐ŸŽ

๐Ÿ๐ŸŽ

510 15

5

0

15

Algorithm Theory, WS 2018/19 Fabian Kuhn 8

Residual Graph: Example

Residual Graph ๐‘ฎ๐’‡

๐‘ 

๐‘ฅ

๐‘ข

๐‘ฆ

๐‘ฃ

๐‘ค

๐‘ž

๐‘ง

๐‘ก

510 15

5

0

15

100

0 5

0

1015

15

0

10

10

05

20

10

10

10

1010 10

10

10

0

5 5

5

Algorithm Theory, WS 2018/19 Fabian Kuhn 9

Augmenting Path

Residual Graph ๐‘ฎ๐’‡

๐‘ 

๐‘ฅ

๐‘ข

๐‘ฆ

๐‘ฃ

๐‘ค

๐‘ž

๐‘ง

๐‘ก

510 ๐Ÿ๐Ÿ“

5

0

15

๐Ÿ๐ŸŽ0

0 5

0

10๐Ÿ๐Ÿ“

๐Ÿ๐Ÿ“

0

10

10

05

20

๐Ÿ๐ŸŽ

10

10

1010 10

10

๐Ÿ๐ŸŽ

0

5 5

5

Algorithm Theory, WS 2018/19 Fabian Kuhn 10

Augmenting Path

Augmenting Path

๐‘ 

๐‘ฅ

๐‘ข

๐‘ฆ

๐‘ฃ

๐‘ค

๐‘ž

๐‘ง

๐‘ก

1520

20

15

10

10

20

15

20

15

15

15

10

5

20

20๐Ÿ๐ŸŽ

๐Ÿ“

๐Ÿ๐ŸŽ

๐Ÿ“

๐Ÿ๐Ÿ“

๐Ÿ“

๐Ÿ๐ŸŽ

๐Ÿ๐ŸŽ

๐Ÿ๐ŸŽ

๐Ÿ๐ŸŽ

๐Ÿ๐ŸŽ

๐Ÿ๐ŸŽ

๐Ÿ๐ŸŽ

๐Ÿ๐ŸŽ

Algorithm Theory, WS 2018/19 Fabian Kuhn 11

Augmenting Path

New Flow

๐‘ 

๐‘ฅ

๐‘ข

๐‘ฆ

๐‘ฃ

๐‘ค

๐‘ž

๐‘ง

๐‘ก

1520

20

15

10

10

20

15

20

15

15

15

10

5

20

20๐Ÿ๐ŸŽ

๐Ÿ“ + ๐Ÿ๐ŸŽ

๐Ÿ๐ŸŽ โˆ’ ๐Ÿ๐ŸŽ

๐Ÿ“ + ๐Ÿ๐ŸŽ

๐Ÿ๐Ÿ“

๐Ÿ“

๐Ÿ๐ŸŽ

๐Ÿ๐ŸŽ + ๐Ÿ๐ŸŽ

๐Ÿ๐ŸŽ

๐Ÿ๐ŸŽ

๐Ÿ๐ŸŽ

๐Ÿ๐ŸŽ โˆ’ ๐Ÿ๐ŸŽ

๐Ÿ๐ŸŽ

๐Ÿ๐ŸŽ

๐ŸŽ + ๐Ÿ๐ŸŽ

Algorithm Theory, WS 2018/19 Fabian Kuhn 12

Augmenting Path

Definition:An augmenting path ๐‘ƒ is a (simple) ๐‘ -๐‘ก-path on the residual graph ๐บ๐‘“ on which each edge has residual capacity > 0.

bottleneck(๐‘ƒ, ๐‘“): minimum residual capacity on any edge of theaugmenting path ๐‘ƒ

Augment flow ๐’‡ to get flow ๐’‡โ€ฒ:

โ€ข For every forward edge (๐‘ข, ๐‘ฃ) on ๐‘ƒ:

๐’‡โ€ฒ ๐’–, ๐’— โ‰” ๐’‡ ๐’–, ๐’— + ๐›๐จ๐ญ๐ญ๐ฅ๐ž๐ง๐ž๐œ๐ค ๐‘ท, ๐’‡

โ€ข For every backward edge (๐‘ข, ๐‘ฃ) on ๐‘ƒ:

๐’‡โ€ฒ ๐’—, ๐’– โ‰” ๐’‡ ๐’—, ๐’– โˆ’ ๐›๐จ๐ญ๐ญ๐ฅ๐ž๐ง๐ž๐œ๐ค(๐‘ท, ๐’‡)

Algorithm Theory, WS 2018/19 Fabian Kuhn 13

Augmented Flow

Lemma: Given a flow ๐‘“ and an augmenting path ๐‘ƒ, the resulting augmented flow ๐‘“โ€ฒ is legal and its value is

๐’‡โ€ฒ = ๐’‡ + ๐›๐จ๐ญ๐ญ๐ฅ๐ž๐ง๐ž๐œ๐ค ๐‘ท, ๐’‡ .

Proof:

Algorithm Theory, WS 2018/19 Fabian Kuhn 14

Augmented Flow

Lemma: Given a flow ๐‘“ and an augmenting path ๐‘ƒ, the resulting augmented flow ๐‘“โ€ฒ is legal and its value is

๐’‡โ€ฒ = ๐’‡ + ๐›๐จ๐ญ๐ญ๐ฅ๐ž๐ง๐ž๐œ๐ค ๐‘ท, ๐’‡ .

Proof:

Algorithm Theory, WS 2018/19 Fabian Kuhn 15

Ford-Fulkerson Algorithm

โ€ข Improve flow using an augmenting path as long as possible:

1. Initially, ๐‘“ ๐‘’ = 0 for all edges ๐‘’ โˆˆ ๐ธ, ๐บ๐‘“ = ๐บ

2. while there is an augmenting ๐‘ -๐‘ก-path ๐‘ƒ in ๐บ๐‘“ do

3. Let ๐‘ƒ be an augmenting ๐‘ -๐‘ก-path in ๐บ๐‘“;

4. ๐‘“โ€ฒ โ‰” augment(๐‘“, ๐‘ƒ);

5. update ๐‘“ to be ๐‘“โ€ฒ;

6. update the residual graph ๐บ๐‘“

7. end;

Algorithm Theory, WS 2018/19 Fabian Kuhn 16

Ford-Fulkerson Running Time

Theorem: If all edge capacities are integers, the Ford-Fulkerson algorithm terminates after at most ๐ถ iterations, where

๐ถ = "max flow value" โ‰ค

๐‘’ out of ๐‘ 

๐‘๐‘’ .

Proof:

Algorithm Theory, WS 2018/19 Fabian Kuhn 17

Ford-Fulkerson Running Time

Theorem: If all edge capacities are integers, the Ford-Fulkerson algorithm can be implemented to run in ๐‘‚(๐‘š๐ถ) time.

Proof:

Algorithm Theory, WS 2018/19 Fabian Kuhn 18

๐‘ -๐‘ก Cuts

Definition:An ๐‘ -๐‘ก cut is a partition (๐ด, ๐ต) of the vertex set such that ๐‘  โˆˆ ๐ดand ๐‘ก โˆˆ ๐ต

๐‘ 

๐‘ฅ

๐‘ข

๐‘ฆ

๐‘ฃ

๐‘ค

๐‘ž

๐‘ง

๐‘ก

1520

20

15

10

10

20

15

20

15

15

15

10

5

20

20

๐‘จ

๐‘ฉ

Algorithm Theory, WS 2018/19 Fabian Kuhn 19

Cut Capacity

Definition:The capacity ๐‘ ๐ด, ๐ต of an ๐‘ -๐‘ก-cut (๐ด, ๐ต) is defined as

๐’„ ๐‘จ,๐‘ฉ โ‰”

๐’† ๐จ๐ฎ๐ญ ๐จ๐Ÿ ๐‘จ

๐’„๐’† .

๐‘ 

๐‘ฅ

๐‘ข

๐‘ฆ

๐‘ฃ

๐‘ค

๐‘ž

๐‘ง

๐‘ก

1520

20

15

10

10

20

๐Ÿ๐Ÿ“

20

15

15

15

10

๐Ÿ“

๐Ÿ๐ŸŽ

๐Ÿ๐ŸŽ

๐‘จ

๐‘ฉ

Algorithm Theory, WS 2018/19 Fabian Kuhn 20

Cuts and Flow Value

Lemma: Let ๐‘“ be any ๐‘ -๐‘ก flow, and (๐ด, ๐ต) any ๐‘ -๐‘ก cut. Then,

๐’‡ = ๐’‡๐จ๐ฎ๐ญ ๐‘จ โˆ’ ๐’‡๐ข๐ง ๐‘จ .

Proof:

Algorithm Theory, WS 2018/19 Fabian Kuhn 21

Cuts and Flow Value

Lemma: Let ๐‘“ be any ๐‘ -๐‘ก flow, and (๐ด, ๐ต) any ๐‘ -๐‘ก cut. Then,

๐’‡ = ๐’‡๐จ๐ฎ๐ญ ๐‘จ โˆ’ ๐’‡๐ข๐ง ๐‘จ .

Lemma: Let ๐‘“ be any ๐‘ -๐‘ก flow, and (๐ด, ๐ต) any ๐‘ -๐‘ก cut. Then,

๐’‡ = ๐’‡๐ข๐ง ๐‘ฉ โˆ’ ๐’‡๐จ๐ฎ๐ญ ๐‘ฉ .

Proof:

Algorithm Theory, WS 2018/19 Fabian Kuhn 22

Upper Bound on Flow Value

Lemma:

Let ๐‘“ be any ๐‘ -๐‘ก flow and (๐ด, ๐ต) any ๐‘ -๐‘ก cut. Then ๐’‡ โ‰ค ๐’„(๐‘จ,๐‘ฉ).

Proof:

Algorithm Theory, WS 2018/19 Fabian Kuhn 23

Ford-Fulkerson Gives Optimal Solution

Lemma: If ๐‘“ is an ๐‘ -๐‘ก flow such that there is no augmenting path in ๐บ๐‘“, then there is an ๐‘ -๐‘ก cut (๐ดโˆ—, ๐ตโˆ—) in ๐บ for which

๐’‡ = ๐’„ ๐‘จโˆ—, ๐‘ฉโˆ— .

Proof:

โ€ข Define ๐‘จโˆ—: set of nodes that can be reached from ๐‘  on a path with positive residual capacities in ๐บ๐‘“:

โ€ข For ๐ตโˆ— = ๐‘‰ โˆ– ๐ดโˆ—, (๐ดโˆ—, ๐ตโˆ—) is an ๐‘ -๐‘ก cutโ€“ By definition ๐‘  โˆˆ ๐ดโˆ— and ๐‘ก โˆ‰ ๐ดโˆ—

Algorithm Theory, WS 2018/19 Fabian Kuhn 24

Ford-Fulkerson Gives Optimal Solution

Lemma: If ๐‘“ is an ๐‘ -๐‘ก flow such that there is no augmenting path in ๐บ๐‘“, then there is an ๐‘ -๐‘ก cut (๐ดโˆ—, ๐ตโˆ—) in ๐บ for which

๐’‡ = ๐’„ ๐‘จโˆ—, ๐‘ฉโˆ— .

Proof:

Algorithm Theory, WS 2018/19 Fabian Kuhn 25

Ford-Fulkerson Gives Optimal Solution

Lemma: If ๐‘“ is an ๐‘ -๐‘ก flow such that there is no augmenting path in ๐บ๐‘“, then there is an ๐‘ -๐‘ก cut (๐ดโˆ—, ๐ตโˆ—) in ๐บ for which

๐’‡ = ๐’„ ๐‘จโˆ—, ๐‘ฉโˆ— .

Proof:

Algorithm Theory, WS 2018/19 Fabian Kuhn 26

Ford-Fulkerson Gives Optimal Solution

Theorem: The flow returned by the Ford-Fulkerson algorithm is a maximum flow.

Proof:

Algorithm Theory, WS 2018/19 Fabian Kuhn 27

Min-Cut Algorithm

Ford-Fulkerson also gives a min-cut algorithm:

Theorem: Given a flow ๐‘“ of maximum value, we can compute an ๐‘ -๐‘ก cut of minimum capacity in ๐‘‚(๐‘š) time.

Proof:

Algorithm Theory, WS 2018/19 Fabian Kuhn 28

Max-Flow Min-Cut Theorem

Theorem: (Max-Flow Min-Cut Theorem)

In every flow network, the maximum value of an ๐‘ -๐‘ก flow is equal to the minimum capacity of an ๐‘ -๐‘ก cut.

Proof:

Algorithm Theory, WS 2018/19 Fabian Kuhn 29

Integer Capacities

Theorem: (Integer-Valued Flows)

If all capacities in the flow network are integers, then there is a maximum flow ๐‘“ for which the flow ๐‘“ ๐‘’ of every edge ๐‘’ is an integer.

Proof:

Algorithm Theory, WS 2018/19 Fabian Kuhn 30

Non-Integer Capacities

What if capacities are not integers?

โ€ข rational capacities:โ€“ can be turned into integers by multiplying them with large enough integer

โ€“ algorithm still works correctly

โ€ข real (non-rational) capacities:โ€“ not clear whether the algorithm always terminates

โ€ข even for integer capacities, time can linearly depend on the value of the maximum flow

Algorithm Theory, WS 2018/19 Fabian Kuhn 31

Slow Execution

โ€ข Number of iterations: 2000 (value of max. flow)

๐‘  ๐‘ก

๐‘ข

๐‘ฃ

1000

1000

1000

1000

1

๐Ÿ

๐Ÿ

๐Ÿ

๐Ÿ

๐Ÿ

๐ŸŽ

๐Ÿ๐Ÿ

๐Ÿ ๐Ÿ

Algorithm Theory, WS 2018/19 Fabian Kuhn 32

Improved Algorithm

Idea: Find the best augmenting path in each step

โ€ข best: path ๐‘ƒ with maximum bottleneck(๐‘ƒ, ๐‘“)

โ€ข Best path might be rather expensive to find find almost best path

โ€ข Scaling parameter ๐šซ: (initially, ฮ” = "max ๐‘๐‘’ rounded down to next power of 2")

โ€ข As long as there is an augmenting path that improves the flow by at least ฮ”, augment using such a path

โ€ข If there is no such path: ฮ” โ‰” ฮคฮ” 2

Algorithm Theory, WS 2018/19 Fabian Kuhn 33

Scaling Parameter Analysis

Lemma: If all capacities are integers, number of different scaling parameters used is โ‰ค 1 + โŒŠlog2 ๐ถโŒ‹.

โ€ข ๐šซ-scaling phase: Time during which scaling parameter is ฮ”

Algorithm Theory, WS 2018/19 Fabian Kuhn 34

Length of a Scaling Phase

Lemma: If ๐‘“ is the flow at the end of the ฮ”-scaling phase, the maximum flow in the network has value at most ๐‘“ + ๐‘šฮ”.

Algorithm Theory, WS 2018/19 Fabian Kuhn 35

Length of a Scaling Phase

Lemma: The number of augmentation in each scaling phase is at most 2๐‘š.

Algorithm Theory, WS 2018/19 Fabian Kuhn 36

Running Time: Scaling Max Flow Alg.

Theorem: The number of augmentations of the algorithm with scaling parameter and integer capacities is at most ๐‘‚(๐‘š log ๐ถ). The algorithm can be implemented in time ๐‘‚ ๐‘š2 log ๐ถ .

Algorithm Theory, WS 2018/19 Fabian Kuhn 37

Strongly Polynomial Algorithm

โ€ข Time of regular Ford-Fulkerson algorithm with integer capacities:

๐‘‚(๐‘š๐ถ)

โ€ข Time of algorithm with scaling parameter:

๐‘‚ ๐‘š2log ๐ถ

โ€ข ๐‘‚(log ๐ถ) is polynomial in the size of the input, but not in ๐‘›

โ€ข Can we get an algorithm that runs in time polynomial in ๐‘›?

โ€ข Always picking a shortest augmenting path leads to running time

๐‘‚ ๐‘š2๐‘›

โ€“ also works for arbitrary real-valued weights

Algorithm Theory, WS 2018/19 Fabian Kuhn 38

Other Algorithms

โ€ข There are many other algorithms to solve the maximum flow problem, for example:

โ€ข Preflow-push algorithm:โ€“ Maintains a preflow (โˆ€ nodes: inflow โ‰ฅ outflow)

โ€“ Alg. guarantees: As soon as we have a flow, it is optimal

โ€“ Detailed discussion in 2012/13 lecture

โ€“ Running time of basic algorithm: ๐‘‚ ๐‘š โ‹… ๐‘›2

โ€“ Doing steps in the โ€œrightโ€ order: ๐‘‚ ๐‘›3

โ€ข Current best known complexity: ๐‘ถ ๐’Ž โ‹… ๐’โ€“ For graphs with ๐‘š โ‰ฅ ๐‘›1+๐œ– [King,Rao,Tarjan 1992/1994]

(for every constant ๐œ– > 0)

โ€“ For sparse graphs with ๐‘š โ‰ค ๐‘› ฮค16 15โˆ’๐›ฟ [Orlin, 2013]

top related