COIN-OR::LEMON - Graph Library

Ticket #650: main.cpp

File main.cpp, 994 bytes (added by Oscar Higgott, 3 years ago)

Loads the lgf graphs and outputs success/failure of MaxWeightedPerfectMatching?

Line 
1#include <iostream>
2#include <lemon/list_graph.h>
3#include <lemon/lgf_reader.h>
4#include <lemon/matching.h>
5
6
7using namespace lemon;
8
9typedef ListGraph UGraph;
10typedef UGraph::EdgeMap<double> LengthMap;
11typedef MaxWeightedPerfectMatching<UGraph,LengthMap> MWPM;
12
13void 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
36int 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}