From c865eda1f432ba4498aa478bebab1978874b4450 Mon Sep 17 00:00:00 2001 From: pulsipher Date: Tue, 22 Oct 2024 11:04:04 -0400 Subject: [PATCH] improve general var defaults --- src/general_variables.jl | 12 ++++++++---- test/general_variables.jl | 12 ++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/general_variables.jl b/src/general_variables.jl index c926fea5..8918f3b8 100644 --- a/src/general_variables.jl +++ b/src/general_variables.jl @@ -820,10 +820,14 @@ for op = (:has_lower_bound, :has_upper_bound, :is_fixed, :is_binary, :is_integer :unset_integer) @eval begin # define the fallback method - function JuMP.$op(vref::DispatchVariableRef) - str = string("`JuMP.$($op)` not defined for variable reference type ", - "`$(typeof(vref))`.") - throw(ArgumentError(str)) + if JuMP.$op in (JuMP.is_binary, JuMP.is_fixed, JuMP.is_integer) + JuMP.$op(vref::DispatchVariableRef) = false + else + function JuMP.$op(vref::DispatchVariableRef) + str = string("`JuMP.$($op)` not defined for variable reference type ", + "`$(typeof(vref))`.") + throw(ArgumentError(str)) + end end # define the dispatch version diff --git a/test/general_variables.jl b/test/general_variables.jl index 2db62b23..189e7b0a 100644 --- a/test/general_variables.jl +++ b/test/general_variables.jl @@ -484,14 +484,18 @@ end gvref = GeneralVariableRef(m, 1, TestIndex) pref = GeneralVariableRef(m, -1, IndependentParameterIndex) # test 1 argument methods - for f in (:has_lower_bound, :has_upper_bound, :is_fixed, :is_binary, - :is_integer, :lower_bound, :upper_bound, :fix_value, :start_value, - :set_binary, :set_integer, :LowerBoundRef, :UpperBoundRef, :FixRef, - :BinaryRef, :IntegerRef, :delete_lower_bound, :delete_upper_bound, + for f in (:has_lower_bound, :has_upper_bound, :lower_bound, :upper_bound, + :fix_value, :start_value, :set_binary, :set_integer, + :LowerBoundRef, :UpperBoundRef, :FixRef, :BinaryRef, :IntegerRef, + :delete_lower_bound, :delete_upper_bound, :unfix, :unset_binary, :unset_integer) @test_throws ArgumentError eval(f)(dvref) @test_throws ArgumentError eval(f)(gvref) end + for f in (:is_fixed, :is_binary, :is_integer) + @test !eval(f)(dvref) + @test !eval(f)(gvref) + end # test setting methods for f in (:set_lower_bound, :set_upper_bound, :set_start_value) @test_throws ArgumentError eval(f)(dvref, 42)