Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rebuild IpoptProblem only if modified #321

Merged
merged 11 commits into from
Aug 17, 2022
24 changes: 21 additions & 3 deletions src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ MOI.supports(::Optimizer, ::MOI.RawOptimizerAttribute) = true

function MOI.set(model::Optimizer, p::MOI.RawOptimizerAttribute, value)
model.options[p.name] = value
# No need to reset model.inner because this gets handled in optimize!.
return
end

Expand All @@ -191,6 +192,7 @@ function MOI.add_variable(model::Optimizer)
push!(model.variable_primal_start, nothing)
push!(model.mult_x_L, nothing)
push!(model.mult_x_U, nothing)
model.inner = nothing
return MOI.add_variable(model.variables)
end

Expand Down Expand Up @@ -231,7 +233,8 @@ function MOI.get(
end

function MOI.add_constraint(model::Optimizer, x::MOI.VariableIndex, set::_SETS)
return MOI.add_constraint(model.variables, x, set)
index = MOI.add_constraint(model.variables, x, set)
model.inner = nothing
odow marked this conversation as resolved.
Show resolved Hide resolved
odow marked this conversation as resolved.
Show resolved Hide resolved
end

function MOI.set(
Expand All @@ -241,6 +244,7 @@ function MOI.set(
set::S,
) where {S<:_SETS}
MOI.set(model.variables, MOI.ConstraintSet(), ci, set)
model.inner = nothing
return
end

Expand All @@ -249,6 +253,7 @@ function MOI.delete(
ci::MOI.ConstraintIndex{MOI.VariableIndex,<:_SETS},
)
MOI.delete(model.variables, ci)
model.inner = nothing
return
end

Expand All @@ -262,7 +267,9 @@ function MOI.is_valid(
end

function MOI.add_constraint(model::Optimizer, func::_FUNCTIONS, set::_SETS)
return MOI.add_constraint(model.qp_data, func, set)
index = MOI.add_constraint(model.qp_data, func, set)
model.inner = nothing
return index
end

function MOI.get(
Expand Down Expand Up @@ -300,6 +307,7 @@ function MOI.set(
) where {F<:_FUNCTIONS,S<:_SETS}
MOI.throw_if_not_valid(model, ci)
MOI.set(model.qp_data, attr, ci, value)
# No need to reset model.inner, because this gets handled in optimize!.
return
end

Expand All @@ -321,6 +329,7 @@ function MOI.set(
)
MOI.throw_if_not_valid(model, vi)
model.variable_primal_start[column(vi)] = value
# No need to reset model.inner, because this gets handled in optimize!.
return
end

Expand Down Expand Up @@ -348,6 +357,7 @@ function MOI.set(
)
MOI.throw_if_not_valid(model, ci)
model.mult_x_L[ci.value] = value
# No need to reset model.inner, because this gets handled in optimize!.
return
end

Expand All @@ -368,6 +378,7 @@ function MOI.set(
)
MOI.throw_if_not_valid(model, ci)
model.mult_x_U[ci.value] = value
# No need to reset model.inner, because this gets handled in optimize!.
return
end

Expand Down Expand Up @@ -397,6 +408,7 @@ function MOI.set(
model.mult_x_L[ci.value] = 0.0
model.mult_x_U[ci.value] = value
end
# No need to reset model.inner, because this gets handled in optimize!.
return
end

Expand All @@ -421,6 +433,7 @@ function MOI.set(
values::Union{Nothing,Vector},
)
model.nlp_dual_start = values
# No need to reset model.inner, because this gets handled in optimize!.
return
end

Expand All @@ -432,6 +445,7 @@ MOI.supports(::Optimizer, ::MOI.NLPBlock) = true

function MOI.set(model::Optimizer, ::MOI.NLPBlock, nlp_data::MOI.NLPBlockData)
model.nlp_data = nlp_data
model.inner = nothing
return
end

Expand All @@ -445,6 +459,7 @@ function MOI.set(
sense::MOI.OptimizationSense,
)
model.sense = sense
model.inner = nothing
return
end

Expand Down Expand Up @@ -472,6 +487,7 @@ function MOI.set(
func::F,
) where {F<:Union{MOI.VariableIndex,<:_FUNCTIONS}}
MOI.set(model.qp_data, attr, func)
model.inner = nothing
return
end

Expand Down Expand Up @@ -648,7 +664,9 @@ end

function MOI.optimize!(model::Optimizer)
start_time = time()
_setup_model(model)
if model.inner === nothing
_setup_model(model)
end
if model.invalid_model
return
end
Expand Down