A simple students project implementing Dinic's Algorithm to compute the max flow/min cut of a network.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
2.4 KiB

  1. #include <iostream>
  2. #include <string>
  3. #include "util/OptionParser.h"
  4. #include "Graph.h"
  5. int main(int argc, char* argv[]) {
  6. popl::OptionParser optionParser("Allowed options");
  7. auto help_option = optionParser.add<popl::Switch>("h", "help", "Print this help message.");
  8. auto input_filename = optionParser.add<popl::Value<std::string>, popl::Attribute::optional>("f", "input-file", "Filename of input graph file.");
  9. auto input_string = optionParser.add<popl::Value<std::string>, popl::Attribute::optional>("s", "input-string", "Input graph string.");
  10. auto stdout_output = optionParser.add<popl::Switch, popl::Attribute::optional>("o", "stdout", "Output to stdout.");
  11. auto file_output = optionParser.add<popl::Value<std::string>, popl::Attribute::optional>("p", "output-file", "Filename for output.");
  12. auto verbose_max_flow = optionParser.add<popl::Switch, popl::Attribute::optional>("a", "max-flow", "Include verbose information about the max flow to the output.");
  13. auto min_cut_option = optionParser.add<popl::Switch, popl::Attribute::optional>("m", "minimum-cut", "Include the minimum cut set to the output.");
  14. auto verbose_option = optionParser.add<popl::Switch, popl::Attribute::optional>("v", "verbose", "Output verbose algorithmic information and runtime. Pass twice to get step-by-step information.");
  15. try {
  16. optionParser.parse(argc, argv);
  17. if(parser::checkOption(input_filename->count(), input_string->count()) > 0) {
  18. std::cout << optionParser << std::endl;
  19. return EXIT_FAILURE;
  20. }
  21. if(help_option->count() > 0) {
  22. std::cout << optionParser << std::endl;
  23. }
  24. } catch (const popl::invalid_option &e) {
  25. return parser::printPoplException(e);
  26. } catch (const std::exception &e) {
  27. std::cerr << "Exception: " << e.what() << "\n";
  28. return EXIT_FAILURE;
  29. }
  30. std::string filename = "";
  31. if(file_output->is_set()) {
  32. filename = file_output->value(0);
  33. }
  34. data::Graph network(stdout_output->is_set(),
  35. file_output->is_set(),
  36. filename,
  37. verbose_max_flow->is_set(),
  38. min_cut_option->is_set(),
  39. verbose_option->count());
  40. if(input_filename->count() > 0) {
  41. network.parseFromFile(input_filename->value(0));
  42. } else if (input_string->count()) {
  43. network.parseFromString(input_string->value(0));
  44. }
  45. network.maxFlowDinic();
  46. return 0;
  47. }