Is there any good implementation of minimum cost maximum flow with negative cycles? Can someone please share their implementation. Also, could you please give the complexity as well.

Thanks in Advance

# | User | Rating |
---|---|---|

1 | ecnerwala | 3648 |

2 | Benq | 3580 |

3 | orzdevinwang | 3570 |

4 | cnnfls_csy | 3569 |

5 | Geothermal | 3568 |

6 | tourist | 3565 |

7 | maroonrk | 3530 |

8 | Radewoosh | 3520 |

9 | Um_nik | 3481 |

10 | jiangly | 3467 |

# | User | Contrib. |
---|---|---|

1 | maomao90 | 174 |

2 | awoo | 164 |

2 | adamant | 164 |

4 | TheScrasse | 160 |

5 | nor | 159 |

6 | maroonrk | 156 |

7 | SecondThread | 150 |

8 | -is-this-fft- | 149 |

9 | pajenegod | 146 |

10 | BledDest | 144 |

Is there any good implementation of minimum cost maximum flow with negative cycles? Can someone please share their implementation. Also, could you please give the complexity as well.

Thanks in Advance

↑

↓

Codeforces (c) Copyright 2010-2024 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Apr/15/2024 19:21:36 (l3).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

I think it is NP hard since it can be used to solve the Hamiltonian Path problem. I'll let someone who is more well versed with the theory correct me on this.

What if we have unit capacity edges?

For sure it isn't NP-Hard (unless P = NP), since there exists linear programming formulation for the problem, and there exists poly-time algorithm to solve linear programs.

The reason it can't solve the Hamiltonian path is that under the definition of the max-flow problem it is legal to send flow along a cycle that is not reachable from the source or from which the sink is not reachable. This way, on a graph with a hamiltonian path if you assign -1 weight to each edge and run the min-cost maxflow algorithms, it will find a single path and multiple cycles in such a way that each vertex belongs to either the path or exactly one cycle. If you are lucky the number of cycles will be zero (and thus you'll find the hamiltonian path), but it doesn't have to be the case.

The way you do it is:

Connect the sink to the source with an edge with infinite capacity and negative infinity cost

For as long as there's a negative cycle in the graph, increase the flow along that cycle by a constant (similar to Ford-Fulkerson you'd introduce reverse edges for all the edges for which the flow was increased).

I don't have an implementation handy, but I remember that the only implementation for mincost maxflow in this book:

https://www.amazon.com/Algorithms-Part-Graph-3rd-Pt-5/dp/0201361183

was exactly that in case you can find it online or among your friends.

Beware that this gives a min cost circulation, and not a min cost max flow (i.e., there might be flow that just “is there”, going in a circle, with no way of it getting there in the first place. That might be a problem depending on what you want. In case you don’t want that, you can get the flow value by summing the flow going through S, but the flow function itself has to be recomputed. Also, the cost is not correct.

What you could do in this case is just find a correct flow (which is a subflow of what your algo outputs), and get its cost.

I’m not sure what I’m proposing is coreect, but I’m pretty confident that it should be.

EDIT: In fact, it

mustbe wrong, because that would solve Hamiltonian cycle. Still, the subtlety here is important to understand.This is possible and can be solved.The idea involves

1.first removing negative cycles by finding negative cycles using bellman ford as long as there is a negative cycle. this should terminate in finite steps because the min cost is bounded.

2.after all negative cycles are removed then we can run standard mincost max flow which allows negative edges.

Here the complexity seems to contain some sort of absolute value of mincost possible or something like that (though not a tighter bound.the above bound is highly intuitional)

MY DOUBT: Can we do any sort of scaling technique here as in max flow porblems to remove linear dependency on min cost possible.

There is an algorithm based on push-relabel and successive approximation that solves the min-cost circulation problem in where

Cis the maximal edge cost. (Edge costs are assumed to be integers.) I think the original paper is "FINDING MINIMUM-COST CIRCULATIONS BY SUCCESSIVE APPROXIMATION" by Andrew V. Goldberg and Robert E. Tarjan.The algorithm alternates two steps: Pushing along each edge that is steeper that ε to get a -optimal pseudoflow and running push relabel to then get a -optimal circulation. This is repeated until .

To solve a min-cost-max-flow problem, first get any max-flow, then solve the min-cost circulation problem on the residual graph. (You could alternatively add a

t→sedge of cost - ∞ and capacity ∞ and just run the min-cost-circulation).My implementation is on github. It's quite fast in practice, I've used it for

V=E= 10^{4}or dense bipartite matching problems withV= 10^{3},E= 10^{6}.Can you give any link to problems requiring mincost maxflow on graphs with negative cycles on any online judge?

There is a problem in UOJ.