Skip to content

Commit

Permalink
Implement VariablePrimal
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Mar 14, 2024
1 parent f96a40b commit 267b390
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/QCQP/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ end

MOI.add_variable(model::Optimizer) = MOI.add_variable(model.model)

function MOI.set(model::Optimizer, attr::MOI.AbstractVariableAttribute, vi::MOI.VariableIndex, value)
return MOI.set(model.model, attr, vi, value)

Check warning on line 60 in src/QCQP/MOI_wrapper.jl

View check run for this annotation

Codecov / codecov/patch

src/QCQP/MOI_wrapper.jl#L59-L60

Added lines #L59 - L60 were not covered by tests
end

function MOI.get(model::Optimizer, attr::MOI.AbstractVariableAttribute, vi::MOI.VariableIndex)
return MOI.get(model.model, attr, vi)

Check warning on line 64 in src/QCQP/MOI_wrapper.jl

View check run for this annotation

Codecov / codecov/patch

src/QCQP/MOI_wrapper.jl#L63-L64

Added lines #L63 - L64 were not covered by tests
end

function MOI.supports_add_constrained_variable(
model::Optimizer,
::Type{S},
Expand Down
14 changes: 14 additions & 0 deletions test/qcqp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,20 @@ function test_scalar_nonlinear_function(x, y, T)
return
end

function test_variable_primal(x, y, T)
inner = Model{T}()
optimizer = MOI.Utilities.MockOptimizer(inner)
model = PolyJuMP.JuMP.direct_generic_model(
T,
PolyJuMP.QCQP.Optimizer{T}(optimizer),
)
PolyJuMP.@variable(model, 1 <= a <= 3)
MOI.set(model, MOI.VariablePrimal(), a, T(2))
MOI.set(model, MOI.TerminationStatus(), MOI.OPTIMAL)
@test MOI.get(model, MOI.TerminationStatus()) == MOI.OPTIMAL
@test PolyJuMP.value(a) == 2
end

function runtests(x, y)
for name in names(@__MODULE__; all = true)
if startswith("$name", "test_")
Expand Down

0 comments on commit 267b390

Please sign in to comment.