I want to save a JuMP model to a .MPS file without appending .MPS to the filename in the second argument to write_to_file, .i.e. not using write_to_file(model,"test.MPS"). The approach below does not work.
julia> using JuMP
julia> model = Model()
A JuMP Model
├ solver: none
├ objective_sense: FEASIBILITY_SENSE
├ num_variables: 0
├ num_constraints: 0
└ Names registered in the model: none
julia> write_to_file(model,"test", FORMAT_MPS)
ERROR: UndefVarError: `FORMAT_MPS` not defined in `Main`
Suggestion: check for spelling errors or missing imports.
Stacktrace:
[1] top-level scope
@ REPL[3]:1
The approach below generates an MPS file named test. Is it possible to have write_to_file generate an MPS file named test.MPS without explicitly passing test.MPS as the second argument to write_to_file?
write_to_file(model, "test", format = MOI.FileFormats.FORMAT_MPS)
Is it possible to have write_to_file generate an MPS file named test.MPS without explicitly passing test.MPS as the second argument to write_to_file
No. We either infer the file format from the extension, or you must pass the format kwarg, in which case we do not care about the extension of filename.
However, this is trivially fixed by defining your own function:
function write_mps_to_file(model, filename)
return JuMP.write_to_file(model, filename * ".mps")
end