Skip to content

Commit 40c4008

Browse files
authored
improve general var defaults (#365)
1 parent b8b4627 commit 40c4008

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/general_variables.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -820,10 +820,14 @@ for op = (:has_lower_bound, :has_upper_bound, :is_fixed, :is_binary, :is_integer
820820
:unset_integer)
821821
@eval begin
822822
# define the fallback method
823-
function JuMP.$op(vref::DispatchVariableRef)
824-
str = string("`JuMP.$($op)` not defined for variable reference type ",
825-
"`$(typeof(vref))`.")
826-
throw(ArgumentError(str))
823+
if JuMP.$op in (JuMP.is_binary, JuMP.is_fixed, JuMP.is_integer)
824+
JuMP.$op(vref::DispatchVariableRef) = false
825+
else
826+
function JuMP.$op(vref::DispatchVariableRef)
827+
str = string("`JuMP.$($op)` not defined for variable reference type ",
828+
"`$(typeof(vref))`.")
829+
throw(ArgumentError(str))
830+
end
827831
end
828832

829833
# define the dispatch version

test/general_variables.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -484,14 +484,18 @@ end
484484
gvref = GeneralVariableRef(m, 1, TestIndex)
485485
pref = GeneralVariableRef(m, -1, IndependentParameterIndex)
486486
# test 1 argument methods
487-
for f in (:has_lower_bound, :has_upper_bound, :is_fixed, :is_binary,
488-
:is_integer, :lower_bound, :upper_bound, :fix_value, :start_value,
489-
:set_binary, :set_integer, :LowerBoundRef, :UpperBoundRef, :FixRef,
490-
:BinaryRef, :IntegerRef, :delete_lower_bound, :delete_upper_bound,
487+
for f in (:has_lower_bound, :has_upper_bound, :lower_bound, :upper_bound,
488+
:fix_value, :start_value, :set_binary, :set_integer,
489+
:LowerBoundRef, :UpperBoundRef, :FixRef, :BinaryRef, :IntegerRef,
490+
:delete_lower_bound, :delete_upper_bound,
491491
:unfix, :unset_binary, :unset_integer)
492492
@test_throws ArgumentError eval(f)(dvref)
493493
@test_throws ArgumentError eval(f)(gvref)
494494
end
495+
for f in (:is_fixed, :is_binary, :is_integer)
496+
@test !eval(f)(dvref)
497+
@test !eval(f)(gvref)
498+
end
495499
# test setting methods
496500
for f in (:set_lower_bound, :set_upper_bound, :set_start_value)
497501
@test_throws ArgumentError eval(f)(dvref, 42)

0 commit comments

Comments
 (0)