Skip to content

Commit f11a00f

Browse files
guimarquamontoison
authored andcommitted
Add support of MOI.is_valid for MOI.ConstraintIndex{MOI.VariableIndex,MOI.Parameter}}
1 parent 3dcd038 commit f11a00f

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

ext/MadNLPMOI/MadNLPMOI.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,11 @@ function MOI.is_valid(model::Optimizer, x::MOI.VariableIndex)
315315
return MOI.is_valid(model.variables, x)
316316
end
317317

318+
function MOI.is_valid(model::Optimizer, ci::MOI.ConstraintIndex{MOI.VariableIndex, MOI.Parameter{Float64}})
319+
p = MOI.VariableIndex(ci.value)
320+
return haskey(model.parameters, p)
321+
end
322+
318323
function MOI.get(model::Optimizer, ::MOI.ListOfVariableIndices)
319324
return model.list_of_variable_indices
320325
end
@@ -856,6 +861,7 @@ function MOIModel(model::Optimizer)
856861
clamp(0.0, model.variables.lower[i], model.variables.upper[i])
857862
end
858863
end
864+
859865
# Constraints bounds
860866
g_L, g_U = copy(model.qp_data.g_L), copy(model.qp_data.g_U)
861867
for bound in model.nlp_data.constraint_bounds

test/MOI_interface_test.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,16 @@ function test_param_in_quadratic_term2()
190190
@assert abs(3 * x_val + 9 * y_val - 15) <= 1e-6 # constraint has no slack
191191
end
192192

193+
function test_parameter_is_valid()
194+
model = MadNLP.Optimizer()
195+
p, ci = MOI.add_constrained_variable(model, MOI.Parameter(2.0))
196+
@test MOI.is_valid(model, p)
197+
@test MOI.is_valid(model, ci)
198+
@test !MOI.is_valid(model, typeof(p)(p.value + 1))
199+
@test !MOI.is_valid(model, typeof(ci)(ci.value + 1))
200+
return
201+
end
202+
193203
end
194204

195205
TestMOIWrapper.runtests()

0 commit comments

Comments
 (0)