3

I am trying to solve an MINLP problem with the ANTIGONE solver (licensed in GAMS), and I am having difficulties to change the advanced settings of the solver.

First, I call the solver from Pyomo as follows.

solver = pe.SolverFactory('gams')
solver.options['mtype']= "minlp"
solution = solver.solve(model, solver = 'antigone')

This part works as it should, however ANTIGONE cannot close the optimality gap, so I'd like to change some of the more advanced options that are provided here https://www.gams.com/latest/docs/S_ANTIGONE.html.

So what I first tried was to change the solver call to the following line.

solution = solver.solve(model, solver='antigone', add_options=['option number_of_partitions 2;'])

However, it looks like add_options is only for the built-in GAMS options, and not for the solver-specific ones.

As a side note, when using these advanced solver options in GAMS, the standard procedure is to create an options file (i.e. antigone.opt), where we specify the desired options.

number_of_partitions 2

antigone.opt is saved under the same directory, and the .gms file calls this file with the GAMS_MODEL.optfile; line.

Going back to my issue, when modifying this option from Pyomo, I tried

solution = solver.solve(model, solver='antigone', add_options=['GAMS_MODEL.optfile;'])

but the problem is that Pyomo creates a temporary file to solve the problem, and hence I cannot add the file antigone.opt before it starts solving.

Therefore, I can see two options to go: (i) I can find a way to create the antigone.opt file in the temporary file through Pyomo before the solver starts solving (less desirable, but it should work), or (ii) I should directly change the option from Pyomo (preferred).

Any help would be much appreciated and thanks in advance for your time!

bburnak
  • 31
  • 2

2 Answers2

2

Maybe this answer arrives a little late for you however I think this might help other people.

I had the same issue you had. After a long crusade and by putting many Stack Overflow posts together, I finally made it work using Pyomo only.

The line,

solution = solver.solve(model, solver='antigone', add_options = ['GAMS_MODEL.optfile;'])

should be replaced by,

solution = solver.solve(model, solver='antigone', add_options = ['GAMS_MODEL.optfile = 1;','$onecho > antigone.opt', 'number_of_partitions 2', '$offecho'])

So the first option specifies the use of the antigone.opt file and the remaining lines tell GAMS to create and write in the antigone.opt file.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
0

I had a similar problem when using pyomo->gams->knitro. The code below worked for me. My code was in /Users/myDir/, and I created the directory "tmp" there. Then I instruct pyomo to use that and the file knitro.opt is placed there.

    opt = SolverFactory('gams')
    opts = {}
    opts["solver"] = "knitro"
    with open("tmp/knitro.opt", "w") as f:
        f.write("algorithm 2\n")
    addOp = ['GAMS_MODEL.optfile=1;']
    opt.solve(instance, io_options=opts, load_solutions=True, tee=True, 
    add_options=addOp, tmpdir='/Users/myDir/tmp')