From 6e2188cc304d1928f75299edb706e596e152c549 Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Mon, 25 Nov 2024 11:31:12 +1300 Subject: [PATCH] Rename _function_type_to_set to _function_type_to_func and test (#443) --- src/utils.jl | 8 ++++---- test/MOI_wrapper.jl | 9 +++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/utils.jl b/src/utils.jl index 2ab285a..cedaed5 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -18,7 +18,7 @@ _kFunctionTypeScalarQuadratic, ) -function _function_type_to_set(::Type{T}, k::_FunctionType) where {T} +function _function_type_to_func(::Type{T}, k::_FunctionType) where {T} if k == _kFunctionTypeVariableIndex return MOI.VariableIndex elseif k == _kFunctionTypeScalarAffine @@ -299,7 +299,7 @@ function MOI.set( end function MOI.get(block::QPBlockData{T}, ::MOI.ObjectiveFunctionType) where {T} - return _function_type_to_set(T, block.objective_function_type) + return _function_type_to_func(T, block.objective_function_type) end function MOI.get(block::QPBlockData{T}, ::MOI.ObjectiveFunction{F}) where {T,F} @@ -312,7 +312,7 @@ function MOI.get( ) where {T} constraints = Set{Tuple{Type,Type}}() for i in 1:length(block) - F = _function_type_to_set(T, block.function_type[i]) + F = _function_type_to_func(T, block.function_type[i]) S = _bound_type_to_set(T, block.bound_type[i]) push!(constraints, (F, S)) end @@ -342,7 +342,7 @@ function MOI.get( for i in 1:length(block) if _bound_type_to_set(T, block.bound_type[i]) != S continue - elseif _function_type_to_set(T, block.function_type[i]) != F + elseif _function_type_to_func(T, block.function_type[i]) != F continue end push!(ret, MOI.ConstraintIndex{F,S}(i)) diff --git a/test/MOI_wrapper.jl b/test/MOI_wrapper.jl index f6b63dc..28b8ba8 100644 --- a/test/MOI_wrapper.jl +++ b/test/MOI_wrapper.jl @@ -742,6 +742,15 @@ function test_RawOptimizerAttribute() return end +function test_function_type_to_func() + model = Ipopt.Optimizer() + x = MOI.add_variable(model) + MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE) + MOI.set(model, MOI.ObjectiveFunction{MOI.VariableIndex}(), x) + @test MOI.get(model, MOI.ObjectiveFunctionType()) == MOI.VariableIndex + return +end + end # module TestMOIWrapper TestMOIWrapper.runtests()