Skip to content

Commit 9bccb51

Browse files
authored
[FileFormats.MOF] add support for other number types (#2770)
1 parent 3eed44d commit 9bccb51

File tree

3 files changed

+195
-131
lines changed

3 files changed

+195
-131
lines changed

src/FileFormats/MOF/MOF.jl

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ MOI.Utilities.@model(
106106
# Reified is handled by UniversalFallback.
107107
# Scaled is handled by UniversalFallback.
108108

109-
const Model = MOI.Utilities.UniversalFallback{InnerModel{Float64}}
109+
const Model{T} = MOI.Utilities.UniversalFallback{InnerModel{T}}
110110

111111
struct Options
112112
print_compact::Bool
@@ -124,29 +124,43 @@ function get_options(m::Model)
124124
end
125125

126126
"""
127-
Model(; kwargs...)
127+
Model(;
128+
print_compact::Bool = false,
129+
warn::Bool = false,
130+
differentiation_backend::MOI.Nonlinear.AbstractAutomaticDifferentiation =
131+
MOI.Nonlinear.SparseReverseMode(),
132+
use_nlp_block::Union{Bool,Nothing} = nothing,
133+
coefficient_type::Type{T} = Float64,
134+
) where {T}
128135
129136
Create an empty instance of FileFormats.MOF.Model.
130137
131138
Keyword arguments are:
132139
133140
- `print_compact::Bool=false`: print the JSON file in a compact format without
134141
spaces or newlines.
142+
135143
- `warn::Bool=false`: print a warning when variables or constraints are renamed
144+
136145
- `differentiation_backend::MOI.Nonlinear.AbstractAutomaticDifferentiation = MOI.Nonlinear.SparseReverseMode()`:
137146
automatic differentiation backend to use when reading models with nonlinear
138147
constraints and objectives.
139-
- `use_nlp_block::Bool=true`: if `true` parse `"ScalarNonlinearFunction"`
148+
149+
`use_nlp_block::Bool=true`: if `true` parse `"ScalarNonlinearFunction"`
140150
into an `MOI.NLPBlock`. If `false`, `"ScalarNonlinearFunction"` are parsed as
141151
`MOI.ScalarNonlinearFunction` functions.
152+
153+
- `coefficient_type::Type{T} = Float64`: the supported type to use when reading
154+
and writing files.
142155
"""
143156
function Model(;
144157
print_compact::Bool = false,
145158
warn::Bool = false,
146159
differentiation_backend::MOI.Nonlinear.AbstractAutomaticDifferentiation = MOI.Nonlinear.SparseReverseMode(),
147160
use_nlp_block::Union{Bool,Nothing} = nothing,
148-
)
149-
model = MOI.Utilities.UniversalFallback(InnerModel{Float64}())
161+
coefficient_type::Type{T} = Float64,
162+
) where {T}
163+
model = MOI.Utilities.UniversalFallback(InnerModel{T}())
150164
model.model.ext[:MOF_OPTIONS] =
151165
Options(print_compact, warn, differentiation_backend, use_nlp_block)
152166
return model

0 commit comments

Comments
 (0)