Skip to content

Commit

Permalink
New approach
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Aug 8, 2024
1 parent 0e56e00 commit c9e73b9
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/file_formats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ function Base.write(
return
end

_value_type(model::MOI.Utilities.AbstractModelLike{T}) where {T} = T

# This fallback may not get the correct value type. However, since
# all models defined in `MOI.FileFormats` are created with
# `MOI.Utilities.@model` except `NL` which only supports `Float64`,
# this does the job for now.
_value_type(model::MOI.ModelLike) = Float64

"""
read_from_file(
filename::String;
Expand All @@ -105,12 +113,11 @@ Other `kwargs` are passed to the `Model` constructor of the chosen format.
function read_from_file(
filename::String;
format::MOI.FileFormats.FileFormat = MOI.FileFormats.FORMAT_AUTOMATIC,
coefficient_type::Type = Float64,
kwargs...,
)
src = MOI.FileFormats.Model(; format, filename, coefficient_type, kwargs...)
src = MOI.FileFormats.Model(; format, filename, kwargs...)
MOI.read_from_file(src, filename)
model = GenericModel{coefficient_type}()
model = GenericModel{_value_type(model)}()
MOI.copy_to(model, src)
return model
end
Expand Down

0 comments on commit c9e73b9

Please sign in to comment.