Thanks, I got one step further, I think. See this code.
function mywrite_nl_file(f::IO, mj::JuMP.Model)
JuMP.build(mj)
m = internalmodel(mj)
m.status = :NotSolved
m.solve_exitcode = -1
m.solve_result_num = -1
m.solve_result = "?"
m.solve_message = ""
# There is no non-linear binary type, only non-linear discrete, so make
# sure binary vars have bounds in [0, 1]
for i in 1:m.nvar
if m.vartypes[i] == :Bin
if m.x_l[i] < 0
m.x_l[i] = 0
end
if m.x_u[i] > 1
m.x_u[i] = 1
end
end
end
AmplNLWriter.make_var_index!(m)
AmplNLWriter.make_con_index!(m)
AmplNLWriter.write_nl_file(f, m.inner)
end
Using this function, I can write the example provided in the package even without solving them. However, for my own example things don’t work. Here it is:
using JuMP, AmplNLWriter
U = randn(10,6)
ft = [1;0;1;0;1;0]
dobs = U*ft
m = Model(solver=AmplNLSolver("bonmin"))
@variable(m, f[1:6], Bin )
@objective(m, Min, dot(U*f-dobs, U*f-dobs));
io = open("/tmp/myExample.nl","w")
mywrite_nl_file(io,m)
close(io)
I’m getting the following error
ERROR: LoadError: Solver does not support quadratic objectives
in setquadobjterms!(::AmplNLWriter.AmplNLLinearQuadraticModel, ::Array{Int32,1}, ::Array{Int32,1}, ::Array{Float64,1}) at ~/.julia/v0.5/MathProgBase/src/SolverInterface/LinearQuadratic.jl:71
in addQuadratics(::JuMP.Model) at ~/.julia/v0.5/JuMP/src/solvers.jl:484
in #build#114(::Bool, ::Bool, ::JuMP.ProblemTraits, ::Function, ::JuMP.Model) at ~/.julia/v0.5/JuMP/src/solvers.jl:422
in write_nl_file(::IOStream, ::JuMP.Model) at ~/.julia/v0.5/ConvDiff/src/io.jl:3
in include_from_node1(::String) at ./loading.jl:488
in include_from_node1(::String) at ~/Software/julia-0.5/usr/lib/julia/sys.dylib:?
while loading ~/.julia/v0.5/AmplNLWriter/examples/myEx.jl, in expression starting on line 14
I tried also with other solvers, like Ipopt and without the binary constraints… no success…
Any clue?