-
Notifications
You must be signed in to change notification settings - Fork 9
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
Changes from 37 commits
c4c8401
7b5b594
172a4bc
7a79bb1
32d21f1
4a984b3
23e0032
acdfa72
16b3fce
308159b
93b951d
5776de6
8cd96f9
74aaf88
edb764f
91b913b
07ae94f
9b74408
0575749
b1a9d92
24b8258
8d6b979
303cb35
d54b111
cb2d86c
37ec22f
582dd08
873c23e
5c7f4a3
06bae39
0ef9bd4
edcd040
8aa441d
7c347f2
11965e3
5ea825a
665c3d3
221d9f8
fa0a87d
c5598b6
691b7b8
db8c351
07a9d59
eced01f
5bfb9e2
0e35e2c
9067615
7903086
8dc54f5
d741dd9
9e30b82
88b0840
77e9c32
1c06bec
84286d7
c3f2257
8edd209
9b9ae46
8317b24
1c55436
6d46fe1
f124ecb
ec8fad7
26a1c80
bf08528
b2a1b6a
442f10e
65331c9
fd9233a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
benchmarkMicaliVazirani.cpp | ||
benchmarkMicaliVazirani.sh) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add empty line at the end In general, please run
and fix the style errors in your files There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please extract it to a separate function |
||
|
||
delete maximum_matching; | ||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
echo "benchmarkMaximumMatching.sh $@" |
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; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
echo "benchmarkMicaliVazirani.sh $@" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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