5

I have a directed graph with flow volumes along edges and I would like to simplify it by removing all cyclic flows. This can be done by finding the minimum of the flow volumes along each edge in any given cycle and reducing the flows of every edge in the cycle by that minimum volume, deleting edges with zero flow. When all cyclic flows have been removed the graph will be acyclic.

For example, if I have a graph with vertices A, B and C with flows of 1 from A→B, 2 from B→C and 3 from C→A then I can rewrite this with no flow from A→B, 1 from B→C and 2 from C→A. The number of edges in the graph has reduced from 3 to 2 and the resulting graph is acyclic.

Which algorithm(s), if any, solve this problem?

General Grievance
  • 4,555
  • 31
  • 31
  • 45
J D
  • 48,105
  • 13
  • 171
  • 274
  • 3
    Didn't you just describe the algorithm for that? – Lasse V. Karlsen Mar 20 '11 at 19:14
  • @Lasse: You mean my example? I can see intuitively what needs to be done by studying a given graph with pencil and paper but I cannot formalise my intuitive approach in order to automate the procedure. – J D Mar 21 '11 at 20:16

4 Answers4

5

You may find it useful to use the flow decomposition theorem (see §6.2 of this discussion of max-flow), which says that any flow can be broken down into a set of flow paths and flow cycles. Moreover, there can be at most m total flow paths and cycles in the graph. This means that one simple algorithm for eliminating flow cycles would be to find all of the flow paths in the graph, then remove all remaining flow in the graph since it must correspond to flow cycles.

To find a flow path or cycle, you can use a simple depth-first search from the source node. Starting at the source node, keep following edges however you'd like until either you hit the terminal node or you visit a node you've previously visited. If you hit the terminal node, then the path you've taken is a simple flow path. If you encounter some node twice, you've just found a flow cycle (formed by the loop that you just found). If you then remove the flow path/cycle from the graph and repeat, you will end up detecting all flow paths and cycles. You know that you're done when there are no flow-carrying edges leaving the source code. If each time that you find a flow path you record the total flow across all of its edges, you can eliminate cyclic flow by repeating this until no flow paths remain, clearing the flow in the network, then adding back in the flow paths.

Since each DFS takes time O(m + n) and there are at most O(m) flow paths, the total runtime of this step is O(m2 + mn), which is a polynomial in the size of the graph.

Hope this helps!

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
2

You could use topological sorting http://en.wikipedia.org/wiki/Topological_sorting

It works great when it comes to finding a cycles in directed graphs

Berial
  • 557
  • 1
  • 8
  • 23
  • Topological sorting is only possible in an acyclic graph. If the graph has cycles, by definition it can't be topologically sorted. – templatetypedef Mar 20 '11 at 19:28
  • Thanks to this You can detect cycles – Berial Mar 20 '11 at 19:35
  • Ah, my mistake... I misread your post. I'm trying to remove my downvote but I can't do so without the post being edited; could you make some minor change so that I can upvote this answer? – templatetypedef Mar 20 '11 at 19:39
  • 1
    Is it possible with topological sorting to find a minimal cycle? For instance, what if you have a->b->c as given, but also b->d->c, how do you find the two cycles separately? Or would that be wrong for this approach in either case? – Lasse V. Karlsen Mar 21 '11 at 13:02
2

You can compute the value V of a flow given and then solve a min-cost flow problem for the network given and flow value V, assigning cost 1 to each edge.

Then a resulting flow should not contain any cycles, since that would be non-optimal (with respect to cost).

Marat Salikhov
  • 6,367
  • 4
  • 32
  • 35
  • Cycle cancellation is apparently a known technique for solving the min-cost flow problem. However, Google turns up little on this subject. Any ideas? – J D Mar 26 '11 at 15:18
  • Hang on, min-cost flow is subtly different. I want to reduce total flow by cancelling cycles but min-cost flow minimizes cost whilst conserving flow. In fact, min-flow with all costs equal would do nothing at all. – J D Mar 30 '11 at 22:24
0

Have you thought about producing a minimum spanning tree? you could use Dijkstra's algorithm for that. If you want to first find out if a graph is cyclic you can determine that by using topological sorting.

David Božjak
  • 16,887
  • 18
  • 67
  • 98
  • 1
    I don't see how MSTs (or even general spanning trees) are useful here, as this is a directed graph and the goal is to find cycles. – templatetypedef Mar 20 '11 at 19:27
  • 1
    Dijkstra is not for finding a mst but a shortest path but I have problem to understand the logic behind. – Micromega Mar 22 '11 at 17:30