Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Defaults of JuMP.is_binary, JuMP.is_integer, and JuMP.is_fixed #365

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/general_variables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions test/general_variables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading