Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This implementation is based on the Java Hackpack's Dinic and KACTL's Dinic. I used techniques/speedups from both and merged them into what I think is a really good flow implementation. It comes out to about 50 lines for just the max flow code, without recovering the flow or any other extra stuff.
Tested on:
Recovering the flow is a bit different, since I avoided using edge pointers.
add()
will return an ID for that edge, and you can get a reference to thatEdge
object by callingget()
with that ID. Seetesting/graphs/Dinic_ReactorCooling.cpp
for an example.circulation()
is also a bit different. There is an optional parameter for vertex demands, where you can specify how much flow is coming in/out of any node (default zero). Ifcirculation()
returns true, it will modify the original graph so that the flow through all the edges satisfy all the edge/vertex demands. Seetesting/graphs/Dinic_ReactorCooling.cpp
for an example.Let me know any thoughts/comments/suggestions you have, so this implementation can be made even better.