Algorithm: Check if max flow is unique - algorithm

A question to the following exercise:
Let N = (V,E,c,s,t) be a flow network such that (V,E) is acyclic, and let m = |E|. Describe a polynomial-
time algorithm that checks whether N has a unique maximum flow, by solving ≤ m + 1 max-flow problems.
Explain correctness and running time of the algorithm
My suggestion would be the following:
run FF (Ford Fulkerson) once and save the value of the flow v(f) and the flow over all egdes f(e_i)
for each edge e_i with f(e_i)>0:
set capacity (in this iteration) of this edge c(e_i)=f(e_i)-1 and run FF.
If the value of the flow is the same as in the original graph, then there exists another way to push the max flow through the network and we're done - the max flow isn't unique --> return "not unique"
Otherwise we continue
we're done with looping without finding another max flow of same value, that means max flow is unique -> return "unique"
Any feedback? Have I overlooked some cases where this does not work?

Your question leaves a few details open, e.g., is this an integer flow graph (probably yes, although Ford-Fulkerson, if it converges, can run on other networks as well), and how exactly do you define whether two flows are different (is it enough that the function mapping edges to flows be different, or must the set of edges actually flowing something be different, which is a stronger requirement).
If the network is not necessarily integer flows, then, no, this will not necessarily work. Consider the following graph, where, on each edge, the number within the parentheses represents the actual flow, and the number to the left of the parentheses represents the capacity (e.g., the capacity of each of (a, c) and (c, d) is 1.1, and the flow of each is 1.):
In this graph, the flow is non-unique. It's possible to flow a total of 1 by floating 0.5 through (a, b) and (b, d). Your algorithm, however, won't find this by reducing the capacity of each of the edges to 1 below its current flow.
If the network is integer, it is not guaranteed to find a different set of participating edges than the current one. You can see it through the following graph:
Finally, though, if the network is an integer flow network, and the meaning of a different flow is simply a different function of edges to flows, then your algorithm is correct.
Sufficiency If your algorithm finds a different flow with the same total result, then obviously the new flow is legal, and, also, necessarily, at least one of the edges is flowing a different amount than it did before.
Necessity Suppose there is a different flow than the original one (with the same total value), with at least one of the edges flowing a different amount. Say that, for each edge, the flow in the alternative solution is not less than the flow in the original solution. Since the flows are different, there must be at least a single edge where the flow in the alternative solution increased. Without a different edge decreasing the flow, though, there is either a violation of the conservation of flow, or the original solution was suboptimal. Hence there is some edge e where the flow in the alternative solution is lower than in the original solution. Since it is an integer flow network, the flow must be at least 1 lower on e. By definition, though, reducing the capacity of e to at least 1 lower than the current flow, will not make the alternative flow illegal. Hence some alternative flow must be found if the capacity is decreased for e.

non integer, rational flows can be 'scaled' to integer
changing edges capacity is risky, because some edges may be critical and are included in every max flow
there is a better runtime solution, you don't need to check every single edge.
create a residual network (https://en.wikipedia.org/wiki/Flow_network). run DFS on the residual network graph, if you find a circle it means there is another max flow, wherein the flow on at least one edge is different.

Related

Given a flow network and a max flow f on it, Determine whether there are at least 4 different max flows

I'm having trouble solving this one and would really appreciate any help. thank you in advance!
so, the problem is:
given a flow network with integer capacities on the edges and a max flow f on that network, I need to write an algorithm (efficient one) that determine whether there are at least 4 more different max flows on that given network.
I have seen people suggesting to check for cycles in the residual network. so if there is a cycle, the max flow is not unique, hence, there is another max flow "f2" and than we can choose every 0 < x < 1 and set infinite max flows such as (1-x)(|f|) + x|f2|.but, I cant seem to understand why the cycles in the residual network means that the max flow is not unique and also have a really hard time proving the second part is legal. (the infinite max flows)
thanks again!
The idea with the cycles seems correct. A network N has multiple distinct max flows if and only if the residual graph of the max flow contains a cycle. If there is more than one max flow there are infinitely many.
If there is a cycle in the residual graph we can augment the flow along that cycle obtaining a different flow. More precisely, let C be a cycle in the residual graph of a max flow. Let d > 0 denote the smallest residual capacity of an edge of cycle C. We can augment the flow on cycle C by any amount in the interval [0, d] each time obtaining a different max flow (so there are indeed infinitely many max flows, to get four you can augment the flow along cycle C by four arbitrary, distinct values from the interval).
We still have to prove that if there are multiple different maximum flows in a network there will indeed always be a cycle in the residual network of any max flow on that network. Doing that in a mathematically rigorous way can be a bit cumbersome, but the main idea is the following: take two distinct max flows F1 and F2 and compute the difference between them (i.e. for every edge e compute F1(e) - F2(e)). Consider the edges where the difference is non-zero. Those edges will all be present in the residual graph of flow F1 (if the sign of the difference is negative the edge in the direction of flow won't be saturated, if the sign is positive the reverse direction will be present). The conservation of flow constraints at each vertex guarantee that those edges will always form a cycle. For an intuitive understanding you can visualize this drawing both the two flows F1 and F2 on the same network in two different colors. You will see that the edges where the flows differ always form cycles. Obviously the flows intersect (at least at source and sink) and from some intersections you will have a path where one flow is greater on one edge and a path where the other flow is greater on another edge. Those two paths must intersect again somewhere deeper in the network (at the latest at the sink but it could also be before), and therefore form a cycle.
Using this, the most efficient algorithm I can think of would be:
Compute the residual graph
Use DFS to check if there is a cycle in the residual graph (you will probably have to run the DFS multiple times since the residual graph consists of multiple components separated by min cuts)
If you have to, generate four different max flows augmenting the flow along the found cycle by different amounts
This would be linear both in the number of vertices and edges

Minimum flow in a network with lower bounds - what am I doing wrong?

The problem that I am trying to solve is as follows:
Given a directed graph, find the minimum number of paths that "cover" the entire graph. Multiple paths may go through the same vertice, but the union of the paths should be all of them.
For the given sample graph(see image), the result should be 2 (1->2->4, and 1->2->3 suffice).
By splitting the vertices and assigning a lower bound of 1 for each edge that connects an in-vertex to an out-vertex, and linking a source to every in-vertex and every out-vertex to a sink (they are not shown in the diagram, as it would make the whole thing messy), the problem is now about finding the minimum flow in the graph, with lower bounds constraints.
However, I have read that in order to solve this, I have to find a feasible flow, and then assign capacities as follows : C(e) = F(e) - L(e). However, by assigning a flow of 1 to each Source-vertex edge, vertex-Sink edge, and In-Out edge, the feasible flow is correct, and the total flow is equal to the number of vertices. But by assigning the new capacities, the in-out edges (marked blue) get a capacity of 0 (they have a lower-bound of 1, and in our choosing of a feasible flow, they get a flow of 1), and no flow is possible.
Fig. 2 : How I choose the "feasible flow"
However, from the diagram you can obviously see that you can direct a 2-flow that suffices the lower-bound on each "vertex edge".
Have I understood the minimum flow algorithm wrong? Where is the mistake?!
Once you have the feasible flow, you need to start "trimming" it by returning flow from the sink back to the source, subject to the lower bound and capacity constraints (really just residual capacities). The lower two black edges are used in the forward direction for this, because they don't have flow on them yet. The edges involving the source and the sink are used in reverse, because we're undoing the flow already on them. If you start thinking about all of this in terms of residual capacities, it will make more sense.

A network flow with different constraints

Considering a simple network flow model: G = (V,E), source node S, and sink node T. For each edge E[i], its capacity is C[i].
Then the flow F[i] on edge E[i] is constrained to be either C[i] or 0, that is, F[i] belongs to {0, C[i]}.
How to compute the maximum flow from S to T? Is this still a network flow problem?
The decision variant of your modified flow problem is NP-complete, as evidenced by the fact that the subset sum problem can be reduced to it: For given items w_1, ..., w_n and a sum W, just create a source S connected to every item i via an edge S -> i of capacity w_i. Then connect every item i to a sink t via another edge i -> t of capacity w_i. Add an edge t -> T of capacity W. There exists a subset of items with cumulative weight W iif the S-T max-flow in the graph is W with your modifications.
That said, there is likely no algorithm that solves this problem efficiently in every case, but for instances not specifically designed to be hard, you can try an integer linear program formulation of the problem and use a general ILP solver to find a solution.
There might be a pseudopolynomial algorithm if your capacities are integers bounded by a value polynomial in the input size.
Um, no its no longer a well defined flow problem, for the reason that Heuster gives, which is that given two edges connected through a node (with no other connections) the flow must be zero unless the two capacities equal each other. Most generic flow algorithms will fail as they cannot sequentially increase the flow.
Given the extreme restrictivity of this condition on a general graph, I would fall back on a game tree working backwards from the sink. Most nodes of the game tree will terminate quickly as there will be no combination of flows into a node that exactly match the needed outflows. With a reasonable heuristic you can probably find a reasonable search order and terminate the tree without having to search every branch.
In fact, you can probably exclude lots of nodes and remove lots of edges before you start, on the grounds that flows through certain nodes will be trivially impossible.

Max Flow Linear time algorithm, Find a valid flow

So let me explain the question:
You are given a graph. You find the max flow. But it turns out that an edge, e_i, had the wrong capacity. It had one less. Unfortunately, the flow was maxed out at the old capacity.
Compute the new max flow in linear time (in terms of the number of edges and vertices) once you are told e_i had the wrong capacity.
Here's my plan: (1) You can't only drop the flow at edge e_i by one at an edge because you must violate certain constraints: like flow is conserved at an edge. Fix the flows so you can get a valid flow. But how?
(2) Someone has given me a hint: it will be helpful to show the valid flow = previous flow -1.mmm...
Help.
Here's a couple of tips:
Suppose you found a path with nonzero flow (i.e >= 1), and contained this edge e_i. How might you use this path to make the overall flow valid again? Now, suppose you aren't given this path. How might you get it yourself?
Now, you know that the max flow of the new graph is either the same, or one less than before (why?). How might you find out which in linear time?

Determining minimum flow in graph with least cost given condition

I am recently preparing for the acm-icpc contest. Here I want to know how to find the minimum
flow with the least cost given the condition that each edge in the graph has a capacity C, a cost V, and a lowerbound flow L (L ≤ C).
First, I'm not sure what "minimum flow with the least cost" means, but I suspect you just mean "flow with the least cost".
Second, the lower bound flows means it is non-trivial to find an "legal flow", which is a flow where conservation of mass is respected, i.e. the sum of the inbound flows is equal to the sum of the outbound flows for all nodes except the source and the sink. (Usually flow problems have L=0 which means that the zero flow is legal.) In fact, there are choices of L and C for which no legal flow exists.
I think you could find a legal flow by starting with a flow which is equal to L on each edge. Some nodes in the graph will then have a surplus flow, and some will have a deficit flow. You can augment the flow by finding a (below capacity) path from a surplus node to a deficit node and pushing more flow along that path. Repeat until all surpluses are zero, or you can't find such a path (in which case no legal flow exists).
Once you find an admissible flow, then Ford-Fulkerson or preflow-push algorithms can then optimize your flow (modify it to lower total cost).
and good luck on your competition!
I'm a little concerned that the first solution proposed can, at best, help you find minimum max flow, which is on track to what you're looking for, but not quite the same.
I took a class taught by Robert Tarjan. He happens to have helped develop a method of deriving minimum flows called: "cycle canceling". Here is a great lecture posted by Kevin Wayne, a senior lecturer at Princeton (with Tarjan): http://www.cs.princeton.edu/~wayne/papers/ratio_talk.pdf
Min-mean circuit canceling in particular will help you to find min flows.
If you look over those two papers and still would like to discuss, please let me know.
I think your question is not well specified.
Are C, L and V single constant that apply to all edges or are they vector?
Since you are providing a minimum flow for edges, I am assuming your graph has directed edges
such that flow is possible only in one direction. The other point that needs clarification is that the cost V, is it per unit of flow? I am assuming yes, since otherwise the cost of any flow would be E.V for L > 0.
So with those assumptions, you want min cost circulation problem.

Resources