-
Notifications
You must be signed in to change notification settings - Fork 27
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
Fix start value #138
Fix start value #138
Conversation
maybe I'm using it wrong but here is what I tried: function example_problem(m = Model())
@variable(m, x >= 0)
@variable(m, y <= 2)
@variable(m, P[1:2,1:2] >= 0)
@objective(m, Max, x+y + P[1,1] - P[2,2])
@constraint(m, x <= y+4)
@constraint(m, P[1,1] + P[2,2] <= 4)
@constraint(m, P[2,1] - P[1,1] <= 4)
return m
end
m = example_problem()
optimize!(m, with_optimizer(SCS.Optimizer, eps=1e-10))
solvedx = value(m[:x])
solvedy = value(m[:y])
solvedP = value.(m[:P])
m2 = example_problem()
set_start_value(m2[:x], solvedx)
set_start_value(m2[:y], solvedy)
set_start_value.(m2[:P], solvedP)
optimize!(m2, with_optimizer(SCS.Optimizer, eps=1e-10, max_iters=3, warm_start=true))
@assert termination_status(m2) == termination_status(m) # fails I can however overwrite SCS.MOISolution: primal = backend(m).optimizer.model.optimizer.sol.primal
dual = backend(m).optimizer.model.optimizer.sol.dual
slack = backend(m).optimizer.model.optimizer.sol.slack
m3 = example_problem(Model(with_optimizer(SCS.Optimizer, eps=1e-10, max_iters=3, warm_start=true)))
m3.moi_backend.optimizer.model.optimizer.sol.primal = primal
m3.moi_backend.optimizer.model.optimizer.sol.dual = dual
m3.moi_backend.optimizer.model.optimizer.sol.slack = slack
optimize!(m3)
@assert termination_status(m3) == termination_status(m) # this works |
What is the termination status for |
m2 = example_problem()
set_start_value(m2[:x], solvedx)
set_start_value(m2[:y], solvedy)
set_start_value.(m2[:P], solvedP)
with_SCS_3iters = with_optimizer(SCS.Optimizer, eps=1e-10, max_iters=3, warm_start=true)
optimize!(m2, with_SCS_3iters)
termination_status(m2)
compare with the same problem where start values are not set: m2 = example_problem()
# set_start_value(m2[:x], solvedx)
# set_start_value(m2[:y], solvedy)
# set_start_value.(m2[:P], solvedP)
with_SCS_3iters = with_optimizer(SCS.Optimizer, eps=1e-10, max_iters=3, warm_start=true)
optimize!(m2, with_SCS_3iters)
termination_status(m2)
|
Isn't the difference between |
SCS will ignore primal when dual and slack are not set: So maybe the question should be: is it possible to set dual and slack from the level of MOI? |
sorry for dumb questions, but the documentation is rather sparse at the moment: I tried copying solution from with_SCS = with_optimizer(SCS.Optimizer,
eps=1e-10,
# max_iters=3,
warm_start=true,
verbose=false)
with_SCS_3iters = with_optimizer(SCS.Optimizer,
eps=1e-10,
max_iters=3,
warm_start=true,
verbose=true)
m = example_problem(Model(with_SCS))
optimize!(m)
m2 = example_problem(Model(with_SCS_3iters));
MOI.set(m2, MOI.VariablePrimalStart(), m2[:x], value(m[:x]))
MOI.set(m2, MOI.VariablePrimalStart(), m2[:y], value(m[:y]))
MOI.set.(m2, MOI.VariablePrimalStart(), m2[:P], value.(m[:P]))
# is this how you iterate over constraints?
for (F,S) in MOI.get(m.moi_backend, MOI.ListOfConstraints())
cnstrs = MOI.get(m.moi_backend, MOI.ListOfConstraintIndices{F,S}())
for c in cnstrs
dual_val = MOI.get(m.moi_backend, MOI.ConstraintDual(), c)
slack_val = MOI.get(m.moi_backend, MOI.ConstraintPrimal(), c)
MOI.set(m2.moi_backend, MOI.ConstraintDualStart(), c, dual_val)
MOI.set(m2.moi_backend, MOI.ConstraintPrimalStart(), c, slack_val)
end
end
optimize!(m2) however I still get warnings:
|
Only |
as noted above implementing only (I see that |
Indeed, it seems we only need to add |
You're missing comma after Union; unfortunately I've already tried this and I get the same warnings (and results). note: F = MOI.SingleVariable
S = MOI.EqualTo{Float64}
MOI.supports(Model(with_SCS).moi_backend, MOI.ConstraintDualStart(), MOI.ConstraintIndex{F,S}) still returns the defined |
Good point, we need to implement starting values for bridges |
fix copy-paste typos
Let's first check if it works if all the constraints are natively supported, i.e. |
until jump-dev/SCS.jl#138 is merged
@blegat what do you mean by natively supported? reading jump-dev/MathOptInterface.jl#528 I understand that we need to wait to remove VectorOfVariables support (as this will be transformed by |
Indeed, I was ambiguous, I meant natively supported by the MOI wrapper (i.e. no bridge are needed). So it should work if for a model like model = Model(with_optimizer(SCS.Optimizer))
@variable(model, x[1:2])
@constraint(model, [x[1] - x[2]] in MOI.Nonnegatives(1))
@constraint(model, [1; x] in MOI.SecondOrderCone(2))
@objective(model, Max, sum(x)) |
I have opened an issue for start values in the bridges: jump-dev/MathOptInterface.jl#684 |
Closes #136