From 39690bb8b153a3f32b029c6c2cdebee421223e31 Mon Sep 17 00:00:00 2001 From: pulsipher Date: Thu, 24 Feb 2022 19:34:59 -0500 Subject: [PATCH 1/3] Updated index dispatch --- src/general_variables.jl | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/general_variables.jl b/src/general_variables.jl index 3a13d2056..81c8ebb0f 100644 --- a/src/general_variables.jl +++ b/src/general_variables.jl @@ -53,15 +53,23 @@ julia> index(vref) FiniteVariableIndex(1) ``` """ -function JuMP.index(vref::GeneralVariableRef)::AbstractInfOptIndex - index_type = _index_type(vref) - if index_type == DependentParameterIndex - return index_type(DependentParametersIndex(_raw_index(vref)), - _param_index(vref)) - else - return index_type(_raw_index(vref)) +function JuMP.index(vref::GeneralVariableRef) + return JuMP.index(vref.index_type, vref) +end + +# Implement dispatch functions +for idx in (:IndependentParameterIndex, :FiniteParameterIndex, + :InfiniteVariableIndex, :SemiInfiniteVariableIndex, + :PointVariableIndex, :MeasureIndex, :DerivativeIndex, + :FiniteVariableIndex) + @eval begin + JuMP.index(::Type{$idx}, vref::GeneralVariableRef) = $idx(vref.raw_index) end end +function JuMP.index(::Type{DependentParameterIndex}, vref::GeneralVariableRef) + return DependentParameterIndex(DependentParametersIndex(vref.raw_index), + vref.param_index) +end """ JuMP.index(vref::DispatchVariableRef)::AbstractInfOptIndex From 68c2201a9afc1f7c064421b034b47689ff05a676 Mon Sep 17 00:00:00 2001 From: pulsipher Date: Fri, 4 Mar 2022 11:18:32 -0500 Subject: [PATCH 2/3] Update tests --- test/utilities.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/utilities.jl b/test/utilities.jl index fdb2e8be2..c4cc7169c 100644 --- a/test/utilities.jl +++ b/test/utilities.jl @@ -44,6 +44,7 @@ struct TestVariableRef <: DispatchVariableRef index::TestIndex end InfiniteOpt.dispatch_variable_ref(m::InfiniteModel, i::TestIndex) = TestVariableRef(m, i) +JuMP.index(::Type{TestIndex}, v::GeneralVariableRef) = TestIndex(v.raw_index) struct TestIndex2 <: ObjectIndex value::Int @@ -53,6 +54,7 @@ struct TestVariableRef2 <: DispatchVariableRef index::TestIndex2 end InfiniteOpt.dispatch_variable_ref(m::InfiniteModel, i::TestIndex2) = TestVariableRef2(m, i) +JuMP.index(::Type{TestIndex2}, v::GeneralVariableRef) = TestIndex2(v.raw_index) JuMP.name(::TestVariableRef2) = "test" InfiniteOpt.support_label(::TestGenMethod) = InternalLabel From bda963b395af0824b3243423a6c2a7fe340a78f3 Mon Sep 17 00:00:00 2001 From: pulsipher Date: Fri, 4 Mar 2022 13:23:02 -0500 Subject: [PATCH 3/3] fix parameter function bug --- src/general_variables.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/general_variables.jl b/src/general_variables.jl index 81c8ebb0f..37380033e 100644 --- a/src/general_variables.jl +++ b/src/general_variables.jl @@ -61,7 +61,7 @@ end for idx in (:IndependentParameterIndex, :FiniteParameterIndex, :InfiniteVariableIndex, :SemiInfiniteVariableIndex, :PointVariableIndex, :MeasureIndex, :DerivativeIndex, - :FiniteVariableIndex) + :FiniteVariableIndex, :ParameterFunctionIndex) @eval begin JuMP.index(::Type{$idx}, vref::GeneralVariableRef) = $idx(vref.raw_index) end