-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFordFulkerson.cpp
48 lines (41 loc) · 1.58 KB
/
FordFulkerson.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "bits/stdc++.h"
#include "headers/maxflow.h"
#include "headers/fordfulkerson.h"
using namespace std;
/**
* takes the input from given file
* @param inputFile location of the input file
* @return max-flow solver class
*/
FordFulkerson takeInput(const string &inputFile) {
ifstream fin(inputFile);
int n, m, s, t;
fin >> n >> m >> s >> t;
FordFulkerson maxFlowSolver(n, s, t);
int u, v, w;
for(int i = 0; i < m; i++) {
fin >> u >> v >> w;
maxFlowSolver.addEdge(u, v, w);
}
return maxFlowSolver;
}
int main(int argc, char const *argv[])
{
// FordFulkerson maxFlowSolver = takeInput("Testcases/small_testcase_1.txt");
FordFulkerson maxFlowSolver = takeInput("Testcases/small_testcase_2.txt");
cout << "Maximun Flow for given graph is: " << maxFlowSolver.getMaxFlow() << endl; // O(max_flow * m)
// It won't recalculate untill you change the graph
// cout << "Maximun Flow for given graph is: " << maxFlowSolver.getMaxFlow() << endl; // O(1)
// Now it will recalculate the answer, because we are changing the graph
// For small_testcase_1.txt file
// maxFlowSolver.addEdge(0, 3, 1000);
// maxFlowSolver.addEdge(3, 10, 1000);
// maxFlowSolver.addEdge(10, 11, 1000);
// cout << "Maximun Flow for given graph is: " << maxFlowSolver.getMaxFlow() << endl; // O(max_flow * m)
// Now it will recalculate the answer, because we are changing the graph
maxFlowSolver.addEdge(0, 1, 1000);
maxFlowSolver.addEdge(1, 3, 1000);
maxFlowSolver.addEdge(3, 5, 1000);
cout << "Maximun Flow for given graph is: " << maxFlowSolver.getMaxFlow() << endl; // O(max_flow * m)
return 0;
}