diff --git a/src/MathOptLazy.jl b/src/MathOptLazy.jl index 509f3d7..c666178 100644 --- a/src/MathOptLazy.jl +++ b/src/MathOptLazy.jl @@ -407,17 +407,17 @@ end ### MOI.optimize! -function _get_start(model, x) - if !MOI.supports(model, MOI.VariablePrimalStart(), MOI.VariableIndex) - return nothing - end - return Dict(xi => MOI.get(model, MOI.VariablePrimalStart(), xi) for xi in x) -end - function MOI.optimize!(model::Optimizer) needs_solve = true x = MOI.get(model, MOI.ListOfVariableIndices()) - start = _get_start(model, x) + # TODO(odow): if the solver supports VariablePrimalStart, we will update the + # primal starts during the solve process. This is destructive and in-place. + # That is, we will overwrite any start set by the user. We can't restore the + # start at the end of the loop because this may invalidate the inner + # solver's solution. To fix properly, we should cache the start in + # ::Optimizer, but this is a hassle and no one probably cares. Revisit this + # decision if it ever becomes a problem. + start = MOI.supports(model, MOI.VariablePrimalStart(), MOI.VariableIndex) while needs_solve needs_solve = false MOI.optimize!(model.inner) @@ -428,18 +428,13 @@ function MOI.optimize!(model::Optimizer) constraints_added += _add_if_necessary(model, v, X) end needs_solve = constraints_added > 0 - if start !== nothing + if start && needs_solve for (xi, v) in X MOI.set(model, MOI.VariablePrimalStart(), xi, v) end end end end - if start !== nothing - for (xi, v) in start - MOI.set(model, MOI.VariablePrimalStart(), xi, v) - end - end return end