Skip to content

Commit

Permalink
Fix MOI.is_valid for ConstraintIndex{VariableIndex,Parameter} (#415)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Jun 6, 2024
1 parent f5b6ecb commit 92bf61e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ function MOI.add_constrained_variable(
return p, ci
end

function MOI.is_valid(
model::Optimizer,
ci::MOI.ConstraintIndex{MOI.VariableIndex,MOI.Parameter{Float64}},
)
p = MOI.VariableIndex(ci.value)
return haskey(model.parameters, p)
end

function MOI.set(
model::Optimizer,
::MOI.ConstraintSet,
Expand Down
10 changes: 10 additions & 0 deletions test/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,16 @@ function test_parameter_number_of_variables()
return
end

function test_parameter_is_valid()
model = Ipopt.Optimizer()
p, ci = MOI.add_constrained_variable(model, MOI.Parameter(2.0))
@test MOI.is_valid(model, p)
@test MOI.is_valid(model, ci)
@test !MOI.is_valid(model, typeof(p)(p.value + 1))
@test !MOI.is_valid(model, typeof(ci)(ci.value + 1))
return
end

function test_parameter_list_of_variable_indices()
model = Ipopt.Optimizer()
x = MOI.add_variable(model)
Expand Down

0 comments on commit 92bf61e

Please sign in to comment.