edmonds-matching-algorithm/src/example.cpp

27 lines
786 B
C++

#include <iostream> // For writing to the standard output.
#include <fstream> // For reading input files.
#include "graph.hpp"
#include "edmonds.h"
int main(int argc, char** argv)
{
if (argc != 2)
{
std::cout << "Expected one argument, found " << argc - 1 << std::endl;
return EXIT_FAILURE; // return 1 would do the same, but is way too easy to mix up!
}
std::fstream input_file_graph{argv[1]};
if (not input_file_graph.is_open()) {
throw std::runtime_error(std::string("Could not open file for reading: ") + argv[1]);
}
ED::Graph graph = ED::Graph::read_dimacs(input_file_graph);
// Now, calculate the matching
ED::Graph optimum_matching = Edmonds::maximum_matching(graph);
std::cout << optimum_matching;
return EXIT_SUCCESS;
}