Finding minimal cut of a flow network - algorithm

I am trying to find a minimum cut of the following network
I am using the following algorithm:
Run Ford-Fulkerson algorithm and consider the final residual graph.
Find the set of vertices that are reachable from source in the residual graph.
All edges which are from a reachable vertex to non-reachable vertex are minimum cut edges. Print all such edges.
In the first step, my algorithm finds 3 paths:
- s->b->h->t **value: 1**
- s->d->e->t **value: 1**
- s->c->h->i->m->d->g->t **value: 0.5**
So the maximum flow (and therefore minimum cut) is equal to 2.5.
However, when I later try to eliminate the aforementioned paths from the network I end up with something like this:
The reachable vertices are s, c and h, which form a cut equal to 3.5.
What am I missing? Why can't I traverse the graph like I would normally to get the minimum cut?

Every time you increase the capacity of an edge in the residual graph, you need to increase the capacity of the opposite edge by the same amount.
Example graph:
Here is the residual graph without backward edges and the the set of the vertices reachable from S (which do not constitute a min-cut):
And the correct residual graph with the min-cut:

I assume, that your definition of residual graph is that you put edge A->B in residual graph if:
a) There is some different between flow and capacity in direction A->B (aka forward edge)
b) There is some flow in direction B->A (aka backward edge)
In this definition your step 2 is wrong.
To find minimum cut, you only walk through forward edges from start. Now you can denote vertices reachable from start as set R and rest as set R'.
Now the cut is made by edges between R and R'.
And the size of the cut is flow between R and R'.

Related

Minimum total capacity cut

In the network below, the numbers indicate capacities of the edges. It is a network flow problem. The question asks for the minimum total capacity cut. My lecturer's answer, shown in the image with a red jiggly line, is:
The minimum total capacity cut contains arcs {AB, SC, SE} as shown.
My answer is {SA, SC, EF}. I'm basically doing the same, only I avoid edge SA and use EF rather than AB. Why am I wrong?
the flow can still pass through S->E->C->D->T so your set of edges is not even a cut.
A cut is a set of edges that once removes makes it impossible for flow to happen from S to T.
Do keep in mind that removing edges does not remove the vertices themselves.
Here's an easy way to get minimum cut:
Run any max flow algorithm on residual graph (Ford-Fulkerson, Edmonds
Karp, Dinic, etc)
Do BFS from source node ignoring saturated edges
(edges where flow value = edge capacity)
Now take all edges that go
from visited nodes to unvisited nodes
Those edges will be one of possible min cuts

How to set exactly one edge to zero in directed weighted graph in order to find shortest path?

The following is the question I am working on:
Consider a directed, weighted graph
G
where all edge weights are
positive. The goal of this problem is to find the shortest path
in
G
between two pre-specified vertices
s
and
t
, but with an added twist: you are allowed to change the weight
of
exactly
one edge (of your
choosing) to zero.
In other words, you must pick an edge in
G
to set to zero that minimizes the shortest
path between
s
and
t
.
Give an efficient algorithm to achieve this goal in
O
(
E
lg
V
) time and analyze your algorithm’s running
time. Sub-optimal solutions will receive less credit.
Hint:
You may have to reverse the edges, run a
familiar algorithm a number of times, plus do some extra work
So I have tried running Dijkstra's from s to all other nodes and then I have tried reversing the edges and running it again from s to all other nodes. However, I found out that we have to run Dijskstra's from s to all other nodes and then reverse the edges and then run Dijkstra's from all other nodes to t. I am not exactly sure how this helps us to find the edge to set to zero. By my intuition I thought that we would simply set the maximum weight edge to zero. What is the point of reversing the edges?
We need to run Dijkstra's algorithm twice - once for the original graph with s as the source vertex, and once with the reversed graph and t as the source vertex. We'll denote the distance we get between vertex s and i from the first run as D(i) and the distance we get between vertex t and i second run D_rev(i).
Note that we can go follow the reversed edges backwards (i.e., follow them in the original direction), thus D_rev(i) is actually the shortest distance from vertex i to t. Similarly, D(i) is the shortest distance from vertex s to i following Dijkstra's algorithm.
We can now loop through all the edges, and for each edge e which connects v1 and v2, add up D(v1) and D_rev(v2), which corresponds to the weight of the path s -> v1 -> v2 -> t with e being the zero edge, since we can go from s to v1 with a distance of D(v1), set e to 0, go from v1 to v2, and then go from v2 to t with a distance of D_rev(v2). The minimum over these is the answer.
A rough proof sketch (and also a restatement) : if we set an edge e to 0, but don't use it in the path, we can be better off setting an edge that's in the path to 0. Thus, we need only consider paths that includes the zeroed edge. The shortest path through a zeroed edge e is to first take the shortest path from s to v1, and then take the shortest path from v2 to t, which are exactly what were computed using the Dijkstra algorithm, i.e., D and D_rev.
Hope this answer helps!

Determine the minimum number of edges E* such that increase the capacity of all these edges leads to icnrease of max flow

Given a network flow G(V,E). After we run FF algorithm and get a residual grpah Gf and a min-cut (S,T)
I want to know a minimum number of edges E′⊂ E such that increasing capacity of each e ∈ E by one unit will increase the max flow to val(f)+1. The algorithm should run in O(E*log(V)).
Here is my approach.
For each cross edge (u,v)
(1) Use BFS to find partial augmenting path s to u; and all partial augmenting path from v to t. If both such partial augmenting path exists. Then increase the (u,v) can make max flow increase by one.
If (1) is false,
There are few possibility
(a) In residual, source s has no outgoing edge
(b) In residual, sink t has no incoming edge.
(c) both of above happens
In case of (a), the min-cut has one set contains only source s. Find the shortest path from cross edge to t, this distance + 1 (the cross edge) will be our minimal. By using Dijlstra algorithm in O(E*log(V)) time
In case of (b), similarly, find the shortest path from a cross edge to t (let's say this cross edge is (u,v) and v in T, v to t is the shortest path for all cross edge), this distance + 1 + the distance of shortest path from s to u = minimal number of edges that increase all its capacity by one, leads to max flow increase by one
In case of (c), we need to look for a shortest path from s to t; we can apply Dijlstra algorithm in O(E*log(V)) time.
However, I think the above approach can achieve the goal but not very efficient (especially in dealing with case (2), it might not run in E*log(V) time).
Is there easier way of approaching?
If capacities are integers then this seems reasonably straightforward.
From S use depth first search to find all of the nodes reachable from there using links with spare capacity. Put these nodes in a set and mark them.
From T use depth first search to find all of the nodes that can reach T using links with spare capacity. Mark these nodes differently.
Use breadth first search to find the shortest path from any node reachable from S to any node that can reach T. Start with the set of nodes reachable from S. At each stage look it see if any node that can reach T is a neighbour of a node in the current set. If so then you are finished. If not, then the set for the next stage is the set of neighbours of nodes in the current set that are not marked. Mark all of the nodes in the new set.
If the capacities are not integers, so that creating any flow does not give you a flow of capacity at least one, then I think you are in the land of https://en.wikipedia.org/wiki/Minimum-cost_flow_problem.

Find all edges in min-cut

Let (G,s,t,{c}) be a flow network, and let F be the set of all edges e for which there exists at least one minimum cut (A,B) such that e goes from A to B. Give a polynomial time algorithm that finds all edges in F.
NOTE: So far I know I need to run Ford-Fulkerson so each edges has a flow. Furthermore I know for all edges in F, the flow f(e) = c(e). However not all edges in a graph G which respects that constraint will be in a min-cut. I am stuck here.
Suppose you have computed a max flow on a graph G and you know the flow through every edge in the graph. From the source vertex s, perform a Breadth First Search OR Depth First Search on the original graph and only traverse those edges that have flow less than the capacity of the edge. Denote the set of vertices reachable in this traversal as S, and unreachable vertices as T.
To obtain the minimum cut C, we simply find all edges in the original graph G which begin at some vertex in S and end at some vertex in T.
This tutorial in Topcoder provides an explanation / proof of the above algorithm. Look at the section beginning with the following text:
A cut in a flow network is simply a partition of the vertices in two sets, let's call them A and B, in such a way that the source vertex is in A and the sink is in B.
I shall attempt to provide an explanation of the corresponding section in the Topcoder tutorial (just for me to brush up on this as well).
Now, suppose that we have computed a max flow on a graph G, and that we have computed the set of edges C using the procedure outlined above. From here, we can conclude several facts.
Fact 1: Source vertex s must be in set S, and sink vertex t must be in set T.
Otherwise, vertices s and t must be in the same set, which means that we must have found a path from s to t consisting only of edges that have flow less than capacity. This means that we can push more flow from s to t, and therefore we have found an augmenting path! However, this is a contradiction, since we have already computed a max flow on the graph. Hence, it is impossible for source vertex s and sink vertex t to be connected, and they must be in different sets.
Fact 2: Every edge beginning at set S and ending at set T must have flow == capacity
Again we prove this by contradiction. Suppose that there is a vertex u in S and a vertex v in T, such that edge (u,v) in the residual network has flow less than capacity. By our algorithm above, this edge will be traversed, and vertex v should be in set S. This is a contradiction. Therefore, such an edge must have flow == capacity.
Fact 3: Removing the edges in C from graph G will mean that there is no path from any vertex in set S to any vertex in set T
Suppose that this is not the case, and there is some edge (u,v) that connects vertex u in set S to vertex v in set T. We can separate this into 2 cases:
Flow through edge (u,v) is less than its capacity. But we know this will cause vertex v to be part of set S, so this case is impossible.
Flow through edge (u,v) is equal to its capacity. This is impossible since edge (u,v) will be considered as part of the edge set C.
Hence both cases are impossible, and we see that removing the edges in C from the original graph G will indeed result in a situation where there is no path from S to T.
Fact 4: Every edge in the original graph G that begins at vertex set T but ends at vertex set S must have a flow of 0
The explanation on the Topcoder tutorial may not be obvious on first reading and the following is an educated guess on my part and may be incorrect.
Suppose that there exists some edge (x,y) (where x belongs to vertex set T and y belongs to vertex set S), such that the flow through (x,y) is greater than 0. For convenience, we denote the flow through (x,y) as f. This means that on the residual network, there must exist a backward edge (y,x) with capacity f and flow 0. Since vertex y is part of set S, the backward edge (y,x) has flow 0 with capacity f > 0, our algorithm will traverse the edge (y,x) and place vertex x as part of vertex set S. However, we know that vertex x is part of vertex set T, and hence this is a contradiction. As such, all edges from T to S must have a flow of 0.
With these 4 facts, along with the Max-flow min-cut theorem, we can conclude that:
The max flow must be less than or equal to the capacity of any cut. By Fact 3, C is a cut of the graph, so the max flow must be less than or equal to the capacity of cut C.
Fact 4 allows us to conclude that there is no "back flow" from T to S. This along with Fact 2 means that the flow consists entirely of "forward flow" from S to T. In particular, all the forward flow must result from the cut C. This flow value happens to be the max flow. As such, by the Max-flow min-cut theorem, we know that C must be a minimum cut.

Is there a minimum spanning tree that does not contain the min/max weighted edge?

If we have an (arbitrary) connected undirected graph G, whose edges have distinct weights,
does every MST of G contains the minimum weighted edge?
is there an MST of G that does not contain the maximum weighted edge?
Also, I'm more thankful if someone can give a hint of the key things one must keep in mind when dealing with such MST questions.
This is a homework problem. Thanks.
is there an MST of G that does not contain the maximum weighted edge?
There may be, but there doesn't have to be. Consider a 4-vertex graph as follows:
[A]--{2}--[B]
| |
| |
{1} {3}
| |
| |
[C]-{50}--[D]
The minimum spanning tree consists of the edge set {CA, AB, BD}. The maximum edge weight is 50, along {CD}, but it's not part of the MST. But if G were already equal to its own MST, then obviously it would contain its own maximum edge.
does every MST of G contains the minimum weighted edge?
Yes. MSTs have a cut property. A cut is simply a partition of the vertices of the graph into two disjoint sets. For any cut you can make, if the weight of an edge in that cut is smaller than the weights of the other edges in the cut, then this edge belongs to all MSTs in the graph. Because you guaranteed that the edge weights are distinct, you have also guaranteed that there is an edge which is smaller than all other edges.
Also, I'm more thankful if someone can give a hint of the key things one must keep in mind when dealing with such MST questions.
Your best bet is to reason about things using the properties of MSTs in general, and to try to construct specific counterexamples which you think will prove your case. I gave an instance of each line of reasoning above. Because of the cut and cycle properties, you can always determine exactly which edges are in an MST, so you can systematically test each edge to determine whether or not it's in the MST.
Does every MST of G contains the minimum weighted edge?
Yes. Lets assume we have a MST which does not contain the min weight edge. Now the inclusion of this edge to the MST will result in a cycle. Now there will always be another edge in the cycle which can be removed to remove the cycle and still maintain the graph(MST) connected.
Is there an MST of G that does not contain the maximum weighted edge?
Depends on the graph. If the graph itself is a tree then we need to include all of its n-1 edges in the MST, so the max weight edge cannot be excluded. Also if the max weight edge is a cut-edge so that its exclusion will never result in connectivity, then the max weight edge cannot be excluded. But if the max weight edge is a part of a cycle then it is possible to exclude from the MST.
For your first question the answer is no, and kruskal's algorithm proves it. It will always select the minimum cost edge.
For the second question the answer is yes, and it's trivial to find an example graph:
1 - 2 (cost 10)
2 - 3 (cost 100)
3 - 1 (cost 1000)
The third edge will never be selected as it introduces a cycle. So basically, if the edge with the maximum cost would create a cycle if inserted in the MST, it won't be inserted.
I see you too are studying for CSC263 through the 2009 test? (Same here!)
Another way to see that the minimum is always in the MST is to look simply at this minimum edge (call it e):
e
v1 ---------------- v2
(Assume this has connections to other verticies). Now, for e NOT to be included in the final MST means at one point we have, without loss of generality, v1 in the MST but not v2. However, the only way to add v2 without adding e would be to say that the addition of v1 didn't add e to the queue (because by definition, e would be at the top of the queue because it has lowest priority) but this contradicts the MST construction theorem.
So essentially, it is impossible to have an edge with minimum weight not get to the queue which means that any MST constructed would have it.

Resources