diff --git a/examples/java/CapacitatedVehicleRoutingProblemWithTimeWindows.java b/examples/java/CapacitatedVehicleRoutingProblemWithTimeWindows.java index 06fe5ef527..55c6551d43 100644 --- a/examples/java/CapacitatedVehicleRoutingProblemWithTimeWindows.java +++ b/examples/java/CapacitatedVehicleRoutingProblemWithTimeWindows.java @@ -47,11 +47,12 @@ class Pair { */ public class CapacitatedVehicleRoutingProblemWithTimeWindows { + static { + System.loadLibrary("jniortools"); + } - static { System.loadLibrary("jniortools"); } - - private static Logger logger = Logger.getLogger( - CapacitatedVehicleRoutingProblemWithTimeWindows.class.getName()); + private static Logger logger = + Logger.getLogger(CapacitatedVehicleRoutingProblemWithTimeWindows.class.getName()); // Locations representing either an order location or a vehicle route // start/end. @@ -101,24 +102,17 @@ public class CapacitatedVehicleRoutingProblemWithTimeWindows { * @param penaltyMin minimum pernalty cost if order is dropped. * @param penaltyMax maximum pernalty cost if order is dropped. */ - private void buildOrders(int numberOfOrders, int xMax, int yMax, - int demandMax, int timeWindowMin, int timeWindowMax, - int timeWindowWidth, int penaltyMin, - int penaltyMax) { + private void buildOrders(int numberOfOrders, int xMax, int yMax, int demandMax, int timeWindowMin, + int timeWindowMax, int timeWindowWidth, int penaltyMin, int penaltyMax) { logger.info("Building orders."); for (int order = 0; order < numberOfOrders; ++order) { - locations.add(Pair.of(randomGenerator.nextInt(xMax + 1), - randomGenerator.nextInt(yMax + 1))); + locations.add(Pair.of(randomGenerator.nextInt(xMax + 1), randomGenerator.nextInt(yMax + 1))); orderDemands.add(randomGenerator.nextInt(demandMax + 1)); /** @todo 1) Specify deliver duration for each shipment*/ orderDurations.add(2); // in minutes - int timeWindowStart = - randomGenerator.nextInt(timeWindowMax - timeWindowMin) + - timeWindowMin; - orderTimeWindows.add( - Pair.of(timeWindowStart, timeWindowStart + timeWindowWidth)); - orderPenalties.add(randomGenerator.nextInt(penaltyMax - penaltyMin + 1) + - penaltyMin); + int timeWindowStart = randomGenerator.nextInt(timeWindowMax - timeWindowMin) + timeWindowMin; + orderTimeWindows.add(Pair.of(timeWindowStart, timeWindowStart + timeWindowWidth)); + orderPenalties.add(randomGenerator.nextInt(penaltyMax - penaltyMin + 1) + penaltyMin); } } @@ -135,24 +129,20 @@ public class CapacitatedVehicleRoutingProblemWithTimeWindows { * @param costCoefficientMax maximum cost per distance unit of a vehicle * (mimimum is 1), */ - private void buildFleet(int numberOfVehicles, int xMax, int yMax, - int startTime, int endTime, int capacity, - int costCoefficientMax) { + private void buildFleet(int numberOfVehicles, int xMax, int yMax, int startTime, int endTime, + int capacity, int costCoefficientMax) { logger.info("Building fleet."); vehicleCapacity = capacity; vehicleStarts = new int[numberOfVehicles]; vehicleEnds = new int[numberOfVehicles]; for (int vehicle = 0; vehicle < numberOfVehicles; ++vehicle) { vehicleStarts[vehicle] = locations.size(); - locations.add(Pair.of(randomGenerator.nextInt(xMax + 1), - randomGenerator.nextInt(yMax + 1))); + locations.add(Pair.of(randomGenerator.nextInt(xMax + 1), randomGenerator.nextInt(yMax + 1))); vehicleEnds[vehicle] = locations.size(); - locations.add(Pair.of(randomGenerator.nextInt(xMax + 1), - randomGenerator.nextInt(yMax + 1))); + locations.add(Pair.of(randomGenerator.nextInt(xMax + 1), randomGenerator.nextInt(yMax + 1))); vehicleStartTime.add(startTime); vehicleEndTime.add(endTime); - vehicleCostCoefficients.add(randomGenerator.nextInt(costCoefficientMax) + - 1); + vehicleCostCoefficients.add(randomGenerator.nextInt(costCoefficientMax) + 1); } } @@ -160,13 +150,13 @@ public class CapacitatedVehicleRoutingProblemWithTimeWindows { * Solves the current routing problem. */ private void solve(final int numberOfOrders, final int numberOfVehicles) { - logger.info("Creating model with " + numberOfOrders + " orders and " + - numberOfVehicles + " vehicles."); + logger.info( + "Creating model with " + numberOfOrders + " orders and " + numberOfVehicles + " vehicles."); // Finalizing model final int numberOfLocations = locations.size(); - RoutingModel model = new RoutingModel(numberOfLocations, numberOfVehicles, - vehicleStarts, vehicleEnds); + RoutingModel model = + new RoutingModel(numberOfLocations, numberOfVehicles, vehicleStarts, vehicleEnds); // Setting up dimensions final int bigNumber = 100000; @@ -178,8 +168,8 @@ public class CapacitatedVehicleRoutingProblemWithTimeWindows { Pair secondLocation = locations.get(secondIndex); Integer distance = 0; Integer duration = 0; - distance = Math.abs(firstLocation.first - secondLocation.first) + - Math.abs(firstLocation.second - secondLocation.second); + distance = Math.abs(firstLocation.first - secondLocation.first) + + Math.abs(firstLocation.second - secondLocation.second); // Deal with Order duration shipment if (firstIndex < numberOfOrders) { // shipment duration @@ -218,9 +208,9 @@ public class CapacitatedVehicleRoutingProblemWithTimeWindows { try { Pair firstLocation = locations.get(firstIndex); Pair secondLocation = locations.get(secondIndex); - return costCoefficient * - (Math.abs(firstLocation.first - secondLocation.first) + - Math.abs(firstLocation.second - secondLocation.second)); + return costCoefficient + * (Math.abs(firstLocation.first - secondLocation.first) + + Math.abs(firstLocation.second - secondLocation.second)); } catch (Throwable throwed) { logger.warning(throwed.getMessage()); return 0; @@ -228,17 +218,14 @@ public class CapacitatedVehicleRoutingProblemWithTimeWindows { } }; model.setArcCostEvaluatorOfVehicle(manhattanCostCallback, vehicle); - model.cumulVar(model.start(vehicle), "time") - .setMin(vehicleStartTime.get(vehicle)); - model.cumulVar(model.end(vehicle), "time") - .setMax(vehicleEndTime.get(vehicle)); + model.cumulVar(model.start(vehicle), "time").setMin(vehicleStartTime.get(vehicle)); + model.cumulVar(model.end(vehicle), "time").setMax(vehicleEndTime.get(vehicle)); } // Setting up orders for (int order = 0; order < numberOfOrders; ++order) { model.cumulVar(model.nodeToIndex(order), "time") - .setRange(orderTimeWindows.get(order).first, - orderTimeWindows.get(order).second); + .setRange(orderTimeWindows.get(order).first, orderTimeWindows.get(order).second); int[] orders = {order}; model.addDisjunction(orders, orderPenalties.get(order)); } @@ -247,8 +234,7 @@ public class CapacitatedVehicleRoutingProblemWithTimeWindows { RoutingSearchParameters parameters = RoutingSearchParameters.newBuilder() .mergeFrom(RoutingModel.defaultSearchParameters()) - .setFirstSolutionStrategy( - FirstSolutionStrategy.Value.PATH_CHEAPEST_ARC) + .setFirstSolutionStrategy(FirstSolutionStrategy.Value.PATH_CHEAPEST_ARC) .build(); logger.info("Search"); @@ -275,19 +261,16 @@ public class CapacitatedVehicleRoutingProblemWithTimeWindows { route += "/!\\Empty Route/!\\ "; } { - for (; !model.isEnd(order); - order = solution.value(model.nextVar(order))) { + for (; !model.isEnd(order); order = solution.value(model.nextVar(order))) { IntVar load = model.cumulVar(order, "capacity"); IntVar time = model.cumulVar(order, "time"); route += order + " Load(" + solution.value(load) + ") " - + "Time(" + solution.min(time) + ", " + - solution.max(time) + ") -> "; + + "Time(" + solution.min(time) + ", " + solution.max(time) + ") -> "; } IntVar load = model.cumulVar(order, "capacity"); IntVar time = model.cumulVar(order, "time"); route += order + " Load(" + solution.value(load) + ") " - + "Time(" + solution.min(time) + ", " + solution.max(time) + - ")"; + + "Time(" + solution.min(time) + ", " + solution.max(time) + ")"; } output += route + "\n"; } @@ -318,10 +301,9 @@ public class CapacitatedVehicleRoutingProblemWithTimeWindows { final int vehicles = 20; final int capacity = 50; - problem.buildOrders(orders, xMax, yMax, demandMax, timeWindowMin, - timeWindowMax, timeWindowWidth, penaltyMin, penaltyMax); - problem.buildFleet(vehicles, xMax, yMax, startTime, endTime, capacity, - costCoefficientMax); + problem.buildOrders(orders, xMax, yMax, demandMax, timeWindowMin, timeWindowMax, + timeWindowWidth, penaltyMin, penaltyMax); + problem.buildFleet(vehicles, xMax, yMax, startTime, endTime, capacity, costCoefficientMax); problem.solve(orders, vehicles); } } diff --git a/examples/java/FlowExample.java b/examples/java/FlowExample.java index d00007d3d2..15e7872373 100644 --- a/examples/java/FlowExample.java +++ b/examples/java/FlowExample.java @@ -20,23 +20,22 @@ import com.google.ortools.graph.MinCostFlow; */ public class FlowExample { - - static { System.loadLibrary("jniortools"); } + static { + System.loadLibrary("jniortools"); + } private static void solveMinCostFlow() { System.out.println("Min Cost Flow Problem - Simple interface"); 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}}; + final int[][] costs = { + {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) { for (int target = 0; target < numTargets; ++target) { - minCostFlow.addArcWithCapacityAndUnitCost(source, numSources + target, - 1, costs[source][target]); + minCostFlow.addArcWithCapacityAndUnitCost( + source, numSources + target, 1, costs[source][target]); } } for (int node = 0; node < numSources; ++node) { @@ -48,9 +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 { @@ -69,12 +67,10 @@ public class FlowExample { maxFlow.addArcWithCapacity(tails[i], heads[i], capacities[i]); } if (maxFlow.solve(0, 5) == MaxFlow.Status.OPTIMAL) { - System.out.println("Total flow " + maxFlow.getOptimalFlow() + "/" + - expectedTotalFlow); + 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: diff --git a/examples/java/IntegerProgramming.java b/examples/java/IntegerProgramming.java index 0f3e34eeab..8e4275d48c 100644 --- a/examples/java/IntegerProgramming.java +++ b/examples/java/IntegerProgramming.java @@ -22,12 +22,14 @@ import com.google.ortools.linearsolver.MPVariable; */ public class IntegerProgramming { - static { System.loadLibrary("jniortools"); } + static { + System.loadLibrary("jniortools"); + } private static MPSolver createSolver(String solverType) { try { - return new MPSolver("IntegerProgrammingExample", - MPSolver.OptimizationProblemType.valueOf(solverType)); + return new MPSolver( + "IntegerProgrammingExample", MPSolver.OptimizationProblemType.valueOf(solverType)); } catch (java.lang.IllegalArgumentException e) { System.err.println("Bad solver type: " + e); return null; @@ -67,29 +69,25 @@ public class IntegerProgramming { // others than GLOP_LINEAR_PROGRAMMING, this is highly recommended!). if (!solver.verifySolution(/*tolerance=*/1e-7, /*logErrors=*/true)) { System.err.println("The solution returned by the solver violated the" - + " problem constraints by at least 1e-7"); + + " problem constraints by at least 1e-7"); return; } - System.out.println("Problem solved in " + solver.wallTime() + - " milliseconds"); + System.out.println("Problem solved in " + solver.wallTime() + " milliseconds"); // The objective value of the solution. - System.out.println("Optimal objective value = " + - solver.objective().value()); + System.out.println("Optimal objective value = " + solver.objective().value()); // The value of each variable in the solution. System.out.println("x1 = " + x1.solutionValue()); System.out.println("x2 = " + x2.solutionValue()); System.out.println("Advanced usage:"); - System.out.println("Problem solved in " + solver.nodes() + - " branch-and-bound nodes"); + System.out.println("Problem solved in " + solver.nodes() + " branch-and-bound nodes"); } public static void main(String[] args) throws Exception { - System.out.println( - "---- Integer programming example with SCIP (recommended) ----"); + System.out.println("---- Integer programming example with SCIP (recommended) ----"); runIntegerProgrammingExample("SCIP_MIXED_INTEGER_PROGRAMMING"); System.out.println("---- Integer programming example with CBC ----"); runIntegerProgrammingExample("CBC_MIXED_INTEGER_PROGRAMMING"); diff --git a/examples/java/Knapsack.java b/examples/java/Knapsack.java index 2e1ab8a128..aa23413b24 100644 --- a/examples/java/Knapsack.java +++ b/examples/java/Knapsack.java @@ -19,23 +19,20 @@ import com.google.ortools.algorithms.KnapsackSolver; */ public class Knapsack { - static { System.loadLibrary("jniortools"); } + static { + System.loadLibrary("jniortools"); + } private static void solve() { - KnapsackSolver solver = - new KnapsackSolver(KnapsackSolver.SolverType - .KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER, - "test"); - final long[] profits = {360, 83, 59, 130, 431, 67, 230, 52, 93, 125, - 670, 892, 600, 38, 48, 147, 78, 256, 63, 17, - 120, 164, 432, 35, 92, 110, 22, 42, 50, 323, - 514, 28, 87, 73, 78, 15, 26, 78, 210, 36, - 85, 189, 274, 43, 33, 10, 19, 389, 276, 312}; + KnapsackSolver solver = new KnapsackSolver( + KnapsackSolver.SolverType.KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER, "test"); + final long[] profits = {360, 83, 59, 130, 431, 67, 230, 52, 93, 125, 670, 892, 600, 38, 48, 147, + 78, 256, 63, 17, 120, 164, 432, 35, 92, 110, 22, 42, 50, 323, 514, 28, 87, 73, 78, 15, 26, + 78, 210, 36, 85, 189, 274, 43, 33, 10, 19, 389, 276, 312}; - final long[][] weights = { - {7, 0, 30, 22, 80, 94, 11, 81, 70, 64, 59, 18, 0, 36, 3, 8, 15, - 42, 9, 0, 42, 47, 52, 32, 26, 48, 55, 6, 29, 84, 2, 4, 18, 56, - 7, 29, 93, 44, 71, 3, 86, 66, 31, 65, 0, 79, 20, 65, 52, 13}}; + final long[][] weights = {{7, 0, 30, 22, 80, 94, 11, 81, 70, 64, 59, 18, 0, 36, 3, 8, 15, 42, 9, + 0, 42, 47, 52, 32, 26, 48, 55, 6, 29, 84, 2, 4, 18, 56, 7, 29, 93, 44, 71, 3, 86, 66, 31, + 65, 0, 79, 20, 65, 52, 13}}; final long[] capacities = {850}; @@ -46,9 +43,10 @@ public class Knapsack { final long computedProfit = solver.solve(); - System.out.println("Optimal_Profit = " + computedProfit + "/" + - optimalProfit); + System.out.println("Optimal_Profit = " + computedProfit + "/" + optimalProfit); } - public static void main(String[] args) throws Exception { Knapsack.solve(); } + public static void main(String[] args) throws Exception { + Knapsack.solve(); + } } diff --git a/examples/java/LinearAssignmentAPI.java b/examples/java/LinearAssignmentAPI.java index 2f35205822..81db91bf0d 100644 --- a/examples/java/LinearAssignmentAPI.java +++ b/examples/java/LinearAssignmentAPI.java @@ -21,16 +21,15 @@ import com.google.ortools.graph.LinearSumAssignment; */ public class LinearAssignmentAPI { - - static { System.loadLibrary("jniortools"); } + static { + System.loadLibrary("jniortools"); + } private static void runAssignmentOn4x4Matrix() { final int numSources = 4; final int numTargets = 4; - final int[][] cost = {{90, 76, 75, 80}, - {35, 85, 55, 65}, - {125, 95, 90, 105}, - {45, 110, 95, 115}}; + final int[][] cost = { + {90, 76, 75, 80}, {35, 85, 55, 65}, {125, 95, 90, 105}, {45, 110, 95, 115}}; final int expectedCost = cost[0][3] + cost[1][2] + cost[2][1] + cost[3][0]; LinearSumAssignment assignment = new LinearSumAssignment(); @@ -41,12 +40,10 @@ public class LinearAssignmentAPI { } if (assignment.solve() == LinearSumAssignment.Status.OPTIMAL) { - System.out.println("Total cost = " + assignment.getOptimalCost() + "/" + - expectedCost); + System.out.println("Total cost = " + assignment.getOptimalCost() + "/" + expectedCost); for (int node = 0; node < assignment.getNumNodes(); ++node) { - System.out.println("Left node " + node + " assigned to right node " + - assignment.getRightMate(node) + " with cost " + - assignment.getAssignmentCost(node)); + System.out.println("Left node " + node + " assigned to right node " + + assignment.getRightMate(node) + " with cost " + assignment.getAssignmentCost(node)); } } else { System.out.println("No solution found."); diff --git a/examples/java/LinearProgramming.java b/examples/java/LinearProgramming.java index 070b1d527d..c94e0090ea 100644 --- a/examples/java/LinearProgramming.java +++ b/examples/java/LinearProgramming.java @@ -22,19 +22,20 @@ import com.google.ortools.linearsolver.MPVariable; */ public class LinearProgramming { - static { System.loadLibrary("jniortools"); } + static { + System.loadLibrary("jniortools"); + } private static MPSolver createSolver(String solverType) { try { - return new MPSolver("LinearProgrammingExample", - MPSolver.OptimizationProblemType.valueOf(solverType)); + return new MPSolver( + "LinearProgrammingExample", MPSolver.OptimizationProblemType.valueOf(solverType)); } catch (java.lang.IllegalArgumentException e) { return null; } } - private static void runLinearProgrammingExample(String solverType, - boolean printModel) { + private static void runLinearProgrammingExample(String solverType, boolean printModel) { MPSolver solver = createSolver(solverType); if (solver == null) { System.out.println("Could not create solver " + solverType); @@ -91,16 +92,14 @@ public class LinearProgramming { // others than GLOP_LINEAR_PROGRAMMING, this is highly recommended!). if (!solver.verifySolution(/*tolerance=*/1e-7, /*logErrors=*/true)) { System.err.println("The solution returned by the solver violated the" - + " problem constraints by at least 1e-7"); + + " problem constraints by at least 1e-7"); return; } - System.out.println("Problem solved in " + solver.wallTime() + - " milliseconds"); + System.out.println("Problem solved in " + solver.wallTime() + " milliseconds"); // The objective value of the solution. - System.out.println("Optimal objective value = " + - solver.objective().value()); + System.out.println("Optimal objective value = " + solver.objective().value()); // The value of each variable in the solution. System.out.println("x1 = " + x1.solutionValue()); @@ -110,8 +109,7 @@ public class LinearProgramming { final double[] activities = solver.computeConstraintActivities(); System.out.println("Advanced usage:"); - System.out.println("Problem solved in " + solver.iterations() + - " iterations"); + System.out.println("Problem solved in " + solver.iterations() + " iterations"); System.out.println("x1: reduced cost = " + x1.reducedCost()); System.out.println("x2: reduced cost = " + x2.reducedCost()); System.out.println("x3: reduced cost = " + x3.reducedCost()); @@ -124,8 +122,7 @@ public class LinearProgramming { } public static void main(String[] args) throws Exception { - System.out.println( - "---- Linear programming example with GLOP (recommended) ----"); + System.out.println("---- Linear programming example with GLOP (recommended) ----"); runLinearProgrammingExample("GLOP_LINEAR_PROGRAMMING", true); System.out.println("---- Linear programming example with CLP ----"); runLinearProgrammingExample("CLP_LINEAR_PROGRAMMING", false); diff --git a/examples/java/LsApi.java b/examples/java/LsApi.java index e2ed5ae42a..943739b9e7 100644 --- a/examples/java/LsApi.java +++ b/examples/java/LsApi.java @@ -29,11 +29,14 @@ import com.google.ortools.constraintsolver.Solver; * */ public class LsApi { - - static { System.loadLibrary("jniortools"); } + static { + System.loadLibrary("jniortools"); + } static class OneVarLns extends BaseLns { - public OneVarLns(IntVar[] vars) { super(vars); } + public OneVarLns(IntVar[] vars) { + super(vars); + } @Override public void initFragments() { @@ -127,11 +130,10 @@ public class LsApi { IntVar[] vars = solver.makeIntVarArray(4, 0, 4, "vars"); IntVar sumVar = solver.makeSum(vars).var(); OptimizeVar obj = solver.makeMinimize(sumVar, 1); - DecisionBuilder db = solver.makePhase(vars, Solver.CHOOSE_FIRST_UNBOUND, - Solver.ASSIGN_MAX_VALUE); + DecisionBuilder db = + solver.makePhase(vars, Solver.CHOOSE_FIRST_UNBOUND, Solver.ASSIGN_MAX_VALUE); OneVarLns oneVarLns = new OneVarLns(vars); - LocalSearchPhaseParameters lsParams = - solver.makeLocalSearchPhaseParameters(oneVarLns, db); + LocalSearchPhaseParameters lsParams = solver.makeLocalSearchPhaseParameters(oneVarLns, db); DecisionBuilder ls = solver.makeLocalSearchPhase(vars, db, lsParams); SolutionCollector collector = solver.makeLastSolutionCollector(); collector.addObjective(sumVar); @@ -146,11 +148,10 @@ public class LsApi { IntVar[] vars = solver.makeIntVarArray(4, 0, 4, "vars"); IntVar sumVar = solver.makeSum(vars).var(); OptimizeVar obj = solver.makeMinimize(sumVar, 1); - DecisionBuilder db = solver.makePhase(vars, Solver.CHOOSE_FIRST_UNBOUND, - Solver.ASSIGN_MAX_VALUE); + DecisionBuilder db = + solver.makePhase(vars, Solver.CHOOSE_FIRST_UNBOUND, Solver.ASSIGN_MAX_VALUE); MoveOneVar moveOneVar = new MoveOneVar(vars); - LocalSearchPhaseParameters lsParams = - solver.makeLocalSearchPhaseParameters(moveOneVar, db); + LocalSearchPhaseParameters lsParams = solver.makeLocalSearchPhaseParameters(moveOneVar, db); DecisionBuilder ls = solver.makeLocalSearchPhase(vars, db, lsParams); SolutionCollector collector = solver.makeLastSolutionCollector(); collector.addObjective(sumVar); @@ -165,8 +166,8 @@ public class LsApi { IntVar[] vars = solver.makeIntVarArray(4, 0, 4, "vars"); IntVar sumVar = solver.makeSum(vars).var(); OptimizeVar obj = solver.makeMinimize(sumVar, 1); - DecisionBuilder db = solver.makePhase(vars, Solver.CHOOSE_FIRST_UNBOUND, - Solver.ASSIGN_MAX_VALUE); + DecisionBuilder db = + solver.makePhase(vars, Solver.CHOOSE_FIRST_UNBOUND, Solver.ASSIGN_MAX_VALUE); MoveOneVar moveOneVar = new MoveOneVar(vars); SumFilter filter = new SumFilter(vars); IntVarLocalSearchFilter[] filters = new IntVarLocalSearchFilter[1]; diff --git a/examples/java/RabbitsPheasants.java b/examples/java/RabbitsPheasants.java index 576715ec02..12da7de112 100644 --- a/examples/java/RabbitsPheasants.java +++ b/examples/java/RabbitsPheasants.java @@ -22,10 +22,11 @@ import java.util.logging.Logger; * */ public class RabbitsPheasants { - private static Logger logger = - Logger.getLogger(RabbitsPheasants.class.getName()); + private static Logger logger = Logger.getLogger(RabbitsPheasants.class.getName()); - static { System.loadLibrary("jniortools"); } + static { + System.loadLibrary("jniortools"); + } /** * Solves the rabbits + pheasants problem. We are seing 20 heads @@ -33,23 +34,18 @@ public class RabbitsPheasants { * seeing? */ private static void solve(boolean traceSearch) { - ConstraintSolverParameters parameters = - ConstraintSolverParameters.newBuilder() - .mergeFrom(Solver.defaultSolverParameters()) - .setTraceSearch(traceSearch) - .build(); + ConstraintSolverParameters parameters = ConstraintSolverParameters.newBuilder() + .mergeFrom(Solver.defaultSolverParameters()) + .setTraceSearch(traceSearch) + .build(); Solver solver = new Solver("RabbitsPheasants", parameters); IntVar rabbits = solver.makeIntVar(0, 100, "rabbits"); IntVar pheasants = solver.makeIntVar(0, 100, "pheasants"); - solver.addConstraint( - solver.makeEquality(solver.makeSum(rabbits, pheasants), 20)); - solver.addConstraint( - solver.makeEquality(solver.makeSum(solver.makeProd(rabbits, 4), - solver.makeProd(pheasants, 2)), - 56)); + solver.addConstraint(solver.makeEquality(solver.makeSum(rabbits, pheasants), 20)); + solver.addConstraint(solver.makeEquality( + solver.makeSum(solver.makeProd(rabbits, 4), solver.makeProd(pheasants, 2)), 56)); DecisionBuilder db = - solver.makePhase(rabbits, pheasants, Solver.CHOOSE_FIRST_UNBOUND, - Solver.ASSIGN_MIN_VALUE); + solver.makePhase(rabbits, pheasants, Solver.CHOOSE_FIRST_UNBOUND, Solver.ASSIGN_MIN_VALUE); solver.newSearch(db); solver.nextSolution(); logger.info(rabbits.toString()); diff --git a/examples/java/Tsp.java b/examples/java/Tsp.java index 67c666bbf9..142db636e1 100644 --- a/examples/java/Tsp.java +++ b/examples/java/Tsp.java @@ -23,7 +23,9 @@ import com.google.ortools.constraintsolver.FirstSolutionStrategy; import com.google.ortools.constraintsolver.RoutingSearchParameters; class Tsp { - static { System.loadLibrary("jniortools"); } + static { + System.loadLibrary("jniortools"); + } static class RandomManhattan extends NodeEvaluator2 { public RandomManhattan(int size, int seed) { @@ -38,8 +40,8 @@ class Tsp { @Override public long run(int firstIndex, int secondIndex) { - return Math.abs(xs[firstIndex] - xs[secondIndex]) + - Math.abs(ys[firstIndex] - ys[secondIndex]); + return Math.abs(xs[firstIndex] - xs[secondIndex]) + + Math.abs(ys[firstIndex] - ys[secondIndex]); } private int[] xs; @@ -77,15 +79,13 @@ class Tsp { } // Add dummy dimension to test API. - routing.addDimension(new ConstantCallback(), size + 1, size + 1, true, - "dummy"); + routing.addDimension(new ConstantCallback(), size + 1, size + 1, true, "dummy"); // Solve, returns a solution if any (owned by RoutingModel). RoutingSearchParameters search_parameters = RoutingSearchParameters.newBuilder() .mergeFrom(RoutingModel.defaultSearchParameters()) - .setFirstSolutionStrategy( - FirstSolutionStrategy.Value.PATH_CHEAPEST_ARC) + .setFirstSolutionStrategy(FirstSolutionStrategy.Value.PATH_CHEAPEST_ARC) .build(); Assignment solution = routing.solveWithParameters(search_parameters); diff --git a/examples/java/Vrp.java b/examples/java/Vrp.java index 809503d880..89c7eacd07 100644 --- a/examples/java/Vrp.java +++ b/examples/java/Vrp.java @@ -24,9 +24,8 @@ class DataProblem { private int[][] locations_; public DataProblem() { - locations_ = new int[][] {{4, 4}, {2, 0}, {8, 0}, {0, 1}, {1, 1}, {5, 2}, - {7, 2}, {3, 3}, {6, 3}, {5, 5}, {8, 5}, {1, 6}, - {2, 6}, {3, 7}, {6, 7}, {0, 8}, {7, 8}}; + locations_ = new int[][] {{4, 4}, {2, 0}, {8, 0}, {0, 1}, {1, 1}, {5, 2}, {7, 2}, {3, 3}, + {6, 3}, {5, 5}, {8, 5}, {1, 6}, {2, 6}, {3, 7}, {6, 7}, {0, 8}, {7, 8}}; // Compute locations in meters using the block dimension defined as follow // Manhattan average block: 750ft x 264ft -> 228m x 80m @@ -40,13 +39,21 @@ class DataProblem { } /// @brief Gets the number of vehicles. - public int getVehicleNumber() { return 4; } + public int getVehicleNumber() { + return 4; + } /// @brief Gets the locations. - public int[][] getLocations() { return locations_; } + public int[][] getLocations() { + return locations_; + } /// @brief Gets the number of locations. - public int getLocationNumber() { return locations_.length; } + public int getLocationNumber() { + return locations_.length; + } /// @brief Gets the depot NodeIndex. - public int getDepot() { return 0; } + public int getDepot() { + return 0; + } } /// @brief Manhattan distance implemented as a callback. @@ -64,10 +71,9 @@ class ManhattanDistance extends NodeEvaluator2 { if (fromNode == toNode) distances_[fromNode][toNode] = 0; else - distances_[fromNode][toNode] = abs(data.getLocations()[toNode][0] - - data.getLocations()[fromNode][0]) + - abs(data.getLocations()[toNode][1] - - data.getLocations()[fromNode][1]); + distances_[fromNode][toNode] = + abs(data.getLocations()[toNode][0] - data.getLocations()[fromNode][0]) + + abs(data.getLocations()[toNode][1] - data.getLocations()[fromNode][1]); } } } @@ -80,16 +86,18 @@ class ManhattanDistance extends NodeEvaluator2 { } class Vrp { - static { System.loadLibrary("jniortools"); } + static { + System.loadLibrary("jniortools"); + } /// @brief Add Global Span constraint. static void addDistanceDimension(RoutingModel routing, DataProblem data) { String distance = "Distance"; routing.addDimension(new ManhattanDistance(data), - 0, // null slack - 3000, // maximum distance per vehicle - true, // start cumul to zero - distance); + 0, // null slack + 3000, // maximum distance per vehicle + true, // start cumul to zero + distance); RoutingDimension distanceDimension = routing.getDimensionOrDie(distance); // Try to minimize the max distance among vehicles. // /!\ It doesn't mean the standard deviation is minimized @@ -97,8 +105,7 @@ class Vrp { } /// @brief Print the solution - static void printSolution(DataProblem data, RoutingModel routing, - Assignment solution) { + static void printSolution(DataProblem data, RoutingModel routing, Assignment solution) { // Solution cost. System.out.println("Objective : " + solution.objectiveValue()); // Inspect solution. @@ -123,8 +130,8 @@ class Vrp { DataProblem data = new DataProblem(); // Create Routing Model - RoutingModel routing = new RoutingModel( - data.getLocationNumber(), data.getVehicleNumber(), data.getDepot()); + RoutingModel routing = + new RoutingModel(data.getLocationNumber(), data.getVehicleNumber(), data.getDepot()); // Setting the cost function. // [todo]: protect callback from the GC @@ -136,8 +143,7 @@ class Vrp { RoutingSearchParameters search_parameters = RoutingSearchParameters.newBuilder() .mergeFrom(RoutingModel.defaultSearchParameters()) - .setFirstSolutionStrategy( - FirstSolutionStrategy.Value.PATH_CHEAPEST_ARC) + .setFirstSolutionStrategy(FirstSolutionStrategy.Value.PATH_CHEAPEST_ARC) .build(); Assignment solution = routing.solveWithParameters(search_parameters); @@ -145,5 +151,7 @@ class Vrp { } /// @brief Entry point of the program. - public static void main(String[] args) throws Exception { solve(); } + public static void main(String[] args) throws Exception { + solve(); + } } diff --git a/ortools/sat/samples/BinPackingProblem.java b/ortools/sat/samples/BinPackingProblem.java index 2b229831e3..91f918accb 100644 --- a/ortools/sat/samples/BinPackingProblem.java +++ b/ortools/sat/samples/BinPackingProblem.java @@ -17,8 +17,9 @@ import com.google.ortools.sat.CpSolver; import com.google.ortools.sat.IntVar; public class BinPackingProblem { - - static { System.loadLibrary("jniortools"); } + static { + System.loadLibrary("jniortools"); + } public static void main(String[] args) throws Exception { // Data. @@ -81,8 +82,7 @@ public class BinPackingProblem { // slack[b] => load[b] <= safeCapacity. model.addLessOrEqual(load[b], safeCapacity).onlyEnforceIf(slacks[b]); // not(slack[b]) => load[b] > safeCapacity. - model.addGreaterOrEqual(load[b], safeCapacity + 1) - .onlyEnforceIf(slacks[b].not()); + model.addGreaterOrEqual(load[b], safeCapacity + 1).onlyEnforceIf(slacks[b].not()); } // Maximize sum of slacks. @@ -93,8 +93,7 @@ public class BinPackingProblem { CpSolverStatus status = solver.solve(model); System.out.println("Solve status: " + status); if (status == CpSolverStatus.OPTIMAL) { - System.out.printf("Optimal objective value: %f%n", - solver.objectiveValue()); + System.out.printf("Optimal objective value: %f%n", solver.objectiveValue()); for (int b = 0; b < numBins; ++b) { System.out.printf("load_%d = %d%n", b, solver.value(load[b])); for (int i = 0; i < numItems; ++i) { diff --git a/ortools/sat/samples/BoolOrSample.java b/ortools/sat/samples/BoolOrSample.java index 4cd1421e55..f6337d69b7 100644 --- a/ortools/sat/samples/BoolOrSample.java +++ b/ortools/sat/samples/BoolOrSample.java @@ -16,8 +16,9 @@ import com.google.ortools.sat.IntVar; import com.google.ortools.sat.Literal; public class BoolOrSample { - - static { System.loadLibrary("jniortools"); } + static { + System.loadLibrary("jniortools"); + } public static void main(String[] args) throws Exception { CpModel model = new CpModel(); diff --git a/ortools/sat/samples/ChannelingSample.java b/ortools/sat/samples/ChannelingSample.java index fd4c2814ed..a9f61cdbcb 100644 --- a/ortools/sat/samples/ChannelingSample.java +++ b/ortools/sat/samples/ChannelingSample.java @@ -19,8 +19,9 @@ import com.google.ortools.sat.CpSolverSolutionCallback; import com.google.ortools.sat.IntVar; public class ChannelingSample { - - static { System.loadLibrary("jniortools"); } + static { + System.loadLibrary("jniortools"); + } public static void main(String[] args) throws Exception { // Model. @@ -42,8 +43,7 @@ public class ChannelingSample { model.addEquality(y, 0).onlyEnforceIf(b.not()); // Searches for x values in increasing order. - model.addDecisionStrategy( - new IntVar[] {x}, + model.addDecisionStrategy(new IntVar[] {x}, DecisionStrategyProto.VariableSelectionStrategy.CHOOSE_FIRST, DecisionStrategyProto.DomainReductionStrategy.SELECT_MIN_VALUE); @@ -51,8 +51,7 @@ public class ChannelingSample { CpSolver solver = new CpSolver(); // Forces the solver to follow the decision strategy exactly. - solver.getParameters().setSearchBranching( - SatParameters.SearchBranching.FIXED_SEARCH); + solver.getParameters().setSearchBranching(SatParameters.SearchBranching.FIXED_SEARCH); // Solves the problem with the printer callback. solver.searchAllSolutions(model, new CpSolverSolutionCallback() { diff --git a/ortools/sat/samples/CodeSample.java b/ortools/sat/samples/CodeSample.java index 849f770ef4..f261fe270e 100644 --- a/ortools/sat/samples/CodeSample.java +++ b/ortools/sat/samples/CodeSample.java @@ -15,8 +15,9 @@ import com.google.ortools.sat.CpModel; import com.google.ortools.sat.IntVar; public class CodeSample { - - static { System.loadLibrary("jniortools"); } + static { + System.loadLibrary("jniortools"); + } public static void main(String[] args) throws Exception { // Creates the model. diff --git a/ortools/sat/samples/CpIsFun.java b/ortools/sat/samples/CpIsFun.java index 12db1f31b2..faff4b8fca 100644 --- a/ortools/sat/samples/CpIsFun.java +++ b/ortools/sat/samples/CpIsFun.java @@ -17,8 +17,9 @@ import com.google.ortools.sat.CpSolverSolutionCallback; import com.google.ortools.sat.IntVar; public class CpIsFun { - - static { System.loadLibrary("jniortools"); } + static { + System.loadLibrary("jniortools"); + } static class VarArraySolutionPrinter extends CpSolverSolutionCallback { public VarArraySolutionPrinter(IntVar[] variables) { @@ -34,7 +35,9 @@ public class CpIsFun { solutionCount++; } - public int getSolutionCount() { return solutionCount; } + public int getSolutionCount() { + return solutionCount; + } private int solutionCount; private final IntVar[] variableArray; @@ -67,10 +70,9 @@ public class CpIsFun { // CP + IS + FUN = TRUE model.addScalProdEqual(new IntVar[] {c, p, i, s, f, u, n, t, r, u, e}, - new long[] {base, 1, base, 1, base * base, base, 1, - -base * base * base, -base * base, -base, - -1}, - 0); + new long[] { + base, 1, base, 1, base * base, base, 1, -base * base * base, -base * base, -base, -1}, + 0); // [END constraints] // [START solve] diff --git a/ortools/sat/samples/IntervalSample.java b/ortools/sat/samples/IntervalSample.java index e6e7adcbd5..a7ff32154c 100644 --- a/ortools/sat/samples/IntervalSample.java +++ b/ortools/sat/samples/IntervalSample.java @@ -16,8 +16,9 @@ import com.google.ortools.sat.IntVar; import com.google.ortools.sat.IntervalVar; public class IntervalSample { - - static { System.loadLibrary("jniortools"); } + static { + System.loadLibrary("jniortools"); + } public static void main(String[] args) throws Exception { CpModel model = new CpModel(); @@ -26,8 +27,7 @@ public class IntervalSample { IntVar endVar = model.newIntVar(0, horizon, "end"); // Java code supports IntVar or integer constants in intervals. int duration = 10; - IntervalVar interval = - model.newIntervalVar(startVar, duration, endVar, "interval"); + IntervalVar interval = model.newIntervalVar(startVar, duration, endVar, "interval"); System.out.println(interval); } diff --git a/ortools/sat/samples/LiteralSample.java b/ortools/sat/samples/LiteralSample.java index cc8298488b..2a497e9d39 100644 --- a/ortools/sat/samples/LiteralSample.java +++ b/ortools/sat/samples/LiteralSample.java @@ -16,8 +16,9 @@ import com.google.ortools.sat.IntVar; import com.google.ortools.sat.Literal; public class LiteralSample { - - static { System.loadLibrary("jniortools"); } + static { + System.loadLibrary("jniortools"); + } public static void main(String[] args) throws Exception { CpModel model = new CpModel(); diff --git a/ortools/sat/samples/NoOverlapSample.java b/ortools/sat/samples/NoOverlapSample.java index 868f85ca6a..00e3ba7372 100644 --- a/ortools/sat/samples/NoOverlapSample.java +++ b/ortools/sat/samples/NoOverlapSample.java @@ -22,8 +22,9 @@ import com.google.ortools.sat.IntervalVar; * day as early as possible. */ public class NoOverlapSample { - - static { System.loadLibrary("jniortools"); } + static { + System.loadLibrary("jniortools"); + } public static void main(String[] args) throws Exception { CpModel model = new CpModel(); @@ -57,8 +58,7 @@ public class NoOverlapSample { // overlap. In this example, as we use 3 fixed intervals that span over // weekends, this constraint makes sure that all tasks are executed on // weekdays. - model.addNoOverlap( - new IntervalVar[] {task0, task1, task2, weekend0, weekend1, weekend2}); + model.addNoOverlap(new IntervalVar[] {task0, task1, task2, weekend0, weekend1, weekend2}); // Makespan objective. IntVar obj = model.newIntVar(0, horizon, "makespan"); diff --git a/ortools/sat/samples/OptionalIntervalSample.java b/ortools/sat/samples/OptionalIntervalSample.java index 9144ce0a64..cd03b45975 100644 --- a/ortools/sat/samples/OptionalIntervalSample.java +++ b/ortools/sat/samples/OptionalIntervalSample.java @@ -17,8 +17,9 @@ import com.google.ortools.sat.IntervalVar; import com.google.ortools.sat.Literal; public class OptionalIntervalSample { - - static { System.loadLibrary("jniortools"); } + static { + System.loadLibrary("jniortools"); + } public static void main(String[] args) throws Exception { CpModel model = new CpModel(); @@ -28,8 +29,8 @@ public class OptionalIntervalSample { // Java code supports IntVar or integer constants in intervals. int duration = 10; Literal presence = model.newBoolVar("presence"); - IntervalVar interval = model.newOptionalIntervalVar( - startVar, duration, endVar, presence, "interval"); + IntervalVar interval = + model.newOptionalIntervalVar(startVar, duration, endVar, presence, "interval"); System.out.println(interval); } diff --git a/ortools/sat/samples/RabbitsAndPheasants.java b/ortools/sat/samples/RabbitsAndPheasants.java index b59e0b438a..7b50f4acf0 100644 --- a/ortools/sat/samples/RabbitsAndPheasants.java +++ b/ortools/sat/samples/RabbitsAndPheasants.java @@ -21,8 +21,9 @@ import com.google.ortools.sat.IntVar; * rabbits and pheasants are there? */ public class RabbitsAndPheasants { - - static { System.loadLibrary("jniortools"); } + static { + System.loadLibrary("jniortools"); + } public static void main(String[] args) throws Exception { // Creates the model. @@ -40,8 +41,7 @@ public class RabbitsAndPheasants { CpSolverStatus status = solver.solve(model); if (status == CpSolverStatus.FEASIBLE) { - System.out.println(solver.value(r) + " rabbits, and " + solver.value(p) + - " pheasants"); + System.out.println(solver.value(r) + " rabbits, and " + solver.value(p) + " pheasants"); } } } diff --git a/ortools/sat/samples/RankingSample.java b/ortools/sat/samples/RankingSample.java index e6abed8a42..6deded0665 100644 --- a/ortools/sat/samples/RankingSample.java +++ b/ortools/sat/samples/RankingSample.java @@ -25,11 +25,11 @@ import java.util.List; // - rank[i] == -1 iff interval[i] is not active. // - rank[i] == number of active intervals that precede interval[i]. public class RankingSample { + static { + System.loadLibrary("jniortools"); + } - static { System.loadLibrary("jniortools"); } - - static void rankTasks(CpModel model, IntVar[] starts, Literal[] presences, - IntVar[] ranks) { + static void rankTasks(CpModel model, IntVar[] starts, Literal[] presences, IntVar[] ranks) { int numTasks = starts.length; // Creates precedence variables between pairs of intervals. @@ -42,8 +42,7 @@ public class RankingSample { IntVar prec = model.newBoolVar(String.format("%d before %d", i, j)); precedences[i][j] = prec; // Ensure that task i precedes task j if prec is true. - model.addLessOrEqualWithOffset(starts[i], starts[j], 1) - .onlyEnforceIf(prec); + model.addLessOrEqualWithOffset(starts[i], starts[j], 1).onlyEnforceIf(prec); } } } @@ -80,7 +79,7 @@ public class RankingSample { IntVar[] vars = new IntVar[numTasks + 1]; int[] coefs = new int[numTasks + 1]; for (int j = 0; j < numTasks; ++j) { - vars[j] = (IntVar)precedences[j][i]; + vars[j] = (IntVar) precedences[j][i]; coefs[j] = 1; } vars[numTasks] = ranks[i]; @@ -109,8 +108,7 @@ public class RankingSample { int duration = t + 1; ends[t] = model.newIntVar(0, horizon, "end_" + t); if (t < numTasks / 2) { - intervals[t] = - model.newIntervalVar(starts[t], duration, ends[t], "interval_" + t); + intervals[t] = model.newIntervalVar(starts[t], duration, ends[t], "interval_" + t); presences[t] = trueVar; } else { presences[t] = model.newBoolVar("presence_" + t); @@ -146,7 +144,7 @@ public class RankingSample { IntVar[] objectiveVars = new IntVar[numTasks + 1]; int[] objectiveCoefs = new int[numTasks + 1]; for (int t = 0; t < numTasks; ++t) { - objectiveVars[t] = (IntVar)presences[t]; + objectiveVars[t] = (IntVar) presences[t]; objectiveCoefs[t] = -7; } objectiveVars[numTasks] = makespan; @@ -162,11 +160,11 @@ public class RankingSample { System.out.println("Makespan: " + solver.value(makespan)); for (int t = 0; t < numTasks; ++t) { if (solver.booleanValue(presences[t])) { - System.out.printf("Task %d starts at %d with rank %d%n", t, - solver.value(starts[t]), solver.value(ranks[t])); + System.out.printf("Task %d starts at %d with rank %d%n", t, solver.value(starts[t]), + solver.value(ranks[t])); } else { - System.out.printf("Task %d in not performed and ranked at %d%n", t, - solver.value(ranks[t])); + System.out.printf( + "Task %d in not performed and ranked at %d%n", t, solver.value(ranks[t])); } } } else { diff --git a/ortools/sat/samples/ReifiedSample.java b/ortools/sat/samples/ReifiedSample.java index a8d2b1adcd..3b21db020e 100644 --- a/ortools/sat/samples/ReifiedSample.java +++ b/ortools/sat/samples/ReifiedSample.java @@ -28,8 +28,9 @@ import com.google.ortools.sat.Literal; * half-reified constraints must be used. */ public class ReifiedSample { - - static { System.loadLibrary("jniortools"); } + static { + System.loadLibrary("jniortools"); + } public static void main(String[] args) throws Exception { CpModel model = new CpModel(); diff --git a/ortools/sat/samples/SimpleSolve.java b/ortools/sat/samples/SimpleSolve.java index a498e1689a..a2a610f784 100644 --- a/ortools/sat/samples/SimpleSolve.java +++ b/ortools/sat/samples/SimpleSolve.java @@ -18,8 +18,9 @@ import com.google.ortools.sat.IntVar; /** Solve a simple problem with three variables and one different constraint. */ public class SimpleSolve { - - static { System.loadLibrary("jniortools"); } + static { + System.loadLibrary("jniortools"); + } public static void main(String[] args) throws Exception { // Create the model. diff --git a/ortools/sat/samples/SolveAllSolutions.java b/ortools/sat/samples/SolveAllSolutions.java index 7233ba62b2..4cef8911f6 100644 --- a/ortools/sat/samples/SolveAllSolutions.java +++ b/ortools/sat/samples/SolveAllSolutions.java @@ -17,8 +17,9 @@ import com.google.ortools.sat.CpSolverSolutionCallback; import com.google.ortools.sat.IntVar; public class SolveAllSolutions { - - static { System.loadLibrary("jniortools"); } + static { + System.loadLibrary("jniortools"); + } static class VarArraySolutionPrinter extends CpSolverSolutionCallback { public VarArraySolutionPrinter(IntVar[] variables) { @@ -27,15 +28,16 @@ public class SolveAllSolutions { @Override public void onSolutionCallback() { - System.out.printf("Solution #%d: time = %.02f s%n", solutionCount, - wallTime()); + System.out.printf("Solution #%d: time = %.02f s%n", solutionCount, wallTime()); for (IntVar v : variableArray) { System.out.printf(" %s = %d%n", v.getName(), value(v)); } solutionCount++; } - public int getSolutionCount() { return solutionCount; } + public int getSolutionCount() { + return solutionCount; + } private int solutionCount; private final IntVar[] variableArray; @@ -55,8 +57,7 @@ public class SolveAllSolutions { // Create a solver and solve the model. CpSolver solver = new CpSolver(); - VarArraySolutionPrinter cb = - new VarArraySolutionPrinter(new IntVar[] {x, y, z}); + VarArraySolutionPrinter cb = new VarArraySolutionPrinter(new IntVar[] {x, y, z}); solver.searchAllSolutions(model, cb); System.out.println(cb.getSolutionCount() + " solutions found."); diff --git a/ortools/sat/samples/SolveWithIntermediateSolutions.java b/ortools/sat/samples/SolveWithIntermediateSolutions.java index 3f012caff8..f7c551fe8e 100644 --- a/ortools/sat/samples/SolveWithIntermediateSolutions.java +++ b/ortools/sat/samples/SolveWithIntermediateSolutions.java @@ -17,19 +17,18 @@ import com.google.ortools.sat.CpSolverSolutionCallback; import com.google.ortools.sat.IntVar; public class SolveWithIntermediateSolutions { + static { + System.loadLibrary("jniortools"); + } - static { System.loadLibrary("jniortools"); } - - static class VarArraySolutionPrinterWithObjective - extends CpSolverSolutionCallback { + static class VarArraySolutionPrinterWithObjective extends CpSolverSolutionCallback { public VarArraySolutionPrinterWithObjective(IntVar[] variables) { variableArray = variables; } @Override public void onSolutionCallback() { - System.out.printf("Solution #%d: time = %.02f s%n", solutionCount, - wallTime()); + System.out.printf("Solution #%d: time = %.02f s%n", solutionCount, wallTime()); System.out.printf(" objective value = %f%n", objectiveValue()); for (IntVar v : variableArray) { System.out.printf(" %s = %d%n", v.getName(), value(v)); @@ -37,7 +36,9 @@ public class SolveWithIntermediateSolutions { solutionCount++; } - public int getSolutionCount() { return solutionCount; } + public int getSolutionCount() { + return solutionCount; + } private int solutionCount; private final IntVar[] variableArray; diff --git a/ortools/sat/samples/SolveWithTimeLimit.java b/ortools/sat/samples/SolveWithTimeLimit.java index 5a575c21d4..8ec9d52084 100644 --- a/ortools/sat/samples/SolveWithTimeLimit.java +++ b/ortools/sat/samples/SolveWithTimeLimit.java @@ -17,8 +17,9 @@ import com.google.ortools.sat.CpSolver; import com.google.ortools.sat.IntVar; public class SolveWithTimeLimit { - - static { System.loadLibrary("jniortools"); } + static { + System.loadLibrary("jniortools"); + } public static void main(String[] args) throws Exception { // Create the model. diff --git a/ortools/sat/samples/StopAfterNSolutions.java b/ortools/sat/samples/StopAfterNSolutions.java index 0e43ad8566..afb60b7b73 100644 --- a/ortools/sat/samples/StopAfterNSolutions.java +++ b/ortools/sat/samples/StopAfterNSolutions.java @@ -17,11 +17,11 @@ import com.google.ortools.sat.CpSolverSolutionCallback; import com.google.ortools.sat.IntVar; public class StopAfterNSolutions { + static { + System.loadLibrary("jniortools"); + } - static { System.loadLibrary("jniortools"); } - - static class VarArraySolutionPrinterWithLimit - extends CpSolverSolutionCallback { + static class VarArraySolutionPrinterWithLimit extends CpSolverSolutionCallback { public VarArraySolutionPrinterWithLimit(IntVar[] variables, int limit) { variableArray = variables; solutionLimit = limit; @@ -29,8 +29,7 @@ public class StopAfterNSolutions { @Override public void onSolutionCallback() { - System.out.printf("Solution #%d: time = %.02f s%n", solutionCount, - wallTime()); + System.out.printf("Solution #%d: time = %.02f s%n", solutionCount, wallTime()); for (IntVar v : variableArray) { System.out.printf(" %s = %d%n", v.getName(), value(v)); } @@ -41,7 +40,9 @@ public class StopAfterNSolutions { } } - public int getSolutionCount() { return solutionCount; } + public int getSolutionCount() { + return solutionCount; + } private int solutionCount; private final IntVar[] variableArray;