9
9
10
10
import static java .lang .Math .min ;
11
11
12
+ import java .lang .reflect .Array ;
12
13
import java .util .ArrayList ;
13
14
import java .util .List ;
14
15
@@ -29,7 +30,8 @@ public Edge(int from, int to, long capacity) {
29
30
public String toString (int s , int t ) {
30
31
String u = (from == s ) ? "s" : ((from == t ) ? "t" : String .valueOf (from ));
31
32
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 );
33
35
}
34
36
}
35
37
@@ -80,7 +82,7 @@ private void initializeGraph() {
80
82
}
81
83
82
84
/**
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.
84
86
*
85
87
* @param from - The index of the node the directed edge starts at.
86
88
* @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) {
98
100
99
101
/**
100
102
* 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.
104
107
*/
105
108
public List <Edge >[] getGraph () {
106
109
execute ();
@@ -222,14 +225,12 @@ private static void exampleFromSlides() {
222
225
// Maximum Flow is: 7
223
226
System .out .printf ("Maximum Flow is: %d\n " , solver .getMaxFlow ());
224
227
225
- // Prints the flow and capacity value of each edge.
226
228
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 )
230
233
System .out .println (e .toString (s , t ));
231
- }
232
- }
233
234
234
235
}
235
236
0 commit comments