Determining minimum flow in graph with least cost given condition - algorithm

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.

Related

Rate node connectedness in a routing graph

I have a directed, weighted routing graph (ca. 10^5 edges, 4 edges per node, lots of circles).
Each edge has a cost associated with it. How can I rate the "connectedness" of each node? It should be a measure of how cheap it is to reach other nodes from this one.
How does everything change if every node gets a reliability factor (the probability that the chosen path containing that node will fail and a new one must be found)?
Thanks for your help
I believe that the problem you've put forth in many terms matches the use case of the PageRank algorithm.
I won't discuss how the algorithm works in general since there are a lot many blogs/videos available online which already explains it in great detail. One of my personal favourite short video on the same is this.
Now lets see how does the algorithm fits for your use case. Let's define connectedness of a node x as C(x). We can rephrase your given statement "how cheap it is to reach other nodes from this node" to "how likely are we to end up on the given node in a random walk across the graph such that we are biased to take edges whose costs are less".
The statement to a large extent relates to the ideology behind the PageRank algorithm. We just need to consider how to include the edge cost for our working.
The original PageRank algorithm uniformly divides the page rank of a given node to all it's adjacent node (denoted as PR(y) / OUT(y) in formula). We on the other hand needs to be more biased towards edges with lower cost for which I'll recommend modifying the formula to,
(SUM-EDGES-COST(y) - EDGE-COST(x, y)) * (C(y) / SUM-EDGES-COST(y))
instead of the traditional C(x) / OUT(x). We take the difference (SUM-EDGES-COST(y) - EDGE-COST(x, y)) since in our scenario lower edge cost means more connectedness. Another possibility is to apply softmax function to the edge cost for each node as a normalisation strategy.
As to answer the part about having a reliability factor, given by R(x) for a node x, we can just multiply it directly to C(x) in the formula.
To wrap things up,
should match your given scenario.
What I've presented here is just one possibility which I can think from the top of my mind and it's highly likely that it just might not work out. All I can hope is that it helps you out in some or the other way. Cheers! :)

Algorithm: Check if max flow is unique

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.

Find a maximum matching

Let G(A,B,V), a bipartite graph where |A|=|B|=n. There's a matching, M subset of E where |M| = n-2013. Describe an efficient algorithm to determine if a maximal matching exists.
Basically the given solution is building a flow-network from the graph, by adding s,t vertices, connecting s to each vertex v in A and each vertex v in B to t. All capacities are 1.
Now, we give a starting flow for all edges M (And all edges connected to edges of M, from s and to t)
Now we just need to run Fold-Falkerson (or Edmond-Karp) Algorithm and check if we were able to improve 2013 paths (i.e. adding more flow for some path). More precisely, we need, at most, to run BFS, 2013 times to decide
My question is:
Why does it work? As I see it, M is just an arbitrary match. It's like we are assuming that M is part of a maximal-matching.
I'd be glad for a clarification!
Thanks
IIUC, the algorithms is this:
Create the flow network s → A → B → t
On this network, calculate the flow induced by M.
Now create the residual flow graph, and continue Edmonds-Karp from here.
Why does this work? The Ford-Fulkerson method guarantees that, given any valid flow (in particular, in this case the one given by M, while the maximal flow is not yet achieved, there is an augmenting path in the residual network. Here, each augmentation increases the flow (and hence the matching) by 1. Hence, if the maximal flow is q, then within q - |M| iterations, it will be achieved.
The point which seems to confuse you is that it seems that the optimal matching necessarily includes M. This is not the case. Augmentation along the residual network can actually cancel flows in the original network. Hence, the augmentations can actually "reverse" some of the matchings of M.

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?

Resources