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.

88 lines
2.3 KiB

2 years ago
2 years ago
  1. # Max Flow using Dinic's Algorithm
  2. ## Installation
  3. This project does not have any specific requirements other than a cpp compiler. The installations process follows the CMake procedure:
  4. ```
  5. git clone https://git.pranger.xyz/sp/MaxFlowDinic
  6. cd MaxFlowDinic
  7. mkdir build
  8. cd build
  9. cmake .. && make
  10. ```
  11. ## Usage
  12. To display the help message:
  13. ```
  14. > ./build/maxFlow -h
  15. You need to pass either and input graph file or an input graph string.
  16. Allowed options:
  17. -h, --help Print this help message.
  18. -f, --input-file arg Filename of input graph file.
  19. -s, --input-string arg Input graph string.
  20. -o, --stdout Output to stdout.
  21. -p, --output-file arg Filename for output.
  22. -u, --check-uniqueness Check uniqueness of maximum flow and minimum cut.
  23. -a, --max-flow Include verbose information about the maximum flow to the output.
  24. -m, --minimum-cut Include the minimum cut set to the output.
  25. -v, --verbose Output verbose algorithmic information and runtime. Pass twice to get information about all augmenting paths computed.
  26. ```
  27. The examples folder features a few toy examples. Using the `-f` option to pass the path to an input file and `-mavv` gives a verbose output.
  28. For example:
  29. ```
  30. >./build/maxFlow -f examples/1.txt -mavv
  31. #Vertices: 10
  32. #Arc: 14
  33. Source: 1, Sink: 10
  34. Vertices: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
  35. 1 -> 2 capacity = 5
  36. 2 -> 10 capacity = 4
  37. 1 -> 10 capacity = 7
  38. 1 -> 3 capacity = 8
  39. 3 -> 10 capacity = 9
  40. 1 -> 4 capacity = 3
  41. 4 -> 7 capacity = 1
  42. 7 -> 10 capacity = 1
  43. 1 -> 5 capacity = 3
  44. 5 -> 8 capacity = 4
  45. 8 -> 10 capacity = 6
  46. 1 -> 6 capacity = 7
  47. 6 -> 9 capacity = 6
  48. 9 -> 10 capacity = 5
  49. Found max flow |x| = 28
  50. Max Flow per arc:
  51. 1 -> 2 flow = 4/5
  52. 2 -> 10 flow = 4/4
  53. 1 -> 10 flow = 7/7
  54. 1 -> 3 flow = 8/8
  55. 3 -> 10 flow = 8/9
  56. 1 -> 4 flow = 1/3
  57. 4 -> 7 flow = 1/1
  58. 7 -> 10 flow = 1/1
  59. 1 -> 5 flow = 3/3
  60. 5 -> 8 flow = 3/4
  61. 8 -> 10 flow = 3/6
  62. 1 -> 6 flow = 5/7
  63. 6 -> 9 flow = 5/6
  64. 9 -> 10 flow = 5/5
  65. Min Cut X: {1, 2, 4, 6, 9}
  66. Complement(X): {3, 5, 7, 8, 10}
  67. Elapsed time: 1ms (1046µs).
  68. Computation Statistics:
  69. #level graphs built: 4
  70. #augmenting paths computed: 6
  71. 1 > 10 | flow = 7
  72. 1 > 2 > 10 | flow = 4
  73. 1 > 3 > 10 | flow = 8
  74. 1 > 4 > 7 > 10 | flow = 1
  75. 1 > 5 > 8 > 10 | flow = 3
  76. 1 > 6 > 9 > 10 | flow = 5
  77. #recursive buildPath calls: 32
  78. ```