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.

86 lines
2.2 KiB

  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. -a, --max-flow Include verbose information about the max flow to the output.
  23. -m, --minimum-cut Include the minimum cut set to the output.
  24. -v, --verbose Output verbose algorithmic information and runtime. Pass twice to get information about all augmenting paths computed.
  25. ```
  26. 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.
  27. For example:
  28. ```
  29. >./build/maxFlow -f examples/1.txt -mavv
  30. #Vertices: 10
  31. #Arc: 14
  32. Source: 1, Sink: 10
  33. Vertices: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
  34. 1 -> 2 capacity = 5
  35. 2 -> 10 capacity = 4
  36. 1 -> 10 capacity = 7
  37. 1 -> 3 capacity = 8
  38. 3 -> 10 capacity = 9
  39. 1 -> 4 capacity = 3
  40. 4 -> 7 capacity = 1
  41. 7 -> 10 capacity = 1
  42. 1 -> 5 capacity = 3
  43. 5 -> 8 capacity = 4
  44. 8 -> 10 capacity = 6
  45. 1 -> 6 capacity = 7
  46. 6 -> 9 capacity = 6
  47. 9 -> 10 capacity = 5
  48. Found max flow |x| = 28
  49. Max Flow per arc:
  50. 1 -> 2 flow = 4/5
  51. 2 -> 10 flow = 4/4
  52. 1 -> 10 flow = 7/7
  53. 1 -> 3 flow = 8/8
  54. 3 -> 10 flow = 8/9
  55. 1 -> 4 flow = 1/3
  56. 4 -> 7 flow = 1/1
  57. 7 -> 10 flow = 1/1
  58. 1 -> 5 flow = 3/3
  59. 5 -> 8 flow = 3/4
  60. 8 -> 10 flow = 3/6
  61. 1 -> 6 flow = 5/7
  62. 6 -> 9 flow = 5/6
  63. 9 -> 10 flow = 5/5
  64. Min Cut X: {1, 2, 4, 6, 9}
  65. Complement(X): {3, 5, 7, 8, 10}
  66. Elapsed time: 1ms (1046µs).
  67. Computation Statistics:
  68. #level graphs built: 4
  69. #augmenting paths computed: 6
  70. 1 > 10 | flow = 7
  71. 1 > 2 > 10 | flow = 4
  72. 1 > 3 > 10 | flow = 8
  73. 1 > 4 > 7 > 10 | flow = 1
  74. 1 > 5 > 8 > 10 | flow = 3
  75. 1 > 6 > 9 > 10 | flow = 5
  76. #recursive buildPath calls: 32
  77. ```