Блог пользователя ouuan

Автор ouuan, история, 7 лет назад, По-английски

Many people think they know how to solve the min-cost-max-flow problem, but most of them only know how to solve it with pseudo-polynomial time algorithm (although it usually runs very fast). And in this blog, min_25 provided a counter case generator, most people's MCMF algorithm runs in $$$O(2^{\frac n 2}n^2\log n)$$$ on it.

the counter case

I tried to find learning materials of polynomial minimum cost flow algorithms, but I can only find papers like A Faster Strongly Polynomial Minimum Cost Flow Algorithm and Theoretical Improvements in Algorithmic Efficiency for Network Flow Problems, and I can't understand them very well.

Are there any other learning materials besides the papers? Thanks in advance.

UPD. I've learned an algorithm with time complexity of $$$O(m^2\log U\log m)$$$ ($$$U$$$ refers to the maximum capacity), for Chinese and those who want to see my code, I wrote a blog; for those who want English learning materials, the one mentioned in Laakeri's comment is good.

  • Проголосовать: нравится
  • +179
  • Проголосовать: не нравится

»
7 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

cp-algorithms has an article for Dinic's.

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +25 Проголосовать: не нравится

I am a bit confused here. According to CP-Algorithms, if we use the Edmonds-Karp algorithm with Bellman-Ford in order to find the lowest-cost path between the source and the sink vertices, then the complexity is $$$O(n^2m^2)$$$, where $$$n$$$ is the number of vertices and $$$m$$$ is the number of edges. Where are you getting this $$$O(2^{n/2}n^2\log n)$$$ complexity from?

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +19 Проголосовать: не нравится

While I've only seen in described in papers, I've found the successive approximation algorithm by Goldberg and Tarjan a natural generalization of the push relabel algorithm (it also uses a height function and push and relabel operations). The paper Solving Minimum-Cost Flow Problems by Successive Approximation on it should be easier to read than the two you linked, especially if you're familiar with push-relabel. The algorithm runs in $$$O(n^3 \log(n C))$$$ where $$$C$$$ is the maximum edge cost (so it's polynomial in the input size but not strongly polynomial) and it is fast in practice.

IIRC you can do capacity scaling with the successive shortest path algorithm (linked on CP-Algorithms above) to get something like $$$O(m^2 \log n \log U)$$$ where $$$U$$$ is the largest edge capacity. This would also be polynomial but not strongly polynomial. This algorithms might be easier to understand as you can first study both components (the capacity scaling and the successive shortest paths) separately.

  • »
    »
    7 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +16 Проголосовать: не нравится

    Thank you very much! I watched a video and I think now I understand the basic idea of capacity scaling.

  • »
    »
    7 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +8 Проголосовать: не нравится

    Won't scaling for min cost max flow possibly create negative cycles?

    • »
      »
      »
      7 лет назад, скрыть # ^ |
       
      Проголосовать: нравится +34 Проголосовать: не нравится

      Sure, so I guess it's not that simple. At the start of each scaling phase, let's add edges that now get a positive capacity one by one and at each point check whether it is included in a negative cycle and update the potentials so that we have no negative edges. (And only look for augmenting paths after adding all edges). Note that the newly added edge is the only edge with negative reduced weight, so this check boils down to running Dijkstra's algorithm to find a path from one endpoint of the edge to the other one (similarly to how we find the augmenting paths).

      Equivalently, we could saturate all newly added edges which have negative reduced weight. This creates some excesses and deficits, which we resolve by finding augmenting paths. As we saturated all negative edges, we only deal with edges of non-negative costs, so we can keep using Dijkstra's. (This involves at most $$$m$$$ augmenting paths, so the runtime remains the same.)

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +13 Проголосовать: не нравится

https://web.stanford.edu/class/cs361b/files/cs361b-notes.pdf — this material has an in-depth explanation about a capacity scaling mincost flow algorithm that has $$$O(m^2 \log U)$$$ time complexity. I have implemented the algorithm in here.

  • »
    »
    7 лет назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится +10 Проголосовать: не нравится

    Could you please explain the "fixPotentials" function (especially how does it avoid the overflow, and the range of potentials after fixing)? Or is it in the notes (the pdf)? I have just read the first 19 pages.

    I tried to implement the capacity scaling algorithm mentioned in Theorem 3.1 but failed, because there are many places which need "sufficiently large number"s, and the relationship of these "sufficiently large number"s are really confusing, overflow may also happen. I read your implementation and found the "fixPotentials" function which may help.

    • »
      »
      »
      7 лет назад, скрыть # ^ |
      Rev. 2  
      Проголосовать: нравится +8 Проголосовать: не нравится

      You are right. The issue with the algorithm is that there is no proof about how the values of the potential function behave, and in naive implementations they might grow exponentially during the algorithm.

      The fixPotentials function is intended to fix this issue. I wrote it 3 years ago, so I don't remember details anymore, but my documentation (which is written in finnish) says that it works in $$$O(m \log n)$$$ time, and after running it, the maximum absolute value of a potential will be $$$nC$$$, where $$$C$$$ is the maximum absolute value of a cost in the input.

      Here is my old description of the fixPotentials function: Select a vertex $$$v$$$ whose potential has not been fixed yet. Then compute the shortest paths (with the old potential function) from $$$v$$$ using only the vertices that are not fixed yet. For all vertices $$$u$$$ reached from $$$v$$$, set the new potential $$$p(u)$$$ as the length of the shortest path from $$$v$$$ + the greatest fixed potential before this stage. Repeat this process until all vertices have been fixed.