Repository navigation
Add a preflow–push maximum flow algorithm - #1082
Conversation
|
Wow, that is really fantastic. Thank you for implementing this and making such a beautiful pull request. |
These networks are generated using the same generators and parameters as in the 1st DIMACS Implementation Challenge. But they are not the same as the actual DIMACS instances due to different random numbers being used.
This ensures that during phase 1, if a node is found to be disconnected from the sink in the residual network, it will not be further processed until phase 2.
The interface is intended to be internal and for use in the minimum cut algorithm.
|
Hi ysitu, This is great! Thank you very much for your work. The Travis failures on your PR are because you did not add the actual It is very handy that you refactored your code to allow retrieving the residual network for minimum cut and friends. Given the benchmarks that you posted, I think we should use this implementation as the default in the Salut! |
|
I have no idea how to fix this. I did add the .bz2 files in ysitu/networkx@75d5c64. |
|
You may have to adjust the |
|
Ysitu, You are right, the files are included. I've only checked the Travis log and saw a "File not found error". You also have to edit |
There was a problem hiding this comment.
There are some DocTest failures in python 3 in lines like this. The order of the keys in dictionaries changes between python versions (and also between platforms). Maybe we could just skip the last two lines of the example and end with >>> flow, F = nx.preflow_push(G, 'x', 'y') or do something more elaborated such as:
print(flow)
for node, nbrs in sorted(F.items()):
print(node)
for n, value in sorted(nbrs.items()):
print(' {0} : {1}'.format(n, value))
There was a problem hiding this comment.
I noticed that, too. I have changed it to print just one entry.
There was a problem hiding this comment.
2014-03-24 16:39 GMT+01:00 ysitu [email protected]:
In networkx/algorithms/flow/preflow_push.py:
- Examples
import networkx as nx
G = nx.DiGraph()
G.add_edge('x','a', capacity=3.0)
G.add_edge('x','b', capacity=1.0)
G.add_edge('a','c', capacity=3.0)
G.add_edge('b','c', capacity=5.0)
G.add_edge('b','d', capacity=4.0)
G.add_edge('d','e', capacity=2.0)
G.add_edge('c','y', capacity=2.0)
G.add_edge('e','y', capacity=3.0)
flow, F = nx.preflow_push(G, 'x', 'y')
flow, F
- (3.0, {'a': {'c': 2.0}, 'c': {'y': 2.0}, 'b': {'c': 0, 'd': 1.0}, 'e': {'y': 1.0}, 'd': {'e': 1.0}, 'y': {}, 'x': {'a': 2.0, 'b': 1.0}})
I noticed that, too. I have changed it to print just one entry.
Great! That also works. Now all tests pass. I think this is ready to merge,
but maybe @loicseguin has some more comments.
Salut!
|
Did I just hit the wrong button? |
|
No worries - I'll reopen it. Or you can too. Thanks for helping fix all of the little details (tests). |
|
My bad. I thought that "Close" button was for closing the comment box. |
|
I do not have time to go over the code in details, but this sure looks pretty nice! I glimpsed over the code and did not see any obvious problems. The runtimes are great! Jordi, I think this can not only become the default for |
|
I believe that there is a bug in the |
This avoids explicitly forming a graph of unsaturated edges during global relabeling.
|
I think that the code is done. For some reason Sphinx does not run on my machine, so I do not know what the docs look like. But I suppose that it should be an easy fix should there be any doc problems. |
|
Ysitu, This is one of the best PR that we had at NetworkX, thank you again for this. Regarding the documentation, I've built it in my system and found a small issue; there are 3 typos in each docstring that prevent correct rendering. I'm not sure how to properly do a pull request on your pull request, so I add the patch below. The changes are minimal, it will probably be faster if you apply them by hand. Salut! |
|
Great! Now the doctrings render correctly. I think this is ready to merge. |
|
I'll merge this. Thank you for this great contribution @ysitu. I hope you will consider making other contributions in the future. |
Add a preflow–push maximum flow algorithm
I noticed that there was a two-year-old Issue (#550) about preflow–push (or push–relabel) algorithms, but apparently those algorithms were never included in any releases. Comments under the Issue showed some discouraging running times. But I think that it is still useful to have them integrated because many papers (e.g., [1]) have suggested the advantage of preflow–push algorithms over the Ford–Fulkerson algorithm.
I was unable to locate the implementations referenced in the Issue, so I went ahead to write one. I picked the highest-label variant with the global relabeling and gap heuristics.
Running compare_relabel.py from the Issue shows an improvement:
Running the 18 DIMACS cases used in [1] shows greater speedups for the larger ones:
Interestingly, the running times of the GL and WLM cases above, measured using Python 3.4 on a Xeon E5530, are longer than those found in [1], which were collected almost 20 years ago on a DECsystem 5000. I suspect that constant factor optimization is possible such as reducing dictionary lookups. But perhaps the user can take a look at a C++ implementation like Boost.Graph if he/she needs to deal with very large problems.
Reference