Implementation of MINLP solver "apopt" in Pyomo

Viewed 1192

I have a mixed integer non linear problem in Pyomo with an objective function and several constraints consisting of non-linear terms and binary variables.

The popular solver "ipopt" finds a solution, but it treats the binary variables as continuous variables.

opt=SolverFactory("ipopt")
results=opt.solve(instance)
results.write()
instance.load(results)

Now I have already tried desperately to try two solvers that can solve mixed-integer non-linear problems.

  1. First I tried the MindPy solver ( https://pyomo.readthedocs.io/en/stable/contributed_packages/mindtpy.html). Unfortunately without success:

I always get the error message: "type NoneType doesn't define round method". This surprises me, because the ipopt-solver finds a solution without problems and the mindtpy-solver is a mixture of a linear solver and a non-linear solver and should actually get this solved.

opt=SolverFactory('mindtpy').solve(instance, mip_solver="glpk", nlp_solver="ipopt", tee=True)
results=opt.solve(instance)
results.write()
instance.load(results)

2)Then I tried the apopt solver. You have to download it separately from "https://github.com/APMonitor/apopt" and put all files into the working directory.

Then I tried to execute the following code, unfortunately without success:

opt=SolverFactory("apopt.py")
results=opt.solve(instance)
results.write()
instance.load(results)

I always get the following error message: "Error message: [WinError 193] %1 is not a valid Win32 application". This is probably related to the fact that my Python interpreter requires an apopt.exe since I have a Windows machine. Attempts such as converting the .py to an .exe file have failed. Also, specifying Solverfactory(..., "executable=C\Users\Python...\\apopt.py" separately did not work.

Does anyone have an idea how to get the solver "apopt" and/or the solver "Mindtpy" to work and can do something with the error messages? Thank you very much in advance!

Edit:

Here is an exemplary and simple concrete model. I have tried to translate it into easier code. As I've already said, the ipopt solver finds a solution:

model = pyo.ConcreteModel()

model.x = pyo.Var([1,2,3,4], domain=pyo.NonNegativeReals)

model.x = pyo.Var([5], domain=pyo.Binary)

model.OBJ = pyo.Objective(expr = 2*model.x[1] + 3*model.x[2] + 3*model.x[3] + 4*model.x[4])

model.Constraint1 = pyo.Constraint(expr = 3*model.x[1] + 4*model.x[2] >= 1)

model.Constraint2 = pyo.Constraint(expr = 3*model.x[3] + 4*model.x[4] >= 1)

model.Constraint3 =pyo.Constraint(expr = 1000*cos(model.x[3]) < 1000)

model. Constraint4=pyo.Constraint(expr = 1000*sin(model.x[4]) < 1000)

model.Constraint5=pyo.Constraint(expr = model.x[2] <= 10000*(1-model.x[5])

model.Constraint6= pyo.Constraint (expr=model.x[2] <= 10000*(model.x[5]))
2 Answers

"type NoneType doesn't define round method"

You should (almost) never use a round() function in your MINLP model. It is not needed either. Instead, use an integer variable, like in:

x-0.5 <= y <= x+0.5 
x continuous variable
y integer variable

The reason why round() is really, really bad, is because it is non-differentiable and not continuous. Almost all NLP and MINLP solvers assume smooth functions (sometimes it is useful to read the documentation).


After fixing your model (quite a few problems with it), I could not reproduce the error message about round().

D:\tmp>type pyom1.py
import pyomo.environ as pyo

model = pyo.ConcreteModel()

model.x = pyo.Var([1,2,3,4], domain=pyo.NonNegativeReals)
model.y = pyo.Var(domain=pyo.Binary)

model.OBJ = pyo.Objective(expr = 2*model.x[1] + 3*model.x[2] + 3*model.x[3] + 4*model.x[4])

model.Constraint1 = pyo.Constraint(expr = 3*model.x[1] + 4*model.x[2] >= 1)
model.Constraint2 = pyo.Constraint(expr = 3*model.x[3] + 4*model.x[4] >= 1)
model.Constraint3 = pyo.Constraint(expr = 1000*pyo.cos(model.x[3]) <= 1000)
model.Constraint4 = pyo.Constraint(expr = 1000*pyo.sin(model.x[4]) <= 1000)
model.Constraint5 = pyo.Constraint(expr = model.x[2] <= 10000*(1-model.y))
model.Constraint6 = pyo.Constraint (expr=model.x[2] <= 10000*(model.y))

pyo.SolverFactory('mindtpy').solve(model, mip_solver='cbc', nlp_solver='ipopt', tee=True)


D:\tmp>python.exe pyom1.py
INFO: ---Starting MindtPy---
INFO: Original model has 6 constraints (2 nonlinear) and 0 disjunctions, with
    5 variables, of which 1 are binary, 0 are integer, and 4 are continuous.
INFO: rNLP is the initial strategy being used.
INFO: NLP 1: Solve relaxed integrality
INFO: NLP 1: OBJ: 1.666666661289117  LB: -inf  UB: inf
INFO: ---MindtPy Master Iteration 0---
INFO: MIP 1: Solve master problem.
INFO: MIP 1: OBJ: 1.6666666499999998  LB: 1.6666666499999998  UB: inf
INFO: NLP 2: Solve subproblem for fixed binaries.
INFO: NLP 2: OBJ: 1.6666666716089886  LB: 1.6666666499999998  UB:
    1.6666666716089886
INFO: MindtPy exiting on bound convergence. LB: 1.6666666499999998 + (tol
    0.0001) >= UB: 1.6666666716089886

D:\tmp>

Try adding the path to apopt.py to the PATH variable. The apopt.py program acts like an executable with the model.nl as an argument to the solver and it produces a sol solution file that is then processed to retrieve the solution. Unlike other solvers in AIMS or Pyomo, APOPT computes remotely on a public server. Here are additional instructions on running APOPT.

APOPT Solver

APOPT (for Advanced Process OPTimizer) is a software package for solving large-scale optimization problems of any of these forms:

  • Linear programming (LP)
  • Quadratic programming (QP)
  • Quadratically constrained quadratic program (QCQP)
  • Nonlinear programming (NLP)
  • Mixed integer programming (MIP)
  • Mixed integer linear programming (MILP)
  • Mixed integer nonlinear programming (MINLP)

Applications of the APOPT include chemical reactors, friction stir welding, prevention of hydrate formation in deep-sea pipelines, computational biology, solid oxide fuel cells, and flight controls for Unmanned Aerial Vehicles (UAVs). APOPT is supported in AMPL, APMonitor, Gekko, and Pyomo.

APOPT Online Solver for Mixed Integer Nonlinear Programming Reads output from AMPL, Pyomo, or other NL File Writers. Similar to other solvers, this script reads the model (NL) file and produces a solution (sol) file. It sends the NL file to a remote server, computes a solution (remotely), and retrieves a solution (sol) file through an internet connection. It communicates with the server http://byu.apopt.com that is hosting the APOPT solver. Contact support@apmonitor.com for support, especially if there is a feature request or a concern about a problem solution.

Instructions for usage:

  • Place apopt.py in an appropriate folder in the system path (e.g. Linux, /usr/bin/)
  • Set appropriate permissions to make the script executable (e.g. chmod 775 apopt.py)
  • In AMPL, Pyomo, or other NL file write, set solver option to apopt.py
  • Test installation by running apopt.py -test
  • Visit apopt.com for additional information and solver option help

Information on the APOPT solver with references can be found at the Wikipedia article for APOPT. APOPT has integration with Gekko and can run locally with m=GEKKO(remote=False).

Related