I’m needing to solve a large number of simple MIPs in succession, and I’m finding that GPLK is 2.5 times faster than Gurobi (with presolve disabled; presolve slows Gurobi further). Is this normal?
I know that for large/complex MIPs Gurobi outperforms GPLK; however, I never realised that the overhead was so large.
Here’s an example:
using JuMP, GLPK, Gurobi, Random
env = Gurobi.Env()
I’ve got a function that generates a number of knapsack problems, with a specified solver:
function test_speed(model_count::Int64, numitems::Int64, solver)
Random.seed!(1)
numinvest = 6;
investcost = zeros(model_count,numinvest)
for m in 1:model_count
investcost[m,:] = ([1,1.8,3.5,6.8,13.5,25])*(1-((m-1)/(model_count*1.2)))/40
end
investvol = [1,2,4,8,16,32]
itemvolume = rand(numitems)*2 + collect(range(4,22,length = numitems))
itemvalue = rand(numitems)
function model_maker(model_index)
model = Model(solver)
@variable(model, bag[1:numinvest], Bin)
@variable(model, y[1:numitems], Bin)
@objective(model, Min,
sum(-itemvalue[i] * y[i] for i in 1:numitems)+
sum(investcost[model_index,i] * bag[i] for i in 1:numinvest))
@constraint(model ,sum( y[i]*itemvolume[i] for i in 1:numitems) <=
sum(bag[i]*investvol[i] for i in 1:numinvest))
model
end
[model_maker(m) for m in 1:model_count]
end
For example, let’s set the number of models to be 1000, and the number of items to be selected from to be 100. We then generate the models for Gurobi and GLPK:
m=1000
n=100
models_Gurobi=test_speed(m,n,
optimizer_with_attributes(() -> Gurobi.Optimizer(env),
"OutputFlag" => 0, "MIPGap" => 0.0, "Presolve" => 0)))
models_GPLK=test_speed(m,n,
optimizer_with_attributes(GLPK.Optimizer,
"msg_lev" => 0, "mip_gap" => 0.0))
Finally, I time how long each takes to solve all the models:
@time for sp in models_Gurobi
optimize!(sp)
end
@time for sp in models_GPLK
optimize!(sp)
end
Here’s the output. The first is for Gurobi, the second is for GLPK.
5.455270 seconds (2.72 M allocations: 152.580 MiB, 11.94% gc time)
1.873296 seconds (3.06 M allocations: 171.813 MiB)
I ran these a few times to check the results, and they were consistent. I also checked that the solvers were getting the same answers, and they were. I finally tested CPLEX, and it is ever slower than Gurobi. Is this typical behaviour?
Is GPLK really the best solver for small MIPs, or are there some additional settings that I should be using?
Thanks.