Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions src/MathOptLazy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down
Loading