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.

69 lines
1.8 KiB

  1. #pragma once
  2. #include <chrono>
  3. #include <vector>
  4. #include <set>
  5. #include <string>
  6. #include <fstream>
  7. #include <iostream>
  8. #include "util/GraphParser.h"
  9. #include "util/Arc.h"
  10. #define NO_AUGMENTING_PATH_FOUND -1
  11. typedef std::vector<std::vector<Capacity>> CapacityMatrix;
  12. namespace data {
  13. class Graph {
  14. public:
  15. Graph(bool stdout_output, bool file_output, std::string output_filename, bool verbose_max_flow, bool min_cut, int verbosity);
  16. void parseFromString(const std::string &graph_string);
  17. void parseFromFile(const std::string &graph_file);
  18. void maxFlowDinic();
  19. private:
  20. void initMatrices();
  21. void initOstream();
  22. void constructLevelGraph();
  23. int findAugmentingPaths();
  24. void buildPath(std::vector<Vertex> &current_path);
  25. void computeFlowForPath(const std::vector<Vertex> &current_path);
  26. void printInformation() const;
  27. void printMaxFlowInformation() const;
  28. void printMinCut() const;
  29. void printComputationStatistics(const std::chrono::steady_clock::time_point &start, const std::chrono::steady_clock::time_point &end) const;
  30. std::vector<Vertex> m_vertices;
  31. std::vector<Arc> m_arc_list;
  32. VertexID m_source_id;
  33. VertexID m_sink_id;
  34. std::vector<Vertex>::iterator m_source;
  35. std::vector<Vertex>::iterator m_sink;
  36. CapacityMatrix m_flow;
  37. CapacityMatrix m_capapcities;
  38. int m_num_vertices;
  39. int m_num_arcs;
  40. int m_max_flow = 0;
  41. bool m_stdout_output = true;
  42. bool m_file_output = false;
  43. std::string m_output_file_name;
  44. std::ostream *m_ofstream;
  45. bool m_verbose_max_flow = false;
  46. bool m_min_cut = false;
  47. int m_verbosity = 0;
  48. uint m_num_paths = 0;
  49. uint m_num_build_path_calls = 0;
  50. uint m_num_level_graphs_built = 0;
  51. std::vector<std::string> m_augmenting_paths;
  52. };
  53. }