4

The function print(model) outputs the model in the console. How can I print the model in a file (e.g. lp file) ?

Best

Michael.

Michael
  • 71
  • 4
  • I only tried print(model, "model.lp"), which does not seem to work – Michael Feb 22 '16 at 12:36
  • 2
    I don't have `JuMP` instaled to test, but `print` can take a first positional argument of the type `IO`, the default is `STDOUT`, so I think this should work: `open("model.lp", "w") do f; print(f, model); end`. – HarmonicaMuse Feb 22 '16 at 14:27
  • 1
    you can also execute the script in the terminal (with the print statement in the script) and capture the output: `julia script.jl > output.txt` – amrods Feb 22 '16 at 16:45

2 Answers2

3

Thank's ! This works:

f = open("model.lp", "w")
print(f, model)
close(f)

# Using `do` one doesn't have to remember to call `close(f)`
open("model.lp", "w") do f
    print(f, model)
end
HarmonicaMuse
  • 7,633
  • 37
  • 52
Michael
  • 71
  • 4
0

Julia's JuMP has inbuilt method writeLP, which takes Model and filename to the model is to be written.

writeLP(m::Model, filename::AbstractString; genericnames=true)

More details can be found here JuMP Documentation