max flow and min-cost max flow - duke compsci...
TRANSCRIPT
![Page 1: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/1.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
Max Flow and Min-Cost Max FlowDuke COMPSCI 309s
Siyang Chen
Spring 2014
![Page 2: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/2.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
Max Flow
Let G = (V ,E ) be directed graph with two special nodes s and t(called the source and sink, respectively). Suppose each edge has acapacity cu,v . A flow for is a function which assigns an amountfu,v to each edge, where f satisfies the following properties:
▶ For each u, v , fu,v ≤ cu,v . (Flows respect the capacityconstraint.)
▶ For each u ̸= s, t,∑
v fv ,u =∑
v fu,v . (Flow is conserved.)
▶ For each u, fu,s = ft,u = 0. (Flow does not flow into thesource or out of the sink.)
The maximum flow problem is to find a flow assignment whichmaximises the sum of the flow out of the source (or into the sink).
![Page 3: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/3.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
Max Flow
Let G = (V ,E ) be directed graph with two special nodes s and t(called the source and sink, respectively). Suppose each edge has acapacity cu,v . A flow for is a function which assigns an amountfu,v to each edge, where f satisfies the following properties:
▶ For each u, v , fu,v ≤ cu,v . (Flows respect the capacityconstraint.)
▶ For each u ̸= s, t,∑
v fv ,u =∑
v fu,v . (Flow is conserved.)
▶ For each u, fu,s = ft,u = 0. (Flow does not flow into thesource or out of the sink.)
The maximum flow problem is to find a flow assignment whichmaximises the sum of the flow out of the source (or into the sink).
![Page 4: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/4.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
Max Flow
How do we solve the max flow problem?
The two most commonalgorithms (Ford-Fulkerson and Edmonds-Karp) have the followingintuitive structure:
1. Find some path p from s to t which isn’t at full capacity yet.
2. Send flow along p until p is at full capacity.
3. Repeat the previous steps until there are no more such paths.
Lot of tutorials and reference implementations available online.
![Page 5: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/5.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
Max Flow
How do we solve the max flow problem? The two most commonalgorithms (Ford-Fulkerson and Edmonds-Karp) have the followingintuitive structure:
1. Find some path p from s to t which isn’t at full capacity yet.
2. Send flow along p until p is at full capacity.
3. Repeat the previous steps until there are no more such paths.
Lot of tutorials and reference implementations available online.
![Page 6: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/6.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
Max Flow
How do we solve the max flow problem? The two most commonalgorithms (Ford-Fulkerson and Edmonds-Karp) have the followingintuitive structure:
1. Find some path p from s to t which isn’t at full capacity yet.
2. Send flow along p until p is at full capacity.
3. Repeat the previous steps until there are no more such paths.
Lot of tutorials and reference implementations available online.
![Page 7: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/7.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
Max Flow
How do we solve the max flow problem? The two most commonalgorithms (Ford-Fulkerson and Edmonds-Karp) have the followingintuitive structure:
1. Find some path p from s to t which isn’t at full capacity yet.
2. Send flow along p until p is at full capacity.
3. Repeat the previous steps until there are no more such paths.
Lot of tutorials and reference implementations available online.
![Page 8: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/8.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
Max Flow
How do we solve the max flow problem? The two most commonalgorithms (Ford-Fulkerson and Edmonds-Karp) have the followingintuitive structure:
1. Find some path p from s to t which isn’t at full capacity yet.
2. Send flow along p until p is at full capacity.
3. Repeat the previous steps until there are no more such paths.
Lot of tutorials and reference implementations available online.
![Page 9: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/9.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
Max Flow
How do we solve the max flow problem? The two most commonalgorithms (Ford-Fulkerson and Edmonds-Karp) have the followingintuitive structure:
1. Find some path p from s to t which isn’t at full capacity yet.
2. Send flow along p until p is at full capacity.
3. Repeat the previous steps until there are no more such paths.
Lot of tutorials and reference implementations available online.
![Page 10: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/10.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
March of the Penguins
Example problem: [March of the Penguins]
Solution:
1. For each island t, let’s determine whether we can send allpenguins to it. We can treat t as the sink and let the flow bethe number of penguins we send to t.
2. Suppose we can jump off island i at most mi times. We canmodel this constraint by splitting i into two nodes – iin andiout – and creating an edge between them with capacity mi .(This ‘node-splitting’ technique is a common way oftranslating node constraints into edge constraints.)
3. Lastly, we create a virtual source node which is connected toevery island i via an edge of capacity ni , the number ofpenguins initially on i .
![Page 11: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/11.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
March of the Penguins
Example problem: [March of the Penguins]Solution:
1. For each island t, let’s determine whether we can send allpenguins to it. We can treat t as the sink and let the flow bethe number of penguins we send to t.
2. Suppose we can jump off island i at most mi times. We canmodel this constraint by splitting i into two nodes – iin andiout – and creating an edge between them with capacity mi .(This ‘node-splitting’ technique is a common way oftranslating node constraints into edge constraints.)
3. Lastly, we create a virtual source node which is connected toevery island i via an edge of capacity ni , the number ofpenguins initially on i .
![Page 12: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/12.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
March of the Penguins
Example problem: [March of the Penguins]Solution:
1. For each island t, let’s determine whether we can send allpenguins to it. We can treat t as the sink and let the flow bethe number of penguins we send to t.
2. Suppose we can jump off island i at most mi times. We canmodel this constraint by splitting i into two nodes – iin andiout – and creating an edge between them with capacity mi .(This ‘node-splitting’ technique is a common way oftranslating node constraints into edge constraints.)
3. Lastly, we create a virtual source node which is connected toevery island i via an edge of capacity ni , the number ofpenguins initially on i .
![Page 13: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/13.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
March of the Penguins
Example problem: [March of the Penguins]Solution:
1. For each island t, let’s determine whether we can send allpenguins to it. We can treat t as the sink and let the flow bethe number of penguins we send to t.
2. Suppose we can jump off island i at most mi times. We canmodel this constraint by splitting i into two nodes – iin andiout – and creating an edge between them with capacity mi .(This ‘node-splitting’ technique is a common way oftranslating node constraints into edge constraints.)
3. Lastly, we create a virtual source node which is connected toevery island i via an edge of capacity ni , the number ofpenguins initially on i .
![Page 14: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/14.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
March of the Penguins
Example problem: [March of the Penguins]Solution:
1. For each island t, let’s determine whether we can send allpenguins to it. We can treat t as the sink and let the flow bethe number of penguins we send to t.
2. Suppose we can jump off island i at most mi times. We canmodel this constraint by splitting i into two nodes – iin andiout – and creating an edge between them with capacity mi .(This ‘node-splitting’ technique is a common way oftranslating node constraints into edge constraints.)
3. Lastly, we create a virtual source node which is connected toevery island i via an edge of capacity ni , the number ofpenguins initially on i .
![Page 15: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/15.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
Max Flow Min Cut Theorem
A cut of the graph is a partitioning of the graph into two sets Xand Y . The capacity of this cut is defined to be∑
u∈X
∑v∈Y
cu,v
The max-flow min-cut theorem states that the maximum capacityof any cut where s ∈ X and t ∈ Y is equal to the max flow from sto t. This is actually a manifestation of the duality property oflinear programs, which we’ll investigate more next week.
![Page 16: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/16.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
Max Flow Min Cut Theorem
A cut of the graph is a partitioning of the graph into two sets Xand Y . The capacity of this cut is defined to be∑
u∈X
∑v∈Y
cu,v
The max-flow min-cut theorem states that the maximum capacityof any cut where s ∈ X and t ∈ Y is equal to the max flow from sto t.
This is actually a manifestation of the duality property oflinear programs, which we’ll investigate more next week.
![Page 17: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/17.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
Max Flow Min Cut Theorem
A cut of the graph is a partitioning of the graph into two sets Xand Y . The capacity of this cut is defined to be∑
u∈X
∑v∈Y
cu,v
The max-flow min-cut theorem states that the maximum capacityof any cut where s ∈ X and t ∈ Y is equal to the max flow from sto t. This is actually a manifestation of the duality property oflinear programs, which we’ll investigate more next week.
![Page 18: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/18.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
Bipartite Matching
A common application of max flow is to solve the bipartitematching problem:
Given a bipartite graph G = (V = X ∪ Y ,E ⊆ X × Y ), what isthe maximum number of edges we can choose such that no twoedges share a common vertex?
![Page 19: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/19.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
Bipartite Matching
A common application of max flow is to solve the bipartitematching problem:Given a bipartite graph G = (V = X ∪ Y ,E ⊆ X × Y ), what isthe maximum number of edges we can choose such that no twoedges share a common vertex?
![Page 20: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/20.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
Bipartite Matching
How do we reduce bipartite matching on G = (X ∪ Y ,E ) to maxflow?
1. Create edges of capacity 1 from s to every x ∈ X , and fromevery y ∈ Y to t.
2. Let edges e = (x , y) ∈ E have capacity 1 from x to y .
The max flow on the modified graph is the maximum bipartitematching.
![Page 21: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/21.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
Bipartite Matching
How do we reduce bipartite matching on G = (X ∪ Y ,E ) to maxflow?
1. Create edges of capacity 1 from s to every x ∈ X , and fromevery y ∈ Y to t.
2. Let edges e = (x , y) ∈ E have capacity 1 from x to y .
The max flow on the modified graph is the maximum bipartitematching.
![Page 22: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/22.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
Bipartite Matching
How do we reduce bipartite matching on G = (X ∪ Y ,E ) to maxflow?
1. Create edges of capacity 1 from s to every x ∈ X , and fromevery y ∈ Y to t.
2. Let edges e = (x , y) ∈ E have capacity 1 from x to y .
The max flow on the modified graph is the maximum bipartitematching.
![Page 23: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/23.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
Bipartite Matching
How do we reduce bipartite matching on G = (X ∪ Y ,E ) to maxflow?
1. Create edges of capacity 1 from s to every x ∈ X , and fromevery y ∈ Y to t.
2. Let edges e = (x , y) ∈ E have capacity 1 from x to y .
The max flow on the modified graph is the maximum bipartitematching.
![Page 24: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/24.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
PythTriplets
Bipartite matching example: [PythTriplets]
Solution:
1. Critical observation: if a2 + b2 = c2 for integral a, b, and c ,then a and b cannot both be odd. (Can be proven viaquadratic residues.)
2. The problem statement also mentions that a and b cannotboth be even, so one must be odd and the other must be even.
3. Then the problem reduces to finding a maximum (bipartite)matching between odd and even numbers.
![Page 25: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/25.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
PythTriplets
Bipartite matching example: [PythTriplets]Solution:
1. Critical observation: if a2 + b2 = c2 for integral a, b, and c ,then a and b cannot both be odd. (Can be proven viaquadratic residues.)
2. The problem statement also mentions that a and b cannotboth be even, so one must be odd and the other must be even.
3. Then the problem reduces to finding a maximum (bipartite)matching between odd and even numbers.
![Page 26: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/26.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
PythTriplets
Bipartite matching example: [PythTriplets]Solution:
1. Critical observation: if a2 + b2 = c2 for integral a, b, and c ,then a and b cannot both be odd. (Can be proven viaquadratic residues.)
2. The problem statement also mentions that a and b cannotboth be even, so one must be odd and the other must be even.
3. Then the problem reduces to finding a maximum (bipartite)matching between odd and even numbers.
![Page 27: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/27.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
PythTriplets
Bipartite matching example: [PythTriplets]Solution:
1. Critical observation: if a2 + b2 = c2 for integral a, b, and c ,then a and b cannot both be odd. (Can be proven viaquadratic residues.)
2. The problem statement also mentions that a and b cannotboth be even, so one must be odd and the other must be even.
3. Then the problem reduces to finding a maximum (bipartite)matching between odd and even numbers.
![Page 28: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/28.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
PythTriplets
Bipartite matching example: [PythTriplets]Solution:
1. Critical observation: if a2 + b2 = c2 for integral a, b, and c ,then a and b cannot both be odd. (Can be proven viaquadratic residues.)
2. The problem statement also mentions that a and b cannotboth be even, so one must be odd and the other must be even.
3. Then the problem reduces to finding a maximum (bipartite)matching between odd and even numbers.
![Page 29: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/29.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
Minimum Path Cover
One application of bipartite matching is to solve the minimumpath cover problem:
Given a graph G = (V ,E ), what is the minimum number ofdisjoint paths needed to cover all the vertices? When G is a DAG,this can be solved with bipartite matching.
![Page 30: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/30.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
Minimum Path Cover
One application of bipartite matching is to solve the minimumpath cover problem:Given a graph G = (V ,E ), what is the minimum number ofdisjoint paths needed to cover all the vertices?
When G is a DAG,this can be solved with bipartite matching.
![Page 31: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/31.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
Minimum Path Cover
One application of bipartite matching is to solve the minimumpath cover problem:Given a graph G = (V ,E ), what is the minimum number ofdisjoint paths needed to cover all the vertices? When G is a DAG,this can be solved with bipartite matching.
![Page 32: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/32.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
Minimum Path Cover
One application of bipartite matching is to solve the minimumpath cover problem:Given a graph G = (V ,E ), what is the minimum number ofdisjoint paths needed to cover all the vertices? When G is a DAG,this can be solved with bipartite matching.
![Page 33: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/33.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
Minimum Path Cover
How do we reduce minimum path cover on a DAG to bipartitematching?
1. Note that a set of edges E ′ is a disjoint path covering if andonly if each node has indegree and outdegree of at most 1.
2. Each edge in E ′ reduces the number of paths we use. I.e., thesize of the minimum path cover is |V | − |E ′|. This means wewant to maximise |E ′| subject to the above constraint.
3. Split the nodes into vin and vout and connect vout and uin if(v , u) ∈ E . A matching in the split graph corresponds exactlyto a disjoint path covering in the original graph.
It suffices, then, to find a maximum bipartite matching for the splitgraph.
![Page 34: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/34.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
Minimum Path Cover
How do we reduce minimum path cover on a DAG to bipartitematching?
1. Note that a set of edges E ′ is a disjoint path covering if andonly if each node has indegree and outdegree of at most 1.
2. Each edge in E ′ reduces the number of paths we use. I.e., thesize of the minimum path cover is |V | − |E ′|. This means wewant to maximise |E ′| subject to the above constraint.
3. Split the nodes into vin and vout and connect vout and uin if(v , u) ∈ E . A matching in the split graph corresponds exactlyto a disjoint path covering in the original graph.
It suffices, then, to find a maximum bipartite matching for the splitgraph.
![Page 35: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/35.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
Minimum Path Cover
How do we reduce minimum path cover on a DAG to bipartitematching?
1. Note that a set of edges E ′ is a disjoint path covering if andonly if each node has indegree and outdegree of at most 1.
2. Each edge in E ′ reduces the number of paths we use. I.e., thesize of the minimum path cover is |V | − |E ′|. This means wewant to maximise |E ′| subject to the above constraint.
3. Split the nodes into vin and vout and connect vout and uin if(v , u) ∈ E . A matching in the split graph corresponds exactlyto a disjoint path covering in the original graph.
It suffices, then, to find a maximum bipartite matching for the splitgraph.
![Page 36: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/36.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
Minimum Path Cover
How do we reduce minimum path cover on a DAG to bipartitematching?
1. Note that a set of edges E ′ is a disjoint path covering if andonly if each node has indegree and outdegree of at most 1.
2. Each edge in E ′ reduces the number of paths we use. I.e., thesize of the minimum path cover is |V | − |E ′|. This means wewant to maximise |E ′| subject to the above constraint.
3. Split the nodes into vin and vout and connect vout and uin if(v , u) ∈ E . A matching in the split graph corresponds exactlyto a disjoint path covering in the original graph.
It suffices, then, to find a maximum bipartite matching for the splitgraph.
![Page 37: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/37.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
Minimum Path Cover
How do we reduce minimum path cover on a DAG to bipartitematching?
1. Note that a set of edges E ′ is a disjoint path covering if andonly if each node has indegree and outdegree of at most 1.
2. Each edge in E ′ reduces the number of paths we use. I.e., thesize of the minimum path cover is |V | − |E ′|. This means wewant to maximise |E ′| subject to the above constraint.
3. Split the nodes into vin and vout and connect vout and uin if(v , u) ∈ E . A matching in the split graph corresponds exactlyto a disjoint path covering in the original graph.
It suffices, then, to find a maximum bipartite matching for the splitgraph.
![Page 38: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/38.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
Taxi Cab Scheme
Example problem: [Taxi Cab Scheme]
Solution:
1. Let customers be nodes, and connect customers a and b withan edge if it’s possible to pick up customer b after droppingoff customer a.
2. The minimum number of taxis needed to accommodate allcustomers is then the minimum path cover of the above graph.
![Page 39: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/39.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
Taxi Cab Scheme
Example problem: [Taxi Cab Scheme]Solution:
1. Let customers be nodes, and connect customers a and b withan edge if it’s possible to pick up customer b after droppingoff customer a.
2. The minimum number of taxis needed to accommodate allcustomers is then the minimum path cover of the above graph.
![Page 40: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/40.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
Taxi Cab Scheme
Example problem: [Taxi Cab Scheme]Solution:
1. Let customers be nodes, and connect customers a and b withan edge if it’s possible to pick up customer b after droppingoff customer a.
2. The minimum number of taxis needed to accommodate allcustomers is then the minimum path cover of the above graph.
![Page 41: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/41.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
Taxi Cab Scheme
Example problem: [Taxi Cab Scheme]Solution:
1. Let customers be nodes, and connect customers a and b withan edge if it’s possible to pick up customer b after droppingoff customer a.
2. The minimum number of taxis needed to accommodate allcustomers is then the minimum path cover of the above graph.
![Page 42: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/42.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
Min-Cost Flow
The minimum-cost maximum flow problem uses the same settingas the maximum flow problem, except that each unit of flow has acost associated with it.
I.e., we want to minimise∑u,v
costu,v · fu,v
such that the maximum flow constraints still hold, i.e.∑v
fs,v
is still maximised.
![Page 43: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/43.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
Min-Cost Flow
The minimum-cost maximum flow problem uses the same settingas the maximum flow problem, except that each unit of flow has acost associated with it. I.e., we want to minimise∑
u,v
costu,v · fu,v
such that the maximum flow constraints still hold, i.e.∑v
fs,v
is still maximised.
![Page 44: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/44.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
Min-Cost Flow
The minimum-cost maximum flow problem uses the same settingas the maximum flow problem, except that each unit of flow has acost associated with it. I.e., we want to minimise∑
u,v
costu,v · fu,v
such that the maximum flow constraints still hold, i.e.∑v
fs,v
is still maximised.
![Page 45: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/45.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
Min-Cost Flow
We can solve the min-cost flow problem in a similar manner as wesolve the max flow problem:
1. Find the shortest path p from s to t which isn’t at fullcapacity yet. Here the path length is defined to be the sum ofall the edge flow costs.
2. Send flow along p until p is at full capacity.
3. Repeat the previous steps until there are no more paths.
Again, there are many tutorials and sample implementations online.
![Page 46: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/46.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
Min-Cost Flow
We can solve the min-cost flow problem in a similar manner as wesolve the max flow problem:
1. Find the shortest path p from s to t which isn’t at fullcapacity yet. Here the path length is defined to be the sum ofall the edge flow costs.
2. Send flow along p until p is at full capacity.
3. Repeat the previous steps until there are no more paths.
Again, there are many tutorials and sample implementations online.
![Page 47: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/47.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
Min-Cost Flow
We can solve the min-cost flow problem in a similar manner as wesolve the max flow problem:
1. Find the shortest path p from s to t which isn’t at fullcapacity yet. Here the path length is defined to be the sum ofall the edge flow costs.
2. Send flow along p until p is at full capacity.
3. Repeat the previous steps until there are no more paths.
Again, there are many tutorials and sample implementations online.
![Page 48: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/48.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
Min-Cost Flow
We can solve the min-cost flow problem in a similar manner as wesolve the max flow problem:
1. Find the shortest path p from s to t which isn’t at fullcapacity yet. Here the path length is defined to be the sum ofall the edge flow costs.
2. Send flow along p until p is at full capacity.
3. Repeat the previous steps until there are no more paths.
Again, there are many tutorials and sample implementations online.
![Page 49: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/49.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
Min-Cost Flow
We can solve the min-cost flow problem in a similar manner as wesolve the max flow problem:
1. Find the shortest path p from s to t which isn’t at fullcapacity yet. Here the path length is defined to be the sum ofall the edge flow costs.
2. Send flow along p until p is at full capacity.
3. Repeat the previous steps until there are no more paths.
Again, there are many tutorials and sample implementations online.
![Page 50: Max Flow and Min-Cost Max Flow - Duke COMPSCI 309sdb.cs.duke.edu/courses/compsci309s/spring14/notes/flow.pdfMax Flow Min Cut Theorem A cut of the graph is a partitioning of the graph](https://reader033.vdocuments.us/reader033/viewer/2022053010/5f0d8adf7e708231d43ae09c/html5/thumbnails/50.jpg)
..........
.....
.....................................................................
.....
......
.....
.....
.
DirectionBoard
Example min-cost flow problem: [DirectionBoard]