From 8f143b6549f2dde5ddadd9a36d3173fe8945f620 Mon Sep 17 00:00:00 2001 From: joaquimg Date: Fri, 27 Sep 2024 02:00:28 -0700 Subject: [PATCH] Add method to comply with JuMP's is_parameter --- src/MOI_wrapper.jl | 11 +++++++++++ test/moi_tests.jl | 1 + 2 files changed, 12 insertions(+) diff --git a/src/MOI_wrapper.jl b/src/MOI_wrapper.jl index b8bbf63..853fa86 100644 --- a/src/MOI_wrapper.jl +++ b/src/MOI_wrapper.jl @@ -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 +end + function MOI.supports( model::Optimizer, attr::MOI.VariableName, diff --git a/test/moi_tests.jl b/test/moi_tests.jl index 6e3350c..29d40bd 100644 --- a/test/moi_tests.jl +++ b/test/moi_tests.jl @@ -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)