Heuristic does not switch off
AnsweredI want to turn off all heuristics to compare two different models. I turn off the heuristics by setting the heuristics parameter to zero. However, the log file still reports solutions found by heuristics. Is it possible to completely turn off all heuristics?
Below is a small example that demonstrates this behavior.
import gurobipy as gp
from gurobipy import GRB
# Data
V = [0, 1]
T = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
p = [8, 1]
r = [[1], [2]]
R = [0]
R_k = [2]
E = []
# MIP model
mip = gp.Model('RCPSP')
# Decision variabels
x = mip.addVars(V, T, vtype=GRB.BINARY, name="x")
C = mip.addVar(vtype=GRB.CONTINUOUS, name="C")
# Constraints
mip.addConstrs((gp.quicksum(x[j,t] for t in T) == 1
for j in V),
name='start_once')
mip.addConstrs((gp.quicksum(x[i, tau] for tau in range(0, tp[j]+1))
 gp.quicksum(x[j, tau] for tau in range(0, t+1) >= 0)
for i,j in E
for t in T),
name='precedence')
mip.addConstrs((gp.quicksum(r[j][k]*x[j,tau] for j in V for tau in range(tp[j]+1, t+1) if tau > 0) <= R_k[k]
for k in R
for t in T),
name="resources")
mip.addConstrs((gp.quicksum((t+p[j]1)*x[j, t] for t in T) <= C
for j in V ),
name='makespan')
# Objective
mip.setObjective((C), GRB.MINIMIZE)
# Parameter
mip.setParam("Heuristics", 0.00)
mip.optimize()

There is no guaranteed way to prevent Gurobi from using all heuristic solutions. When you set the Heuristics parameter to 0, Gurobi spends no time looking for heuristic solutions. However, it could happen that Gurobi still encounters solutions as part of its solving process, even without devoting any additional meaningful work to finding them. These are reported as heuristic solutions.
For this small model, if you really want Gurobi to ignore the heuristic solution, you could try setting the Threads parameter to 1. In general, limiting the number of threads does not necessarily prevent Gurobi from finding these "free" solutions. This small model is a special case, since Gurobi finds the heuristic solution in a secondary thread helping at the root node.
Note that setting Threads to 1 typically has a negative effect on solver performance, because you are limiting the computing resources available to Gurobi.
0
Please sign in to leave a comment.
Comments
1 comment