Skip to content

Commit

Permalink
Update tests for GenericModel{T} and GenericVariableRef{T} (#3378)
Browse files Browse the repository at this point in the history
This is another step in the process of adding generic number support to
JuMP. These commits are separate to make them easier to review and to
minimize the risk of introducing breaking changes.
  • Loading branch information
blegat authored and odow committed Jun 26, 2023
1 parent 00131a8 commit 43178a1
Show file tree
Hide file tree
Showing 12 changed files with 232 additions and 173 deletions.
2 changes: 1 addition & 1 deletion docs/src/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Update versions of the documentation (#3185)
- Tidy the import of packages and remove unnecessary prefixes (#3186) (#3187)
- Refactor `src/JuMP.jl` by moving methods into more relevant files (#3188)
- Fix docstring of `Model` not appearing in the documentation (#3198)
- Fix docstring of [`Model`](@ref) not appearing in the documentation (#3198)

## Version 1.6.0 (January 1, 2023)

Expand Down
8 changes: 4 additions & 4 deletions src/nlp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,12 @@ function set_nonlinear_objective(model::Model, sense::MOI.OptimizationSense, x)
end

"""
_nlp_objective_function(model::Model)
_nlp_objective_function(model::GenericModel)
Returns the nonlinear objective function or `nothing` if no nonlinear objective
function is set.
"""
function _nlp_objective_function(model::Model)
function _nlp_objective_function(model::GenericModel)
if model.nlp_model === nothing
return nothing
end
Expand Down Expand Up @@ -507,12 +507,12 @@ function num_nonlinear_constraints(model::GenericModel)
end

"""
all_nonlinear_constraints(model::Model)
all_nonlinear_constraints(model::GenericModel)
Return a vector of all nonlinear constraint references in the model in the
order they were added to the model.
"""
function all_nonlinear_constraints(model::Model)
function all_nonlinear_constraints(model::GenericModel)
nlp_model = nonlinear_model(model)
if nlp_model === nothing
return NonlinearConstraintRef[]
Expand Down
4 changes: 3 additions & 1 deletion src/print.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ end
# Helper function that rounds carefully for the purposes of printing Reals
# e.g. 5.3 => 5.3
# 1.0 => 1
_string_round(x::Float64) = isinteger(x) ? string(round(Int, x)) : string(x)
function _string_round(x::Union{Float32,Float64})
return isinteger(x) ? string(round(Int, x)) : string(x)
end

_string_round(::typeof(abs), x::Real) = _string_round(abs(x))

Expand Down
2 changes: 1 addition & 1 deletion test/Containers/test_tables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function JuMP.build_variable(::Function, info::VariableInfo, _::_Mock)
return _MockVariable(ScalarVariable(info))
end

function JuMP.add_variable(model::Model, x::_MockVariable, name::String)
function JuMP.add_variable(model::GenericModel, x::_MockVariable, name::String)
variable = add_variable(model, x.var, name)
return _MockVariableRef(variable)
end
Expand Down
Loading

0 comments on commit 43178a1

Please sign in to comment.