Skip to content

Commit 92bf61e

Browse files
authored
Fix MOI.is_valid for ConstraintIndex{VariableIndex,Parameter} (#415)
1 parent f5b6ecb commit 92bf61e

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/MOI_wrapper.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,14 @@ function MOI.add_constrained_variable(
165165
return p, ci
166166
end
167167

168+
function MOI.is_valid(
169+
model::Optimizer,
170+
ci::MOI.ConstraintIndex{MOI.VariableIndex,MOI.Parameter{Float64}},
171+
)
172+
p = MOI.VariableIndex(ci.value)
173+
return haskey(model.parameters, p)
174+
end
175+
168176
function MOI.set(
169177
model::Optimizer,
170178
::MOI.ConstraintSet,

test/MOI_wrapper.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,16 @@ function test_parameter_number_of_variables()
336336
return
337337
end
338338

339+
function test_parameter_is_valid()
340+
model = Ipopt.Optimizer()
341+
p, ci = MOI.add_constrained_variable(model, MOI.Parameter(2.0))
342+
@test MOI.is_valid(model, p)
343+
@test MOI.is_valid(model, ci)
344+
@test !MOI.is_valid(model, typeof(p)(p.value + 1))
345+
@test !MOI.is_valid(model, typeof(ci)(ci.value + 1))
346+
return
347+
end
348+
339349
function test_parameter_list_of_variable_indices()
340350
model = Ipopt.Optimizer()
341351
x = MOI.add_variable(model)

0 commit comments

Comments
 (0)