Skip to content

Added Dinic #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Added Dinic #15

wants to merge 3 commits into from

Conversation

lightseba
Copy link
Contributor

@lightseba lightseba commented Nov 23, 2020

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 that Edge object by calling get() with that ID. See testing/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). If circulation() returns true, it will modify the original graph so that the flow through all the edges satisfy all the edge/vertex demands. See testing/graphs/Dinic_ReactorCooling.cpp for an example.

Let me know any thoughts/comments/suggestions you have, so this implementation can be made even better.

@lightseba lightseba added the new-code label for issues which discuss new code for the hackpack label Nov 23, 2020
@lightseba lightseba self-assigned this Nov 23, 2020
@Xylenox
Copy link
Contributor

Xylenox commented Nov 24, 2020

Looks good, but have you considered porting it to Kotlin?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-code label for issues which discuss new code for the hackpack
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants