Skip to content

Instantly share code, notes, and snippets.

@ericphanson
Created October 27, 2019 21:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericphanson/9ab9f8460bbe5200be82d0b0cb55ecd5 to your computer and use it in GitHub Desktop.
Save ericphanson/9ab9f8460bbe5200be82d0b0cb55ecd5 to your computer and use it in GitHub Desktop.
Problem trying to warmstart
using SCS
using MathOptInterface # MathOptInterface v0.9.6
const MOI = MathOptInterface
const MOIU = MOI.Utilities
const MOIB = MOI.Bridges
function make_model(vector)
optimizer = SCS.Optimizer(verbose=false)
T = Float64
model = MOIB.full_bridge_optimizer(
MOIU.CachingOptimizer(
MOIU.UniversalFallback(MOIU.Model{T}()),
optimizer
),
T
)
vars = MOI.add_variables(model, 3)
# Add objective
obj_terms = [ MOI.ScalarAffineTerm(one(T), vars[k]) for k in 1:3 ]
obj = MOI.ScalarAffineFunction{T}(obj_terms, zero(T))
MOI.set(model, MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}(), obj)
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
# Add constraint
VAF = MOI.VectorAffineFunction{T}([ MOI.VectorAffineTerm{T}(k, MOI.ScalarAffineTerm{T}(vector[k], vars[k])) for k = 1:3], zeros(T, 3))
constr_indices = MOI.add_constraint(model, VAF, MOI.Zeros(3))
return model, constr_indices
end
vector = rand(3)
model, constr_indices = make_model(vector)
MOI.optimize!(model) # works
dual_value = MOI.get(model, MOI.ConstraintDual(), constr_indices)
# Get a fresh model
model, constr_indices = make_model(vector)
# Attempt to warmstart
MOI.set(model, MOI.ConstraintDualStart(), constr_indices, dual_value) # works
MOI.optimize!(model) # errors
@ericphanson
Copy link
Author

I can confirm it works for me on the brand new 0.9.7 :). Thanks very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment