Solve problems starting from corresponding .nl files

Dear all,

I want to solve a bunch of nonlinear optimization problems, whose nl. files are available. Hence I would like to charge the .nl files directly in Julia and solve the corresponding problem with a nonlinear solver like Ipopt. Do you know if there is a way to realize it?

Thanks very much. All your support is really appreciated!

Hi @Luca

You can use AmplNLReader.jl and NLPModelsIpopt.jl wrapper to Ipopt.

For instance:

using AmplNLReader, NLPModelsIpopt

hs33 = AmplModel("hs033.nl")
ipopt(hs33)
1 Like

Hi Luca,

You can use AmplNLReader.jl (https://juliasmoothoptimizers.github.io/AmplNLReader.jl/stable/).
Also, check this tutorial on how to call NLPModelsIpopt.jl: https://juliasmoothoptimizers.github.io/tutorials/solve-an-optimization-problem-with-ipopt/

Best,

Thanks for the the quick answers! I would like to use also bonmin, couenne, and shot as solvers since there are integer variables in my model. Is it possible too? I check GitHub - jump-dev/AmplNLWriter.jl: Julia interface to AMPL-enabled solvers.

With JuMP, you’re after something like this:

using JuMP, AmplNLWriter, Bonmin_jll
model = read_from_file("file.nl")
set_optimizer(model, () -> AmplNLWriter.Optimizer(Bonmin_jll.amplexe))
optimize!(model)
2 Likes

Thanks for your answer. I tried the following code:

using JuMP, AmplNLWriter, SHOT_jll

model1 = MOI.FileFormats.Model(format = MOI.FileFormats.FORMAT_NL)
model = read_from_file(model1, "instance_15_3_1_0.nl")
set_optimizer(model, () -> AmplNLWriter.Optimizer(SHOT_jll.amplexe))
optimize!(model)

but I obtain the following error:

ERROR: LoadError: UndefVarError: FORMAT_NL not defined

Your code is not what I wrote?

FORMAT_NL not defined

This suggests you have an old version of MathOptInterface installed.

Try what I wrote, and if that doesn’t work, update your packages.

1 Like

I have update all Julia packages. I tried your code and it works! Thanks you so much!

1 Like