Hi, I’m using JuMP to build LP-problems and later I want to update the objective coefficients with the function set_objective_coefficient instead of building the whole LP again. Below are the functions I defined and the time it took to run them. They seem to be slow. Please help me make the code faster.
function BuildFull(Big::Float64)::JuMP.Model
M = Model(with_optimizer(CPLEX.Optimizer))
NArea = 57
NMod = 20
NKOpt = 168
InfUB = 1.0E8
@variable(M,0.0 <= spi[iArea=1:NArea,iMod=1:NMod,k=1:NKOpt] <= InfUB, base_name="spi")
@objective(M,MathOptInterface.MIN_SENSE, sum(spi[iArea,iMod,k] for iArea=1:NArea for iMod=1:NMod for k=1:NKOpt))
return M
end
function update_coeff!(model::JuMP.Model)
iMod = 1
spi = model[:spi]
for iArea=1:NArea
for k=1:NKOpt
spi_coeff = 2.0
set_objective_coefficient(model, spi[iArea,iMod,k], spi_coeff)
end
end
return nothing
end
I time the functions with the @time macro
using JuMP
using CPLEX
using MathOptFormat
using MathOptInterface
const MOI = MathOptInterface
const Big = 1.0E18
model = @time BuildFull(Big)
@time update_coeff!(model)
The @time macro returns the following:
0.575319 seconds (2.38 M allocations: 127.048 MiB, 51.21% gc time)
20.401694 seconds (94.43 k allocations: 27.333 GiB, 20.58% gc time)
This is the second run. 20 seconds seems a long time.
Is it possible to speed things up?
Tips to increase performance of @variable is also appreciated.
These are the package versions I use:
julia> Pkg.installed()
Dict{String,Union{Nothing, VersionNumber}} with 14 entries:
"Distributions" => v"0.24.3"
"Clp" => v"0.8.3"
"Atom" => v"0.12.25"
"CPLEX" => v"0.6.2"
"JuMP" => v"0.20.1"
"Juno" => v"0.8.4"
"DelimitedFiles" => nothing
"MathOptFormat" => v"0.4.0"
"StatsBase" => v"0.33.2"
"HDF5" => v"0.12.5"
"Plots" => v"1.4.3"
"Cbc" => v"0.7.1"
"MathOptInterface" => v"0.9.8"
"Printf" => nothing