Skip to content

Commit 0869d29

Browse files
authored
Implement VariablePrimal (#115)
1 parent bf0e158 commit 0869d29

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/QCQP/MOI_wrapper.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,23 @@ end
5656

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

59+
function MOI.set(
60+
model::Optimizer,
61+
attr::MOI.AbstractVariableAttribute,
62+
vi::MOI.VariableIndex,
63+
value,
64+
)
65+
return MOI.set(model.model, attr, vi, value)
66+
end
67+
68+
function MOI.get(
69+
model::Optimizer,
70+
attr::MOI.AbstractVariableAttribute,
71+
vi::MOI.VariableIndex,
72+
)
73+
return MOI.get(model.model, attr, vi)
74+
end
75+
5976
function MOI.supports_add_constrained_variable(
6077
model::Optimizer,
6178
::Type{S},

test/qcqp.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,20 @@ function test_scalar_nonlinear_function(x, y, T)
215215
return
216216
end
217217

218+
function test_variable_primal(x, y, T)
219+
inner = Model{T}()
220+
optimizer = MOI.Utilities.MockOptimizer(inner)
221+
model = PolyJuMP.JuMP.direct_generic_model(
222+
T,
223+
PolyJuMP.QCQP.Optimizer{T}(optimizer),
224+
)
225+
PolyJuMP.@variable(model, 1 <= a <= 3)
226+
MOI.set(model, MOI.VariablePrimal(), a, T(2))
227+
MOI.set(model, MOI.TerminationStatus(), MOI.OPTIMAL)
228+
@test MOI.get(model, MOI.TerminationStatus()) == MOI.OPTIMAL
229+
@test PolyJuMP.value(a) == 2
230+
end
231+
218232
function runtests(x, y)
219233
for name in names(@__MODULE__; all = true)
220234
if startswith("$name", "test_")

0 commit comments

Comments
 (0)