mostly reindent of examples

This commit is contained in:
Laurent Perron
2019-05-06 10:31:03 +02:00
parent 9b8a26beee
commit cd6bf20fe5
10 changed files with 77 additions and 91 deletions

View File

@@ -14,9 +14,12 @@
import com.google.ortools.graph.MaxFlow;
import com.google.ortools.graph.MinCostFlow;
/** Sample showing how to model using the flow solver. */
public class FlowExample {
/**
* Sample showing how to model using the flow solver.
*
*/
public class FlowExample {
static {
System.loadLibrary("jniortools");
}
@@ -26,11 +29,7 @@ public class FlowExample {
final int numSources = 4;
final int numTargets = 4;
final int[][] costs = {
{90, 75, 75, 80},
{35, 85, 55, 65},
{125, 95, 90, 105},
{45, 110, 95, 115}
};
{90, 75, 75, 80}, {35, 85, 55, 65}, {125, 95, 90, 105}, {45, 110, 95, 115}};
final int expectedCost = 275;
MinCostFlow minCostFlow = new MinCostFlow();
for (int source = 0; source < numSources; ++source) {
@@ -48,13 +47,8 @@ public class FlowExample {
System.out.println("total flow = " + totalFlowCost + "/" + expectedCost);
for (int i = 0; i < minCostFlow.getNumArcs(); ++i) {
if (minCostFlow.getFlow(i) > 0) {
System.out.println(
"From source "
+ minCostFlow.getTail(i)
+ " to target "
+ minCostFlow.getHead(i)
+ ": cost "
+ minCostFlow.getUnitCost(i));
System.out.println("From source " + minCostFlow.getTail(i) + " to target "
+ minCostFlow.getHead(i) + ": cost " + minCostFlow.getUnitCost(i));
}
}
} else {
@@ -75,15 +69,8 @@ public class FlowExample {
if (maxFlow.solve(0, 5) == MaxFlow.Status.OPTIMAL) {
System.out.println("Total flow " + maxFlow.getOptimalFlow() + "/" + expectedTotalFlow);
for (int i = 0; i < maxFlow.getNumArcs(); ++i) {
System.out.println(
"From source "
+ maxFlow.getTail(i)
+ " to target "
+ maxFlow.getHead(i)
+ ": "
+ maxFlow.getFlow(i)
+ " / "
+ maxFlow.getCapacity(i));
System.out.println("From source " + maxFlow.getTail(i) + " to target " + maxFlow.getHead(i)
+ ": " + maxFlow.getFlow(i) + " / " + maxFlow.getCapacity(i));
}
// TODO(user): Our SWIG configuration does not currently handle these
// functions correctly in Java: