Greetings,
I have a JuMP model that is being instantiated at some point of my code.
I will be running optimize!(model)
several times and, for each, I would like to change the value of the coefficient given as a parameter to the create_model()
function.
The following MWE is working for now, but I was wondering if there was a more efficient way (in terms of performance) to change the value of this coefficient.
using JuMP
using HiGHS
function create_model(value::Float64)
model = Model(HiGHS.Optimizer)
@variable(model, x[1:5] >= 5)
@objective(model, Min, sum(x[i]*value for i in 1:5))
return model
end
model = create_model(1.0)
MOI.modify(model.moi_backend,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(),
[MOI.ScalarCoefficientChange(MOI.VariableIndex(model[:x][i]), 2.0)
for i in 1:5]
)
I thought about creating an expression @expression(model, value, 0.0)
and changing its value, but could not find the documentation for it.
Does anyone know what is the best option?
Thanks in advance!