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

clean up preprocessing and add functions for modifying c, b, h #792

Merged
merged 9 commits into from
Dec 13, 2021
Merged
4 changes: 2 additions & 2 deletions examples/JuMP_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ function solve_check(
Hypatia.rescale_affine(cone, z_k)
end
if Hypatia.needs_permute(cone)
Hypatia.permute_affine(cone, s_k)
Hypatia.permute_affine(cone, z_k)
s_k = Hypatia.permute_affine(cone, s_k)
z_k = Hypatia.permute_affine(cone, z_k)
end
append!(s, s_k)
append!(z, z_k)
Expand Down
4 changes: 2 additions & 2 deletions src/MathOptInterface/cones.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ end
needs_permute(cone::SpecNucCone) = needs_untransform(cone)

function permute_affine(cone::SpecNucCone, vals::AbstractVector{T}) where {T}
@views vals[2:end] = reshape(vals[2:end], cone.row_dim, cone.column_dim)'
return vals
w_vals = reshape(vals[2:end], cone.row_dim, cone.column_dim)'
return vcat(vals[1], vec(w_vals))
end

function permute_affine(cone::SpecNucCone, func::VAF{T}) where {T}
Expand Down
56 changes: 56 additions & 0 deletions src/MathOptInterface/wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,62 @@ end

MOI.optimize!(opt::Optimizer) = Solvers.solve(opt.solver)

function MOI.modify(
opt::Optimizer{T},
::MOI.ObjectiveFunction{SAF{T}},
chg::MOI.ScalarConstantChange{T},
) where {T}
obj_offset = chg.new_constant
if opt.obj_sense == MOI.MAX_SENSE
obj_offset = -obj_offset
end
Solvers.modify_obj_offset(opt.solver, obj_offset)
return
end

function MOI.modify(
opt::Optimizer{T},
::MOI.ObjectiveFunction{SAF{T}},
chg::MOI.ScalarCoefficientChange{T},
) where {T}
new_c = chg.new_coefficient
if opt.obj_sense == MOI.MAX_SENSE
new_c = -new_c
end
Solvers.modify_c(opt.solver, [chg.variable.value], [new_c])
return
end

function MOI.modify(
opt::Optimizer{T},
ci::MOI.ConstraintIndex{VAF{T}, MOI.Zeros},
chg::MOI.VectorConstantChange{T},
) where {T}
idxs = opt.zeros_idxs[ci.value]
Solvers.modify_b(opt.solver, idxs, chg.new_constant)
return
end

function MOI.modify(
opt::Optimizer{T},
ci::MOI.ConstraintIndex{VAF{T}, <:SupportedCone{T}},
chg::MOI.VectorConstantChange{T},
) where {T}
i = ci.value
idxs = opt.moi_cone_idxs[i]
set = opt.moi_cones[i]
new_h = chg.new_constant
if needs_permute(set)
@assert !needs_rescale(set)
new_h = permute_affine(set, new_h)
end
if needs_rescale(set)
rescale_affine(set, new_h)
end
Solvers.modify_h(opt.solver, idxs, new_h)
return
end

function MOI.get(opt::Optimizer, ::MOI.TerminationStatus)
status = opt.solver.status
if status in (Solvers.NotLoaded, Solvers.Loaded)
Expand Down
Loading