1 | #include <iostream> |
---|
2 | #include <lemon/list_graph.h> |
---|
3 | #include <lemon/lgf_reader.h> |
---|
4 | #include <lemon/matching.h> |
---|
5 | |
---|
6 | |
---|
7 | using namespace lemon; |
---|
8 | |
---|
9 | typedef ListGraph UGraph; |
---|
10 | typedef UGraph::EdgeMap<double> LengthMap; |
---|
11 | typedef MaxWeightedPerfectMatching<UGraph,LengthMap> MWPM; |
---|
12 | |
---|
13 | void SolveMatchingFromFile(std::string filename){ |
---|
14 | UGraph graph; |
---|
15 | LengthMap length(graph); |
---|
16 | |
---|
17 | try { |
---|
18 | GraphReader<UGraph> reader(graph, filename); |
---|
19 | reader.edgeMap("weight",length); |
---|
20 | reader.run(); |
---|
21 | } catch (FormatError& error) { |
---|
22 | std::cerr << error.what() << std::endl; |
---|
23 | } |
---|
24 | |
---|
25 | MWPM pm(graph, length); |
---|
26 | bool success = pm.run(); |
---|
27 | |
---|
28 | std::cout << filename << ": "; |
---|
29 | if (success){ |
---|
30 | std::cout << "succeeded" << std::endl; |
---|
31 | } else { |
---|
32 | std::cout << "failed" << std::endl; |
---|
33 | } |
---|
34 | } |
---|
35 | |
---|
36 | int main() { |
---|
37 | SolveMatchingFromFile("failing_graph_1.lgf"); |
---|
38 | SolveMatchingFromFile("failing_graph_2.lgf"); |
---|
39 | SolveMatchingFromFile("failing_graph_3.lgf"); |
---|
40 | SolveMatchingFromFile("failing_graph_4.lgf"); |
---|
41 | SolveMatchingFromFile("working_graph.lgf"); |
---|
42 | return 0; |
---|
43 | } |
---|