Skip to content

Commit

Permalink
Fix methods for calling value on a ::Number (#3776)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Jun 17, 2024
1 parent 6efbfb8 commit 20093d9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/variables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2457,8 +2457,12 @@ function value(::AbstractArray{<:AbstractJuMPScalar})
)
end

value(::_MA.Zero) = 0.0
value(x::Number) = x
# Fallback. See JuMP#3775
value(::_MA.Zero; result::Int = 1) = 0.0

value(x::Number; result::Int = 1) = x

value(::Function, x::Number) = x

function _info_from_variable(v::GenericVariableRef)
has_lb = has_lower_bound(v)
Expand Down
11 changes: 11 additions & 0 deletions test/test_variable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1651,4 +1651,15 @@ function test_variable_normalized_coefficient_vector_quadratic()
return
end

function test_value_number()
model = Model()
@variable(model, x, start = 2)
@expression(model, expr[i in 0:2], (1 + x)^i)
y = Containers.DenseAxisArray([1, 3, 9], 0:2)
@test (value.(start_value, expr), y)
@test value(expr[0]; result = 1) == 1
@test value(expr[0]; result = 2) == 1
return
end

end # module TestVariable

0 comments on commit 20093d9

Please sign in to comment.