or-tools: setMaxTimeInSeconds does not work properly
Hi all, First of all thanks for the great work behind this library. I found a bug related with the search time limits on the SatSolver, with the next chunk of code (in Java) I will try to show it.
public static final long numIter = 20000;
public static final long SOLVER_TIME = 10;
public static final long DOMAIN_LIMIT = 5000;
public static void main(String[] args) {
CpModel model = new CpModel();
for (int i = 0; i < numIter; i++) {
generateConstraints(model, i%200);
}
CpSolver solver = new CpSolver();
solver.getParameters().setMaxTimeInSeconds(SOLVER_TIME);
solver.getParameters().setMaxDeterministicTime(SOLVER_TIME);
solver.getParameters().setNumSearchWorkers(4);
solver.solve(model);
System.out.println(solver.responseStats());
model.getBuilder().clear();
solver.getParameters().clear();
}
public static void generateConstraints(CpModel model, int i) {
IntVar var1 = model.newIntVar(-DOMAIN_LIMIT / 2, DOMAIN_LIMIT / 2, "Var");
IntVar var2 = model.newIntVar(-DOMAIN_LIMIT / 2, DOMAIN_LIMIT / 2, "Var");
IntVar varSum = model.newIntVar(-DOMAIN_LIMIT, DOMAIN_LIMIT, "Var");
IntVar booleanVar = model.newBoolVar("Var");
model.addLinearSumEqual(new IntVar[] {var1, var2}, varSum);
model.addGreaterOrEqual(varSum, i).onlyEnforceIf(booleanVar);
model.addLessOrEqual(varSum, i).onlyEnforceIf(booleanVar.not());
}
The solver solves the problem in my computer (CPU Intel i5-4460 3.20GHz, RAM 8GB ) in 17 seconds using 4 workers. If only one worker is used, the problem is solved in 23 seconds. Either using 1 or 4 workers the setMaxTimeInSeconds and the setMaxDeterministicTime does not work, since the solver ends after the imposed limit (10 seconds).
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 21
Thank you! I apologise, I don’t know how I missed that, it was right there.
I made a mistake when I paste the code. I deleted the line that makes the solver solve the model
solver.solve(model)
.Anyway, based on the given example in https://developers.google.com/optimization/cp/cp_tasks, the methodology I used to set the parameters is fine (and any other is provided I think), so I guess that
solver.getParameters()
returns a reference of the internal object and not a copy.