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

Fix MOI.get for quadratic constraints #151

Merged
merged 3 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
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
38 changes: 10 additions & 28 deletions src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -452,18 +452,18 @@ end
function MOI.set(
model::Optimizer,
::MOI.ConstraintFunction,
c::MOI.ConstraintIndex{F,S},
c::MOI.ConstraintIndex{F},
f::F,
) where {F,S}
) where {F}
MOI.set(model.optimizer, MOI.ConstraintFunction(), c, f)
return
end

function MOI.get(
model::Optimizer,
attr::MOI.ConstraintFunction,
ci::MOI.ConstraintIndex{F,S},
) where {F,S}
ci::MOI.ConstraintIndex,
)
if haskey(model.quadratic_outer_to_inner, ci)
inner_ci = model.quadratic_outer_to_inner[ci]
return _original_function(model.quadratic_constraint_cache[inner_ci])
Expand Down Expand Up @@ -501,8 +501,8 @@ end
function MOI.get(
model::Optimizer,
attr::MOI.ConstraintSet,
ci::MOI.ConstraintIndex{F,S},
) where {F,S}
ci::MOI.ConstraintIndex,
)
if haskey(model.quadratic_outer_to_inner, ci)
inner_ci = model.quadratic_outer_to_inner[ci]
return model.quadratic_constraint_cache_set[inner_ci]
Expand Down Expand Up @@ -1084,29 +1084,11 @@ end

function MOI.get(
model::Optimizer,
attr::T,
attr::MOI.AbstractConstraintAttribute,
c::MOI.ConstraintIndex,
) where {
T<:Union{MOI.ConstraintPrimal,MOI.ConstraintDual,MOI.ConstraintBasisStatus},
}
return MOI.get(model.optimizer, attr, c)
end

function MOI.get(
model::Optimizer,
attr::AT,
c::MOI.ConstraintIndex{MOI.ScalarAffineFunction{T},S},
) where {
AT<:Union{
MOI.ConstraintPrimal,
MOI.ConstraintDual,
MOI.ConstraintBasisStatus,
},
T,
S<:MOI.AbstractScalarSet,
}
moi_ci = get(model.affine_outer_to_inner, c, c)
return MOI.get(model.optimizer, attr, moi_ci)
)
optimizer_ci = get(model.constraint_outer_to_inner, c, c)
return MOI.get(model.optimizer, attr, optimizer_ci)
end

#
Expand Down
10 changes: 10 additions & 0 deletions test/jump_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1079,3 +1079,13 @@ function test_abstract_optimizer_attributes()
@test get_attribute(model, "tm_lim") 60 * 1000
return
end

function test_get_quadratic_constraint()
model = Model(() -> POI.Optimizer(GLPK.Optimizer()))
@variable(model, x)
@variable(model, p in Parameter(2.0))
@constraint(model, c, p * x <= 10)
optimize!(model)
@test value(c) 2.0 * value(x)
return
end
Loading