MCPcopy Create free account
hub / github.com/PrajaktaSathe/Java / fordFulkerson

Method fordFulkerson

Programs/FordFulkerson.java:35–66  ·  view source on GitHub ↗
(int graph[][], int s, int t)

Source from the content-addressed store, hash-verified

33
34 // Applying fordfulkerson algorithm
35 int fordFulkerson(int graph[][], int s, int t) {
36 int u, v;
37 int Graph[][] = new int[V][V];
38
39 for (u = 0; u < V; u++)
40 for (v = 0; v < V; v++)
41 Graph[u][v] = graph[u][v];
42
43 int p[] = new int[V];
44
45 int max_flow = 0;
46
47 // Updating the residual calues of edges
48 while (bfs(Graph, s, t, p)) {
49 int path_flow = Integer.MAX_VALUE;
50 for (v = t; v != s; v = p[v]) {
51 u = p[v];
52 path_flow = Math.min(path_flow, Graph[u][v]);
53 }
54
55 for (v = t; v != s; v = p[v]) {
56 u = p[v];
57 Graph[u][v] -= path_flow;
58 Graph[v][u] += path_flow;
59 }
60
61 // Adding the path flows
62 max_flow += path_flow;
63 }
64
65 return max_flow;
66 }
67
68 public static void main(String[] args) throws java.lang.Exception {
69 int graph[][] = new int[][] { { 0, 8, 0, 0, 3, 0 }, { 0, 0, 9, 0, 0, 0 }, { 0, 0, 0, 0, 7, 2 },

Callers 1

mainMethod · 0.95

Calls 2

bfsMethod · 0.95
minMethod · 0.80

Tested by

no test coverage detected