Let G = (V, E) be a network with s and t being the source and the sink. Let f be a maximum flow in G. Find an algorithm that determines whether there exists a unique min-cut in G.
I have managed to find a similar question on this site:
Determining the uniqueness of a min-cut
A summary of the answer given there:
Find all the vertices reachable from s in the residual graph and we've found a min-cut (S,T) in G.
Look at the same residual graph, starting at t. Look at the group of vertices reachable from t in the reverse direction of the arrows (meaning all the vertices which can reach t).
This group is also a min-cut.
If that cut is identical to your original cut, then there is only one. Otherwise, you just found 2 cuts, so the original one can't possibly be unique.
I don't understand why if the cut is identical to the original cut then the cut is unique.
Who can promise us that there is no other min-cut ?
Thanks in advance
Actually, I don't quite understand that solution. But in the original question, the second answer provided by davin is absolutely correct.
I just copy and paste it here
Given a minimum S-T cut, (U,V) with cut-edges E', we make one simple observation:
If this minimum cut is not unique, then there exists some other minimum cut with
a set of cut-edges E'', such that E'' != E'.
If so, we can iterate over each edge in E', add to its capacity, recalculate the
max flow, and check if it increased.
As a result of the observation above, there exists an edge in E' that when
increased, the max flow doesn't increase iff the original cut is not unique.
some explanation of my own:
What you need to prove actually is
there exists an edge in E' that when increased, the max flow doesn't increase
<=>
the original cut is not unique
=>:
You increase the capacity of edge e by 1, calculate the new max flow and it remains the same, which means that e is not in the new min-cut. (if e is in, according to the property of min-cut, f(e)=capacity of e, which leads to an increase). Since e is not in the new min-cut, it is also a min-cut of the original graph which has the same volume with the cut we know.Thus, the original cut is not unique.
<=:
The original cut is not unique(Let's call them E and E'), which means you can find an edge e that is in E but not in E'. Then you just increase the capacity of e by 1. When calculating the min-cut of the new graph, E' is already there. Since E' doesn't contain edge e, max flow remains the same with no doubt.
Hope you understand :)
another option to prove by contradiction the first way:
->:
let's say there's a single minimal (S,T) cut with cut edges E'.
After increasing the capacity of edge e which belongs to E' by 1 and finding that the max flow remains the same, leads that e is not in the new min-cut. (if e is in E', according to the property of min-cut the max flow would be increased).
However at the beginning we said the e is in E' - contradiction
The algorithm that you talked about is more efficient than the suggested ones.
The algorithm:
For graph G=(V,E)
Find maximum flow in the graph, and let R be the last residual graph.
Run BFS from s (find nodes reachable from s), lets call them X
Run BFS from t with reversed edges (find nodes that there is a path to t), lets call them Y.
if X + Y = V ('+' as in union) return TRUE, else FALSE
A short explanation:
in step 2 we find the nodes that determine the minimum cut (X, V/X).X is the set of all nodes reachable from s in our last residual graph. In step 3 we find the set of nodes from which t is reachable in the last residual graph. This set defines the cut (V-Y,Y) which is the minimum-cut closest to t. In step 4, is go the same cut from both ends (X + Y = V), then the graph has a unique minimum cut.
The complexity is mainly finding the maximum flow. With Edmonds Karp O(|E|^2|V|), and BFS O(|E| + |V|).
The complexity of the suggested answer will be O(|V||E|^3).
So far, all discussion of the algorithm presented in the original post (both here an d in the post from which it is copied) seem to stop short of actually proving that if the two minimum cuts are the same, then it is the unique minimum cut. But this isn't hard!
OK, so what are these two minimum cuts? We run a maximum flow algorithm and look at the residual graph. The first cut is (S,T=V-S) where S is the set of all nodes that can be reached from the source using only edges with residual capacity. The second cut is (V-T,T) where T is the set of all nodes that can reach the sink using only edges with residual capacity.
If these two cuts are different, then clearly there is more than one minimal cut. But if they are the same, then we can use the technique described by laike9m to show that this is the only minimum cut. Why? Well, by the definitions of S and T in the previous paragraph, each edge e=(v0->v1) in the cut comes with a path s->v0 and a path v1->t that have residual capacity. Thus, if we increase the capacity of e, we know that we will increase the maximum flow. Since this is true for every edge e in the cut, this means that this minimum cut is unique.
Related
The following is the given algorithm for finding a Euler Path in a Eulerian Graph. However, it is said that there is an counter example with less than 10 vertices. The given Eulerian Graph is undirected and every vertex has even degree and it will start and end at the same vertex.
1. Perform a DFS traversal of G and number the vertices in DFS-preorder.
2. Re-initialize all vertices and edges of G as unused.
3. Produce a cycle as follows:
Start from the vertex with preorder number 1 (computed in step 1), and
repeatedly go to the vertex with highest preorder number possible along
an unused edge.
Stop when all edges incident to the current vertex are used.
I have been trying vertices from 6 to 9 for the last 3 days and I really couldn't come up with one example. Any help is appreciated! Thank you.
It's a little pedantic based on the definition that a Euler graph is a graph where each vertex has even degrees, so what if we considered that the graph was unconnected?
A---C E---G
| | | |
B---D F---H
To run DFS on different components - there would need to be a step prior to #1 which discovers the complete graph.
The following graph would also not work as the algo would take the path: {0,3,4,7,1,3,2,1,0} missing 5,6.
I am posting this as an answer because I didnt know how to show the graph correctly in comment as you could have seen.
Well correct me if i m wrong but wont the algo be struck for following graph-
A---B
\ /
C
/ \
D---E
With DFS- C A B D E
Now as C is node number 1 we will start from it and will have to visit it again to go to other cycle.
Similar graphs with 2 or more cycles with common node will give error if what i understood of your code is correct.
PS- Can anyone tell how start newline in comment
I'm currently trying to implement the viterbi algorithm in python, more specifically the version presented in an online course.
As it stands, the algorithm is presented that way:
given a sentence with K tokens, we have to generate K tags .
We assume that tag K-1 = tag K-2 = '*', then for k going from 0 to K,
we set the tag for the token as follows :
tag(WORD_k) = argmax(p(k-1, tag_k-2, tag_k-1) * e( word_k, tag_k) * q(tag_k, tag_k-1, tag_k-1))
From my understanding this is straightforward because the p parameters are already calculated on each step (we go from 1 forward, and we already know p0), and max for the e and q params can be calculated by one iteration through the tags (since we can't come up with 2 different tags, we basically have to find the tag T for which the q * e product is maximal, and return that). This saves a lot of time, since we are almost at linear time in terms in big O notation, instead of exponential complexity, which we would get if we iterated through all possible word/tag combinations.
Am I getting the core of the algorithm correctly or am I missing something out?
Thanks in advance
since we can't come up with 2 different tags, we basically have to
find the tag T for which the q * e product is maximal, and return that
Yeah, sounds about right. q is the trigram (transition) probability and e is named the emission probability. As you said is unchanged between different paths in each stage, so the max is only dependent on the other two.
Each tag sequence should start with two asterisks at positions -2 and -1. So the first assumption is correct:
If we assume to be the maximum probability that the last two tags at position k are u and v, based on what we just said about the beginning asterisks, the base case would be
.
You had two errors in the general case though. The emission probability is a conditional. Also in the trigram, is repeated two times and the formula given is incorrect:
The integraloty theorem tells us that if all capacities in a flow network are integers, then there is a maximum flow where every value is an integer
But the most remarkable part is the existence, not every maximum flow!
Which means this statement doesn't claim every maximum flow is integer-valued
I cannot figure out why if all capacities are integer, but there exists a maximum flow is not integer-valued!!
Or did I just get wrong idea of this theorem that tries to tell me?
Let
e = edge in the graph.
c(e) = capacity of the given edge e
f(e) = amount of flow going through given edge e
The theorem states:
If c(e) for all edges, e, in graph are integers, then there exists a max flow
f for which every flow value f(e) is an integer.
Notice the theorem does not place constraint on f(e).
Only c(e) must be integer.
Since "c(e) must be integer" does not imply "f(e) must be integer" as well.
Therefore it is perfectly valid to have non-integer flow with integer capacity.
Here is an example where all capacities are integer with a maximum flow that has some edges that has non-integer flow..
G is the flow Graph I am working with..
N is a maximum integral flow..
N` is a maximum flow where it has some edges has non-integer flow..
pair number on edges are of format: "flow/capacity"
Remember the theorem only says the upper bound of f(u,v) are integers.. it does not say anything about its lower bound.. therefore flow can be any number between 0 and c(u,v)..
If using Ford-Fulkerson method to get a maximum flow, then the resulted flow must be integer-valued
But, we still can have a maximum flow that use real number as the flow value on the edges
Check this example:
B
/ \
/ \
/ \
s------A t
\ /
\ /
\ /
C
the directions of edges all go from left to right , and the (s,a) has 1 flow and 1 capacity,
and rest of all all go with 0.5 flow and 1 capacity.
This is flow network having a maximum flow but not integer-valued.
Can anyone give me the thought process involved in developing a context free grammar for this? I'm given a language where there are a certain number of 0's and a certain number of 1's but the number of 0's is not equal to the number of 1's. However the 0's come first then the 1's (that should make things more straight forward). So an acceptable string would be 0000111 or 01111111
I don't want you to just give me the direct answer, or the answer at all for that matter. Just the process of figuring it out.
Well, the direct answer which you don't want is:
S - initial symbol
S -> X | Y
X -> 0X1 | X1 | 1
Y -> 0Y1 | 0Y | 0
It's the first thing that comes to mind so there isn't too much of a process. Anyway, I would say that the very first thing you must see is that there are two possibilities - either you have more ones, or zeroes and it's good two divide the problem into these two (as I divided S into X and Y).
Then you see that "context free" makes it impossible to control the number in any place other than the boundary between zeroes and ones. The you just get the idea and write down the solution.
I am new to SMT solvers. I would like to know that how could I encode a simple TSP problem having 4/6 nodes? I am confused how to set my constraints using the Z3pay APA. Any kind of hint or help would be highly appreciated.
You can phrase your TSP problem as an ILP problem. The question is now how to encode the TSP as an ILP. There are two well known answers: Miller–Tucker–Zemlin and Dantzig–Fulkerson–Johnson.
The basic idea is as follows: Say we have n cities. Let us denote by d_ij the distance between cities i and j and let us denote by x_{ij} the boolean value (0 or 1) whether the TSP contains the edge from i to j. Then finding the smallest tour means
minimize sum_{i,j} x_{ij} d_{ij}
such that the x_{ij} describe a cycle. With those two conditions we get one or more cycles:
sum_{j} x_{ij} = 1 for all i exactly one outgoing edge per city
sum_{i} x_{ij} = 1 for all j exactly one ingoing edge per city
Now we have to exclude the case that the solutions comprises multiple cycles. We can add this exponential number of Dantzig–Fulkerson–Johnson conditions:
sum_{i in S} sum_{j in S} x_{ij} < |S| for all proper subsets S of {1, ..., n}
Note that if our solution contains two cycles then for S being the vertex set of one of the cycles then the x_{ij}-sum will be |S|. On the other hand, if there is only one cycle then the x_{ij}-sum will never reach |S|, e.g., if you remove one vertex from {1, ..., n} then the number of edges remaining is n-2, but |S| = n-1.
Of course, an exponential number of constraints is not what we want, so we look for a more clever way to exclude the subcycle cases. And here is where Miller–Tucker–Zemlin jumps in.
A different approach would be to simply ignore the subcycle problem, compute a solution and check whether the solution comprises subcycles. If it does, exclude the solution by adding it as a lazy constraint and repeat until you get a single-cycle solution. The keyword here is lazy constraint.
There is a nice sample that may be useful for you:
http://z3.codeplex.com/SourceControl/changeset/view/1235b3ea24d9#examples/python/hamiltonian/hamiltonian.py