COMP 2711H: Lecture 19
Date: 2024-10-14 22:27:53
Reviewed:
Topic / Chapter:
summary
βQuestions
Notes
Network Flow and Ford-Fulkerson Algorithm
-
Matching (cont.)
- design an algorithm giving a maximum matching
- pick any trivial matching: empty or maximal matching
- if it's not a maximum: search for an augmented path
- while such path exists: expand the matching
- finally, if no augmented path can be found
- it's a maximum matching
- similar technique: starting with suboptimal solution
- and keep improving the method
- π¨βπ« still "augmented"
- until it can't be further improved
- theorem: if it can't be further improved => it's optimal
- and keep improving the method
- design an algorithm giving a maximum matching
-
Network flow
- problem of interest: network flow
- directed graph
- w/ capacity function
- claim: there are two special vertices
- source and sink
- example
graph LR a((a)) b((b)) c((c)) d((d)) a--4-->b a--5-->c b--6-->d b--1-->c c--5-->d
- source: <span class="katex"><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.4306em;"></span><span class="mord mathnormal">a</span></span></span></span>
- sink: <span class="katex"><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6944em;"></span><span class="mord mathnormal">d</span></span></span></span>
- π¨βπ« consider: edge as unidirectional water pipe
- and capacity: of water flow
- question: what's the max possible flow from source to sink, s.t. all water reaches sink?
- π¨βπ« name: maximum flow algorithm / max flow
- from above example: has capacity , thus we can't send flow larger than 4
- instead of edge: assign capacity to every pair of vertices
- ~= Dijkstra?
- now:
- flow: function
- : flow from to
- condition / constraints
-
- skew symmetry
- sending 2 units : same as sending -2 units
- all except source & sink: indegree = outdegree
- preservation of flow: water coming out from source = water reaching sink
- for source:
- there may be edge to source as well
- and for sink:
- solution , flow s.t. it satisfies 3 conditions above:
- intuition
- for a walk: total flow that can be pass through it = minimum capacity of an edge in walk
- e.g. 1 unit across
- capacity: 4,1,5
- e.g. 1 unit across
- interestingly: one can send flow in reverse direction, too
- e.g. 1 unit across
- capacity: 5,-1,6 respectively
- as it "cancels" my previous flow
- e.g. 1 unit across
- formally speaking:
- if there is flow
- then
- and , satisfying condition
- if there is flow
- thus: find a path
- using only the edges:
- for a walk: total flow that can be pass through it = minimum capacity of an edge in walk
- residual graph of flow :
- w/ same vertices as
- any non-zero edges on this graph: can be utilized for more flow
- upon move :
- and
- is there a case: our flow is maximal, but not maximum?
-
Ford-Fulkerson's algorithm
- basically the idea above
- start with initial flow as 0
- while there exists an augmented path from the source to the sink
- find an augmenting path using any path-finding algorithms
- BFS or DFS
- determine: amount of flow that can be sent along the path
- i.e. minimum residual capacity along the edges of the path
- increase the flow along the augmented path by determined amount
- find an augmenting path using any path-finding algorithms
- return the maximum flow
-
Proof of correctness
- first: extend
- s.t. for a set :
- and
- suppose:
- then,
- define: cut in : division
- s.t.
- what is is : a cut?
-
- as for any non- :
-
- (due to condition)
- vertex: 0 as sum of flow from any non-
- , almost by definition
-
- similarly, define for vertex group
- then: (as inequality holds for every elements)
- a flow is optimal if (can't be further improved)
- thus: find a cut satisfying the condition
- let : all set of vertices that an be reached from in residual graph
- and the rest:
- as algorithm continued until you can't reach in residual anymore
- when the algorithm is stuck: there is no edge going
- if there was: it's reachable, and thus marked
- as original graph and residual graph: shares vertices, but not edges
- there "might" be an edge
- but its non-existence in residual: shows that all its capacity has been used up
- how about ?
- in original graph, it might have
- however: in can't have positive flow as that would add positive edge in residual graph
- which is edge, impossible
- finally:
- thus: the algorithm outputs optimal solution
- related idea: it also gives minimum capacity with
- does this algorithm runs forever?
- if flows doesn't start with 0 / set is of real numbers: yes
- each step: increases flow at least by one
- new range of
- furthermore, upper bound for flow exists: capacity
- thus it can't run forever
- if flows doesn't start with 0 / set is of real numbers: yes
- π¨βπ« in 3711, you make it run for w/ slight modification
- first: extend