Can I use Stoer-Wagner algorithm to find the max cut?
Say, I negate all weights of the edges and find the minimum cut of this graph using Stoer-Wagner algorithm, is the result cut a max cut of the original graph?
Added: In Stoer-Wagner algorithm, what if I choose the least tightly connected vertex instead, and choose the largest among all cut returned by cut-of-the-phase, is it the global maximum cut? Why or Why not? Any example?
Nico's observation that max cut is hard is the general reason that approaches like this one probably won't work, but the specific problem is that, when Stoer--Wagner goes to find an st min cut, the max flow routine that it most likely calls can't find a flow at all, since all of the capacities are negative. (Max flow algorithms can handle negative capacities in case there's a way to circulate flow to eliminate the negative capacities and get a feasible flow, but if they're all negative, then there's no way.)
Related
I have programmed the minimum Hungarian algorithm for a bipartite graph, with Dijkstra's algorithm to find the minimum cost of a maximum matching. However, I want to use such an algorithm to implement the maximum Hungarian algorithm and don't know if it's correct to just negate the edges, because I don't know if the algorithm will handle it.
My implementation is based on the explanation on the following site: https://www.ics.uci.edu/~eppstein/163/lecture6b.pdf
Given G=(AUB, E), the idea is to label the vertices via an artificial start vertex s which has edges with unsaturated nodes in A, and run Dijkstra's algorithm from s in order to label each vertex, then after labeling each, the edges will be reweighted by their original weight minus the labels of the edge's endpoints.
I have read a lot of articles, and the only I could see is that a minimum Hungarian algorithm can be handled well with maximum cost by negating each edge, however, I am afraid that due to the fact that Dijkstra's algorithm doesn't handle negative edges well, it won't work.
First find the maximum weight in your graph. Then negate all of the weights and add the maximum weight to them. Adding the original maximum to all of the negated values makes them all positive.
You can also use INT_MAX (or whatever is equivalent to it in the programming language you're using) instead of the maximum weight. This skips the step of finding the maximum weight, but could make the first iteration of the Hungarian Algorithm take longer, or cause you to need an extra iteration of the algorithm to get the result. It probably doesn't make much of a difference either way and the performance difference will vary based on the particular weights in your graph.
we have an undirected graph G = (V,E) with n nodes and m edges, i want to calculate whether G have a cut of size m or not ? How can I solve it ? I tried BFS but i realized that we can calculate with lower or upper level for cut.
Edit: The cut just separates the graph in two pieces.
This problem is a sub-case of the maximum cut problem. Note that the maximum-cut problem asks for a cut of at least an arbitrary value x, not necessarily m. It is thus more general than what you asked for.
Max-Cut is NP-complete, meaning that there is no known algorithm in polynomial time. The best know algorithm is trying out every possible cut (brute search).
A max-cut may look like the following picture. Generally it does NOT look like something that you'd create with BFS or DFS.
In this sub-problem you are lucky though: First off, the edges are unweighted, meaning that indirectly all of them have a weight of 1. If they were weighted, my proposed solution would be invalid.
If there is a max-cut of size m, this means that every edge is part of the cut. This is equivalent to the test of bipartness. This is possible to check in linear time. Here is an example of a biparte graph:
To conclude: The question "does Graph G have a cut of size of at least x" is NP-complete, but your question is equivalent to test of bipartness. A graph is biparte exactly if it doesn't contain any circles of uneven length. Here is the algorithm to test for bipartness, which runs in O(V+E), just like BFS.
Assume that we are given an undirected, unweighted graph G= (V, E) and some cost function c:E→R>0 assigning a positive cost c(e) to each edge e∈E. The goal is to compute a minimum cut of G of minimum cost (i.e., a minimum cost cut among the cuts consisting of the smallest number of edges). Give an algorithm which with high probability finds such a minimum cost minimum cut in polynomial time. What is the running time of your algorithm?
Hint: Karger Algorithm
Approach I:
Do Karger n^c times (still polynomial, raises exponent on n of c) and compare resulting min cuts. with c >=1
Approach II:
When Karger is taken its edges for Contraction, raise probabilty of High weights. Doesnt affect Runtime
or even a combination of both?
Approach I doesn't seem to add anything to Karger's algorithm. From the introduction to this article: "By iterating this basic algorithm a sufficient number of times, a minimum cut can be found with high probability." In other words, Approach I is already part of the algorithm.
Approach II is technically unnecessary (Karger's algorithm will eventually find the minimum cut anyways), and may actively impair the algorithm. For example, consider a graph that can be cut by removing one particular edge, but otherwise requires two or more edges for a cut (the numbers represent the cost of an edge):
If that particular edge has the highest cost (999 in this example), then raising the probability of selecting that edge for contraction reduces the probability of finding the (minimum cost) minimum cut. In fact, it reduces the probability of finding the (any cost) minimum cut.
So all you need to do is run the standard algorithm. On each iteration you need to check if the newly found cut has fewer edges than the current best cut. If so, the newly found cut is the best cut (so far). If the newly found cut has the same number of edges as the current best cut, then compare the costs to see which is better.
Is there a reduction from the min cost flow problem to the max-flow problem? Or viceversa? I would like to use a min cost flow algorithm to solve a max-flow problem.
Sorry I think I misunderstand the question the first time. Yes, Minimum Cost is a special case for max flow. Rather than max flow, min cost assumes that after going through each edge, there is a cost to the flow. Therefore, if you set the cost at each edge to be zero, then min cost is reduced to the max flow.
Edit:
Since min cost problem needs a pre-defined required flow to send to begin with. You will need to run the above algorithm (with cost of edge c(u, v) = 0) for multiple times to search for the maximum value. For a given range of values, binary search can be used to more efficiently locate the max
Do you mean Min Cut Max Flow? (Edit: I do not think you meant this, but this is the basis of proving max flow, worth looking at if you have not)
I will be easier to understand if you drop a graph and do a min cut yourself.
Add a cost (per unit flow) of -1 to each edge, then use your minimise cost algorithm. That will maximise the flow.
The accepted answer may be practical. Proofing that Max-Flow is a special case of Min-Cost-Flow there is another possibility. My solution takes one iteration of the minimum-mean-cycle-cancelling algorithm in O(m^3 n^2 log n) (cause c is not conservative):
1. set c(e) = 0 for all edges in G
2. add edge (t,s) with inf capacity and c((t,s)) = -1
3. start MIN-MEAN-CYCLE-CANCELLING on modified graph G'
correctness: Algorithm is searching for residual circles with negative weight. As long as there is an augmentive path from s to t there are negative weighted residual circles.
We have an array of elements a1,a2,...aN from an alphabet E. Assuming |N| >> |E|.
For each symbol of the alphabet we define an unique integer priority = V(sym). Let's define V{i} := V(symbol(ai)) for the simplicity.
How can I find the priority function V for which:
Count(i)->MAX | V{i} < V{i+1}
In other words, I need to find the priorities / permutation of the alphabet for which the number of positions i, satisfying the condition V{i}<V{i+1}, is maximum.
Edit-1: Please, read carefully. I'm given an array ai and the task is to produce a function V. It's not about sorting the input array with a priority function.
Edit-2: Example
E = {a,b,c}; A = 'abcab$'; (here $ = artificial termination symbol, V{$}=+infinity)
One of the optimal priority functions is: V{a}=1,V{b}=2,V{c}=3, which gives us the following signs between array elements: a<b<c>a<b<$, resulting in 4 '<' signs of 5 total.
If elements could not have tied priorities, this would be trivial. Just sort by priority. But you can have equal priorities.
I would first sort the alphabet by priority. Then I'd extract the longest rising subsequence. That is the start of your answer. Extract the longest rising subsequence from what remains. Append that to your answer. Repeat the extraction process until the entire alphabet has been extracted.
I believe that this gives an optimal result, but I haven't tried to prove it. If it is not perfectly optimal, it still will be pretty good.
Now that I think I understand the problem, I can tell you that there is no good algorithm to solve it.
To see this let us first construct a directed graph whose vertices are your elements, and whose edges indicate how many times one element immediately preceeded another. You can create a priority function by dropping enough edges to get a directed acyclic graph, use the edges to create a partially ordered set, and then add order relations until you have a full linear order, from which you can trivially get a priority function. All of this is straightforward once you have figured out which edges to drop. Conversely given that directed graph and your final priority function, it is easy to figure out which set of edges you had to decide to drop.
Therefore your problem is entirely equivalent to figuring out a minimal set of edges you need to drop from athat directed graph to get athat directed acyclic graph. However as http://en.wikipedia.org/wiki/Feedback_arc_set says, this is a known NP hard problem called the minimum feedback arc set. begin update It is therefore very unlikely that there is a good algorithm for the graphs you can come up with. end update
If you need to solve it in practice, I'd suggest going for some sort of greedy algorithm. It won't always be right, but it will generally give somewhat reasonable results in reasonable time.
Update: Moron is correct, I did not prove NP-hard. However there are good heuristic reasons to believe that the problem is, in fact, NP-hard. See the comments for more.
There's a trivial reduction from Minimum Feedback Arc Set on directed graphs whose arcs can be arranged into an Eulerian path. I quote from http://www14.informatik.tu-muenchen.de/personen/jacob/Publications/JMMN07.pdf :
To the best of our knowledge, the
complexity status of minimum feedback
arc set in such graphs is open.
However, by a lemma of Newman, Chen,
and Lovász [1, Theorem 4], a
polynomial algorithm for [this problem]
would lead to a 16/9 approximation
algorithm for the general minimum
feedback arc set problem, improving
over the currently best known O(log n
log log n) algorithm [2].
Newman, A.: The maximum acyclic subgraph problem and degree-3 graphs.
In: Proceedings of the 4th
International Workshop on
Approximation Algorithms for
Combinatorial Optimization Problems,
APPROX. LNCS (2001) 147–158
Even,G.,Naor,J.,Schieber,B.,Sudan,M.:Approximatingminimumfeedbacksets
and multi-cuts in directed graphs. In:
Proceedings of the 4th International
Con- ference on Integer Programming
and Combinatorial Optimization. LNCS
(1995) 14–28