Skip to content

Commit 35d2709

Browse files
committed
nf
1 parent c13fb03 commit 35d2709

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

com/williamfiset/algorithms/graphtheory/networkflow/examples/FordFulkersonExample.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import static java.lang.Math.min;
1111

12+
import java.lang.reflect.Array;
1213
import java.util.ArrayList;
1314
import java.util.List;
1415

@@ -29,7 +30,8 @@ public Edge(int from, int to, long capacity) {
2930
public String toString(int s, int t) {
3031
String u = (from == s) ? "s" : ((from == t) ? "t" : String.valueOf(from));
3132
String v = (to == s) ? "s" : ((to == t) ? "t" : String.valueOf(to));
32-
return String.format("Edge %s -> %s = %d/%d", u, v, flow, capacity);
33+
return String.format("Edge %s -> %s, flow = %d, capacity = %d, original capacity = %d", u, v,
34+
flow, capacity, originalCapacity);
3335
}
3436
}
3537

@@ -80,7 +82,7 @@ private void initializeGraph() {
8082
}
8183

8284
/**
83-
* Adds a directed edge (and residual edge) to the flow graph.
85+
* Adds a directed edge (and its residual edge) to the flow graph.
8486
*
8587
* @param from - The index of the node the directed edge starts at.
8688
* @param to - The index of the node the directed edge ends at.
@@ -98,9 +100,10 @@ public void addEdge(int from, int to, long capacity) {
98100

99101
/**
100102
* Returns the residual graph after the solver has been executed. This
101-
* allows you to inspect the {@link Edge#flow} and {@link Edge#capacity}
102-
* values of each edge. This is useful if you want to figure out which edges
103-
* were used during the max flow.
103+
* allows you to inspect the {@link Edge#flow}, {@link Edge#capacity},
104+
* and {@link Edge#originalCapacity} values of each edge. This is useful
105+
* if you are debugging or want to figure out which edges were used
106+
* during the max flow.
104107
*/
105108
public List<Edge>[] getGraph() {
106109
execute();
@@ -222,14 +225,12 @@ private static void exampleFromSlides() {
222225
// Maximum Flow is: 7
223226
System.out.printf("Maximum Flow is: %d\n", solver.getMaxFlow());
224227

225-
// Prints the flow and capacity value of each edge.
226228
List<Edge>[] resultGraph = solver.getGraph();
227-
for (int i = 0; i < resultGraph.length; i++) {
228-
List<Edge> edges = resultGraph[i];
229-
for (Edge e : edges) {
229+
230+
// Prints the flow and capacity value of each edge.
231+
for (List<Edge> edges : resultGraph)
232+
for (Edge e : edges)
230233
System.out.println(e.toString(s, t));
231-
}
232-
}
233234

234235
}
235236

0 commit comments

Comments
 (0)