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

Maximum weight matching algorithms #25

Merged
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
c4c8401
Initial implementations for Gabow and Galil Micali Gabow
rkilar May 20, 2023
7b5b594
Work in progress augmentation handling
rkilar May 21, 2023
172a4bc
Add lazy path augmentation
rkilar May 22, 2023
7a79bb1
Finished MicaliGabow
rkilar Jul 17, 2023
32d21f1
Started Micali Vazirani algorithm
rkilar Jul 30, 2023
4a984b3
Change MV algorithm
rkilar Aug 2, 2023
23e0032
Changes to MV algorithm
rkilar Aug 3, 2023
acdfa72
MV fixed
rkilar Aug 9, 2023
16b3fce
Minor MV cleanup
rkilar Aug 9, 2023
308159b
Final MV cleanup
rkilar Aug 9, 2023
93b951d
Scaling algorithm done
rkilar Aug 22, 2023
5776de6
Minor scaling speedup
rkilar Aug 23, 2023
8cd96f9
Minor updates
rkilar Aug 23, 2023
74aaf88
Split find min implementation
rkilar Aug 29, 2023
edb764f
Clean up
rkilar Apr 24, 2024
91b913b
Minor fixes to maximum matching algorithms
rkilar Apr 25, 2024
07ae94f
Add comments, clean up unused code
rkilar Apr 27, 2024
9b74408
Add comments and documentation
rkilar Apr 30, 2024
0575749
Add comments for the scaling algorithm
rkilar May 1, 2024
b1a9d92
Update comments and names for the scaling algorithm
rkilar May 2, 2024
24b8258
Made names more consistent
rkilar May 5, 2024
8d6b979
Change some priority queues, fix naming
rkilar May 6, 2024
303cb35
Better naming
rkilar May 8, 2024
d54b111
Slight optimizations
rkilar May 8, 2024
cb2d86c
Optimize the Micali Gabow algorithm
rkilar May 9, 2024
37ec22f
Remove my scripts from gitignore
rkilar May 9, 2024
582dd08
Added tests for maximum matching algorithms
rkilar May 10, 2024
873c23e
Cleanup code
rkilar May 10, 2024
5c7f4a3
Rename algorithm to include all authors
rkilar May 12, 2024
06bae39
Merge branch 'master' into matching-algorithms
rkilar May 12, 2024
0ef9bd4
Change name of heap
rkilar May 13, 2024
edcd040
Update names
rkilar May 13, 2024
8aa441d
Remove debug code
rkilar May 13, 2024
7c347f2
Fix linter errors in header files, small fixes and cleanup
rkilar May 13, 2024
11965e3
Minor cleanup
rkilar May 13, 2024
5ea825a
Fix memory leaks and corner cases
rkilar May 13, 2024
665c3d3
Fix memory leaks in Galil Micali Gabow
rkilar May 14, 2024
221d9f8
Added thesis draft
rkilar Aug 15, 2024
fa0a87d
Small gabow scaling algorithm optimazation
rkilar Aug 15, 2024
c5598b6
Change names to be more consistent with thesis
rkilar Aug 15, 2024
691b7b8
Fix gabow scaling memory leaks
rkilar Aug 15, 2024
db8c351
Fix errors in the maximum matching text
rkilar Aug 18, 2024
07a9d59
Split matching data structures into separate files
rkilar Aug 18, 2024
eced01f
Clean up priority queue files
rkilar Aug 18, 2024
5bfb9e2
Added perfect matching options
rkilar Aug 21, 2024
0e35e2c
Add tests, fix linting errors
rkilar Aug 22, 2024
9067615
Added greedy optimization option for perfect matching
rkilar Aug 23, 2024
7903086
Improve benchmark output
rkilar Aug 23, 2024
8dc54f5
Add experimental results
rkilar Aug 30, 2024
d741dd9
Optimize Galil Micali Gabow algorithm
rkilar Aug 31, 2024
9e30b82
Further optimizations
rkilar Aug 31, 2024
88b0840
Optimize the array priority queue
rkilar Sep 1, 2024
77e9c32
Update experimental results summary
rkilar Sep 1, 2024
1c06bec
Initial text corrections
rkilar Sep 5, 2024
84286d7
Corrections draft
rkilar Sep 7, 2024
c3f2257
More corrections
rkilar Sep 7, 2024
8edd209
Remove shortened definitions
rkilar Sep 7, 2024
9b9ae46
Final corrections
rkilar Sep 7, 2024
8317b24
Final corrections
rkilar Sep 13, 2024
1c55436
Update figures
rkilar Sep 13, 2024
6d46fe1
Final final corrections
rkilar Sep 13, 2024
f124ecb
Bibliography typo fixes
rkilar Sep 13, 2024
ec8fad7
Revert some optimization to align with text
rkilar Sep 28, 2024
26a1c80
Clean up code
rkilar Sep 28, 2024
bf08528
Remove debug code
rkilar Sep 28, 2024
b2a1b6a
Update networkit
krzysztof-turowski Oct 8, 2024
442f10e
Apply style changes
krzysztof-turowski Oct 8, 2024
65331c9
Merge branch 'master' into pr/25
krzysztof-turowski Oct 8, 2024
fd9233a
Update networkit
krzysztof-turowski Oct 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,13 @@ koala_make_benchmark(
benchmark_independent_set
benchmarkIndependentSet.cpp
benchmarkIndependentSet.sh)

koala_make_benchmark(
benchmark_maximum_matching
benchmarkMaximumMatching.cpp
benchmarkMaximumMatching.sh)

koala_make_benchmark(
benchmark_mv

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, doesn't MV solve maximum matching as well?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to MaximumWeightMatching and MaximumMatching, respectively

benchmarkMicaliVazirani.cpp
benchmarkMicaliVazirani.sh)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add empty line at the end

In general, please run

cpplint --linelength=100 --extensions=cpp,hpp --filter=-legal/copyright,-build/c++20,-build/include,-build/namespaces,-build/header_guard,-runtime/references,-runtime/string --recursive --exclude=./backup --exclude=./build --exclude=./input --exclude=./lib --exclude=./cpp/flow/maximum_flow/dynamic_tree/*

and fix the style errors in your files

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

50 changes: 50 additions & 0 deletions benchmark/benchmarkMaximumMatching.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include <cassert>
#include <filesystem>
#include <iostream>

#include <matching/MaximumMatching.hpp>
#include <io/DimacsGraphReader.hpp>

int main(int argc, char **argv) {
if (argc < 3) {
std::cout << "Usage: " << argv[0] << " algorithm filename" << std::endl;
return 1;
}
std::string algorithm(argv[1]);
std::string path(argv[2]);
if (!std::filesystem::exists(path)) {
std::cout << "File " << path << " does not exist" << std::endl;
return 1;
}
auto G = Koala::DimacsGraphReader().read(path);
G.indexEdges(true);
Koala::MaximumWeightMatching* maximum_matching;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see e.g. benchmarkIndependentSet - I guess it's slightly cleaner to run run_algorithm<T>(G) with a proper T depending on the input params. At least you'd avoid unnecessary raw pointers.

if (algorithm == "edmonds") {
maximum_matching = new Koala::EdmondsMaximumMatching(G);
} else if (algorithm == "gabow") {
maximum_matching = new Koala::GabowMaximumMatching(G);
} else if (algorithm == "micali") {
maximum_matching = new Koala::GalilMicaliGabowMaximumMatching(G);
} else if (algorithm == "scaling") {
maximum_matching = new Koala::GabowScalingMatching(G);
} else {
std::cout << "Unknown algorithm: " << algorithm << std::endl;
return 1;
}
maximum_matching->run();
auto matching = maximum_matching->getMatching();
int weight = 0;
for (auto [u, v] : matching) {
std::cout << u << " " << v << std::endl;
if (v != NetworKit::none) {
assert(matching[v] == u);
assert(G.hasEdge(u, v));

weight += static_cast<int>(G.weight(u, v));
}
}
std::cout << weight / 2 << std::endl;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please extract it to a separate function


delete maximum_matching;
return 0;
}
1 change: 1 addition & 0 deletions benchmark/benchmarkMaximumMatching.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo "benchmarkMaximumMatching.sh $@"
32 changes: 32 additions & 0 deletions benchmark/benchmarkMicaliVazirani.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <cassert>
#include <filesystem>
#include <iostream>

#include <matching/MaximumMatching.hpp>
#include <io/DimacsGraphReader.hpp>

int main(int argc, char **argv) {
if (argc < 2) {
std::cout << "Usage: " << argv[0] << " filename" << std::endl;
return 1;
}
std::string path(argv[1]);
if (!std::filesystem::exists(path)) {
std::cout << "File " << path << " does not exist" << std::endl;
return 1;
}
auto G = Koala::DimacsGraphReader().read(path);
G.indexEdges(true);
Koala::MicaliVaziraniMatching MVmatching(G);
MVmatching.run();
auto matching = MVmatching.getMatching();
int size = 0;
for (auto [u, v] : matching) {
std::cout << u << " " << v << std::endl;
if (v != NetworKit::none && u < v)
size ++;
}
std::cout << size << std::endl;

return 0;
}
1 change: 1 addition & 0 deletions benchmark/benchmarkMicaliVazirani.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo "benchmarkMicaliVazirani.sh $@"
1 change: 1 addition & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ add_subdirectory(mst)
add_subdirectory(recognition)
add_subdirectory(set_cover)
add_subdirectory(traversal)
add_subdirectory(matching)
Loading