Skip to content

Commit

Permalink
Add method to comply with JuMP's is_parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquimg committed Sep 27, 2024
1 parent bc64222 commit 8f143b6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,17 @@ function MOI.is_valid(model::Optimizer, vi::MOI.VariableIndex)
return false
end

function MOI.is_valid(
model::Optimizer,
ci::MOI.ConstraintIndex{MOI.VariableIndex,MOI.Parameter{T}},
) where {T}
vi = MOI.VariableIndex(ci.value)
if haskey(model.parameters, p_idx(vi))
return true
end
return false

Check warning on line 160 in src/MOI_wrapper.jl

View check run for this annotation

Codecov / codecov/patch

src/MOI_wrapper.jl#L160

Added line #L160 was not covered by tests
end

function MOI.supports(
model::Optimizer,
attr::MOI.VariableName,
Expand Down
1 change: 1 addition & 0 deletions test/moi_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function test_basic_tests()
y, cy = MOI.add_constrained_variable(optimizer, MOI.Parameter(0.0))
@test MOI.is_valid(optimizer, x[1])
@test MOI.is_valid(optimizer, y)
@test MOI.is_valid(optimizer, cy)
@test MOI.get(optimizer, POI.ListOfPureVariableIndices()) == x
@test MOI.get(optimizer, MOI.ListOfVariableIndices()) == [x[1], x[2], y]
z = MOI.VariableIndex(4)
Expand Down

0 comments on commit 8f143b6

Please sign in to comment.