partial sync with main (without the routing part)

This commit is contained in:
Laurent Perron
2024-07-12 13:56:11 +02:00
parent 2c333f58a3
commit 21a75638c2
266 changed files with 13149 additions and 6408 deletions

View File

@@ -18,11 +18,13 @@ import com.google.ortools.Loader;
import com.google.ortools.sat.CpModel;
import com.google.ortools.sat.CpSolver;
import com.google.ortools.sat.CpSolverSolutionCallback;
import com.google.ortools.sat.CpSolverStatus;
import com.google.ortools.sat.IntVar;
import com.google.ortools.sat.LinearExpr;
import java.util.function.Consumer;
/** Solves an optimization problem and displays all intermediate solutions. */
public class SolveAndPrintIntermediateSolutionsSampleSat {
public final class SolveAndPrintIntermediateSolutionsSampleSat {
// [START print_solution]
static class VarArraySolutionPrinterWithObjective extends CpSolverSolutionCallback {
public VarArraySolutionPrinterWithObjective(IntVar[] variables) {
@@ -46,6 +48,27 @@ public class SolveAndPrintIntermediateSolutionsSampleSat {
private int solutionCount;
private final IntVar[] variableArray;
}
static class BestBoundCallback implements Consumer<Double> {
public BestBoundCallback() {
bestBound = 0.0;
numImprovements = 0;
}
@Override
public void accept(Double bound) {
bestBound = bound;
numImprovements++;
}
public double getBestBound() {
return bestBound;
}
double bestBound;
int numImprovements;
}
// [END print_solution]
public static void main(String[] args) throws Exception {
@@ -79,10 +102,18 @@ public class SolveAndPrintIntermediateSolutionsSampleSat {
CpSolver solver = new CpSolver();
VarArraySolutionPrinterWithObjective cb =
new VarArraySolutionPrinterWithObjective(new IntVar[] {x, y, z});
solver.solve(model, cb);
solver.getParameters().setNumWorkers(1);
solver.getParameters().setLinearizationLevel(2);
BestBoundCallback bestBoundCallback = new BestBoundCallback();
solver.setBestBoundCallback(bestBoundCallback);
CpSolverStatus unusedStatus = solver.solve(model, cb);
// [END solve]
System.out.println(cb.getSolutionCount() + " solutions found.");
System.out.println("solution count: " + cb.getSolutionCount());
System.out.println("best bound count: " + bestBoundCallback.numImprovements);
}
private SolveAndPrintIntermediateSolutionsSampleSat() {}
}
// [END program]