Skip to content
Closed
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
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Calculus = "49dc2e85-a5d0-5ad3-a950-438e2897f1b9"
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MathOptFormat = "f4570300-c277-12e8-125c-4912f86ce65d"
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Expand All @@ -18,6 +19,7 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Calculus = "0.5"
DataStructures = "0.17"
ForwardDiff = "~0.5.0, ~0.6, ~0.7, ~0.8, ~0.9, ~0.10"
MathOptFormat = "≥ 0.2"
MathOptInterface = "~0.9.1"
NaNMath = "0.3"
OffsetArrays = "≥ 0.2.13"
Expand Down
6 changes: 4 additions & 2 deletions src/JuMP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ using SparseArrays
import MathOptInterface
const MOI = MathOptInterface
const MOIU = MOI.Utilities
using MathOptFormat

import Calculus
import DataStructures.OrderedDict
Expand All @@ -38,8 +39,8 @@ Base.@deprecate(setlowerbound, JuMP.set_lower_bound)
Base.@deprecate(setupperbound, JuMP.set_upper_bound)
Base.@deprecate(linearterms, JuMP.linear_terms)

writeLP(args...; kargs...) = error("writeLP has been removed from JuMP. Use `MathOptFormat.jl` instead.")
writeMPS(args...; kargs...) = error("writeMPS has been removed from JuMP. Use `MathOptFormat.jl` instead.")
writeLP(args...; kargs...) = error("writeLP has been merged into write_to_file and its arguments have changed.")
writeMPS(args...; kargs...) = error("writeMPS has been merged into write_to_file and its arguments have changed.")

include("utils.jl")

Expand Down Expand Up @@ -787,6 +788,7 @@ include("nlp.jl")
include("print.jl")
include("lp_sensitivity.jl")
include("callbacks.jl")
include("file_formats.jl")

# JuMP exports everything except internal symbols, which are defined as those
# whose name starts with an underscore. If you don't want all of these symbols
Expand Down
28 changes: 28 additions & 0 deletions src/file_formats.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function write_to_file(model::Model, io::IO, format::MathOptFormat.FileFormat; kwargs...)
@assert format != AUTOMATIC_FILE_FORMAT
dest = MathOptFormat._file_formats[format][2]()
MOI.copy_to(dest, backend(model))
MOI.write_to_file(dest, io)
return
end

"""
write_to_file(model::Model, filename::String; format::FileFormat=AUTOMATIC_FILE_FORMAT, compression::MathOptFormat.AbstractCompressionScheme=MathOptFormat.AutomaticCompression(), kwargs...)

Write `model` to the file called `filename` using the format `format`.

Valid formats are given by the enum [`FileFormat`](@ref). Valid compression algorithms
are given by a concrete subtype of [`AbstractCompressionScheme`](@ref).

For keyword options, see [MathOptFormat.jl](https://github.com/odow/MathOptFormat.jl).
"""
function write_to_file(model::Model, filename::String;
format::MathOptFormat.FileFormat=MathOptFormat.AUTOMATIC_FILE_FORMAT,
compression::MathOptFormat.AbstractCompressionScheme=MathOptFormat.AutomaticCompression(),
kwargs...)
if format == AUTOMATIC_FILE_FORMAT
format = MathOptFormat._filename_to_format(filename)
end
MOI.write_to_file(model, filename, compression=compression)
return
end