Skip to content
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

Mincut #105

Merged
merged 13 commits into from
Aug 28, 2023
Merged

Mincut #105

merged 13 commits into from
Aug 28, 2023

Conversation

etiennedeg
Copy link
Member

The implementation was mostly wrong. It was doing a single max adjacency visit, whereas Stoer Wagner do multiple cut of the case, shrinks two vertex at each phase, and repeat until there is one vertex remaining. I optimized Stoer Wagner a bit with the simple realization that an edge can be contracted if its weight is higher than the current mincut. Each additional merged edge spare a whole minimum cut phase. As the graphs shrinks, edge weights sum up, so more and more edges can be merged.

I also fixed a bug in max adjacency visit when the graph contains loops.

@codecov
Copy link

codecov bot commented Feb 15, 2022

Codecov Report

Merging #105 (384ba30) into master (745add6) will increase coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #105      +/-   ##
==========================================
+ Coverage   97.19%   97.20%   +0.01%     
==========================================
  Files         114      114              
  Lines        6656     6701      +45     
==========================================
+ Hits         6469     6514      +45     
  Misses        187      187              

@simonschoelly
Copy link
Contributor

I haven't had time to refresh my memory on min-cut algorithms, but I was wondering, was the old algorithm just incorrect for weighted graphs or are there also unweighted graphs where it would perform incorrectly?

The reason am asking is, that your new implementation allocates quite a lot of memory, so it will probably not as efficient anymore. Still your regression test shows that the old implementation was incorrect and being correct is better than being efficient.

@etiennedeg
Copy link
Member Author

etiennedeg commented Feb 20, 2022

The old implementation was very wrong and failing also for unweighted graphs (see the example provided in the original issue). It is expected that the new implementation is much slower than the previous one, but it might be possible that it can be implemented more efficiently, merging vertices is a quite delicate operation to do efficiently. I also fixed a bug for graphs with self-loops and also for directed graphs. It is possible to be a bit more efficient for dense graphs, and for undirected graphs but not that much. Maybe it is worth specializing, I don't know...

@etiennedeg
Copy link
Member Author

Just realized that Stoer-Wagner does not work on directed graphs, reverted the commit and disabled the function for directed graphs.

@gdalle gdalle added the bug Something isn't working label Jun 16, 2023
@gdalle gdalle added this to the v1.9 milestone Jun 28, 2023
@etiennedeg
Copy link
Member Author

I added a new heuristic. During a phase, the connection of a non visited vertex with the visited vertices is a lower bound on the size of the minimal cut between this vertex and the last visited vertex. If the connection is higher than the best mincut found, we can already merge these two vertices, saving one cut of the phase. This is a much better heuristic than the one I described above in this PR. I also fixed many things (I really don't know what the heck I did in my last commit, I added a check to guarantee the validity of @inbounds, I corrected the initialization of the phase)

@etiennedeg etiennedeg force-pushed the mincut branch 2 times, most recently from b5b139c to 81dc65e Compare July 4, 2023 15:27
@gdalle
Copy link
Member

gdalle commented Jul 27, 2023

This bug has been standing there for far too long, so given @etiennedeg's track record I'd be in favor of merging even though I haven't delved into the algorithm details.

One thing I'd like to understand though is how the new test ensures non regression vis-à-vis sbromberger/LightGraphs.jl#1589, since they appear to be different graphs

@etiennedeg
Copy link
Member Author

The bug was due to the fact that the algorithm was never doing merging logic. The example is built such that it can't be solved without using the merging logic, no matter what starting vertex and what lexicographic ordering of the vertices is chosen, so it should do a much better job as ensuring there is no regression.

@gdalle gdalle merged commit e8f3a49 into JuliaGraphs:master Aug 28, 2023
12 checks passed
@etiennedeg etiennedeg deleted the mincut branch May 7, 2024 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants