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.

70 lines
1.9 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 setSourceAndSinkIterator();
  22. void initOstream();
  23. void constructLevelGraph();
  24. int findAugmentingPaths();
  25. void buildPath(std::vector<Vertex> &current_path);
  26. void computeFlowForPath(const std::vector<Vertex> &current_path);
  27. void printInformation() const;
  28. void printMaxFlowInformation() const;
  29. void printMinCut() const;
  30. void printComputationStatistics(const std::chrono::steady_clock::time_point &start, const std::chrono::steady_clock::time_point &end) const;
  31. std::vector<Vertex> m_vertices;
  32. std::vector<Arc> m_arc_list;
  33. VertexID m_source_id;
  34. VertexID m_sink_id;
  35. std::vector<Vertex>::iterator m_source;
  36. std::vector<Vertex>::iterator m_sink;
  37. CapacityMatrix m_flow;
  38. CapacityMatrix m_capapcities;
  39. int m_num_vertices;
  40. int m_num_arcs;
  41. int m_max_flow = 0;
  42. bool m_stdout_output = true;
  43. bool m_file_output = false;
  44. std::string m_output_file_name;
  45. std::ostream *m_ofstream;
  46. bool m_verbose_max_flow = false;
  47. bool m_min_cut = false;
  48. int m_verbosity = 0;
  49. uint m_num_paths = 0;
  50. uint m_num_build_path_calls = 0;
  51. uint m_num_level_graphs_built = 0;
  52. std::vector<std::string> m_augmenting_paths;
  53. };
  54. }