4

I would like to run a solvers comparison on several instances of MINLPLib. I can get the .NL files for each instance. Now, I would like to reformulate several instances and I need to edit the .NL files (in particular I would like to add a term to the objective function). I would ask you if you know an easy way to read and modify directly the .NL files for instance using Pyomo via Python.

SecretAgentMan
  • 1,895
  • 2
  • 13
  • 39
Luca
  • 59
  • 2
  • 1
    That may not be so easy. I would take one of the source files (.mod, .gms) and go from there. If you really desperately need Pyomo files, GAMS/Convert can translate the .gms file to a Pyomo file. – Erwin Kalvelagen Feb 03 '22 at 08:57

1 Answers1

5

It is basically impossible to edit a .nl file by hand correctly (unless it's a trivially simple file), since information about what's happening is distributed across the file in very non-obvious, partially undocumented, and order-dependent ways.

One way you could do this in practice is to use the Octeract Reformulator API (it's free) to import the .nl file, modify what you want, and write to a new .nl file:

from octeract import *

model = Model() model.import_model_file("/home/nikos/octeract/engine/test-libraries/stability_tests/ex6_1_1.nl") print(model) obj = model.get_objective_function_string() model.minimize(obj+"+sin(x1*x2)") print(model) model.write_problem_to_NL_file("myNewProblem.nl")

Nikos Kazazakis
  • 12,121
  • 17
  • 59