From bea91a6f94b0e92bcf48b9a1cf53a2595976bae8 Mon Sep 17 00:00:00 2001 From: Stefan Pranger Date: Mon, 24 Jan 2022 20:16:26 +0100 Subject: [PATCH] added examples and README --- README.md | 86 ++++++++++++++++++++++++++++++++++++++++++ examples/1.txt | 15 ++++++++ examples/2.txt | 7 ++++ examples/3.txt | 8 ++++ examples/FF_killer.txt | 6 +++ 5 files changed, 122 insertions(+) create mode 100644 README.md create mode 100644 examples/1.txt create mode 100644 examples/2.txt create mode 100644 examples/3.txt create mode 100644 examples/FF_killer.txt diff --git a/README.md b/README.md new file mode 100644 index 0000000..7033175 --- /dev/null +++ b/README.md @@ -0,0 +1,86 @@ +# Max Flow using Dinic's Algorithm + +## Installation + +This project does not have any specific requirements other than a cpp compiler. The installations process follows the CMake procedure: + +``` +git clone https://git.pranger.xyz/sp/MaxFlowDinic +cd MaxFlowDinic +mkdir build +cd build +cmake .. && make +``` + +## Usage + +To display the help message: + +``` +> ./build/maxFlow -h + +You need to pass either and input graph file or an input graph string. +Allowed options: + -h, --help Print this help message. + -f, --input-file arg Filename of input graph file. + -s, --input-string arg Input graph string. + -o, --stdout Output to stdout. + -p, --output-file arg Filename for output. + -a, --max-flow Include verbose information about the max flow to the output. + -m, --minimum-cut Include the minimum cut set to the output. + -v, --verbose Output verbose algorithmic information and runtime. Pass twice to get information about all augmenting paths computed. +``` + +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. + +For example: +``` +>./build/maxFlow -f examples/1.txt -mavv +#Vertices: 10 +#Arc: 14 +Source: 1, Sink: 10 +Vertices: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 + 1 -> 2 capacity = 5 + 2 -> 10 capacity = 4 + 1 -> 10 capacity = 7 + 1 -> 3 capacity = 8 + 3 -> 10 capacity = 9 + 1 -> 4 capacity = 3 + 4 -> 7 capacity = 1 + 7 -> 10 capacity = 1 + 1 -> 5 capacity = 3 + 5 -> 8 capacity = 4 + 8 -> 10 capacity = 6 + 1 -> 6 capacity = 7 + 6 -> 9 capacity = 6 + 9 -> 10 capacity = 5 +Found max flow |x| = 28 +Max Flow per arc: + 1 -> 2 flow = 4/5 + 2 -> 10 flow = 4/4 + 1 -> 10 flow = 7/7 + 1 -> 3 flow = 8/8 + 3 -> 10 flow = 8/9 + 1 -> 4 flow = 1/3 + 4 -> 7 flow = 1/1 + 7 -> 10 flow = 1/1 + 1 -> 5 flow = 3/3 + 5 -> 8 flow = 3/4 + 8 -> 10 flow = 3/6 + 1 -> 6 flow = 5/7 + 6 -> 9 flow = 5/6 + 9 -> 10 flow = 5/5 +Min Cut X: {1, 2, 4, 6, 9} +Complement(X): {3, 5, 7, 8, 10} +Elapsed time: 1ms (1046µs). +Computation Statistics: + #level graphs built: 4 + #augmenting paths computed: 6 + 1 > 10 | flow = 7 + 1 > 2 > 10 | flow = 4 + 1 > 3 > 10 | flow = 8 + 1 > 4 > 7 > 10 | flow = 1 + 1 > 5 > 8 > 10 | flow = 3 + 1 > 6 > 9 > 10 | flow = 5 + #recursive buildPath calls: 32 +``` diff --git a/examples/1.txt b/examples/1.txt new file mode 100644 index 0000000..bdfcaa0 --- /dev/null +++ b/examples/1.txt @@ -0,0 +1,15 @@ +10 14 1 10 +1 2 5 +2 10 4 +1 10 7 +1 3 8 +3 10 9 +1 4 3 +4 7 1 +7 10 1 +1 5 3 +5 8 4 +8 10 6 +1 6 7 +6 9 6 +9 10 5 diff --git a/examples/2.txt b/examples/2.txt new file mode 100644 index 0000000..eba1c54 --- /dev/null +++ b/examples/2.txt @@ -0,0 +1,7 @@ +4 5 1 4 +1 2 4 +1 3 8 +2 3 1 +3 2 1 +3 4 3 +2 4 8 diff --git a/examples/3.txt b/examples/3.txt new file mode 100644 index 0000000..d05aefc --- /dev/null +++ b/examples/3.txt @@ -0,0 +1,8 @@ +5 7 1 5 +1 3 5 +1 4 3 +3 4 3 +4 2 5 +3 2 3 +2 5 7 +3 5 3 diff --git a/examples/FF_killer.txt b/examples/FF_killer.txt new file mode 100644 index 0000000..8d4b37c --- /dev/null +++ b/examples/FF_killer.txt @@ -0,0 +1,6 @@ +4 5 1 4 +1 2 99 +1 3 99 +2 3 1 +2 4 99 +3 4 99