Changing IPOPT options with pyomo doesn't work - pyomo

I am using IPOPT solver for solving KKTs conditions (a bunch of equality constraints and complementarity conditions).
For assigning the solver for the complementarity problem, I use the command line below:
solver = po.SolverFactory('mpec_nlp')
And then according to IPOPT documentation I am changing the number of maximum iteration
solver.options['max_iter']=1000
But solver doesn't listen to me and still stops at its default maximum of 3000 iterations
Do you have any suggestions on how to make it work?

Consider creating ipopt.opt file using notepad. Write max_iter 500 into the file. Place the file into your working directory (where your code is running)

Related

Accessing Pyomo user time with Neos

I teach an optimization course in which I use the Pyomo modeling language to solve problems. I also encourage students to compare solvers using Neos. However, I have not found a way to measure the computational time required to solve the problems.
To explain my point I have created this notebook in Colab (https://github.com/salvapineda/notebooks/blob/main/UserTimePyomoNeos.ipynb)
First, I solve a model using cbc without using NEOS. As you can see, the "Solver Information" includes the time required to solve the problem.
Then, I solve the same model using cbc through NEOS. However, the "Solver Information" does not include any time information.
Is there any way to access the computational time when I am solving Pyomo models in Neos?
Do you mean the breakdown of the computation time? The model in Colab on NEOS returns 0.00389 seconds.
Message: CBC 2.10.3 optimal, objective 3.49; 0 nodes, 2 iterations, 0.00389 seconds

Initializing IPOPT when using pyomo parmest

I am learning to use pyomo parmest. I am trying to recreate the following parameter estimation example. The code that I created is in the following jupyter notebook. IPOPT stops with the message of maximum iterations exceeded when using collocation but solves with finite difference discretization. Since it is suggested that collocation is typically more robust, I would like to know what I might be doing wrong in using the collocation discretization.
I had originally used number of collocation points in discretization ncp = 4. When I changed ncp = 2, IPOPT ran without issues. The updated ipython notebook is in this location.

How to obtain iterations and runtime of the Feasibility Pump from the Coin-OR Framework

I have programmed an algorithm that finds feasible points for mixed-integer convex optimization problems. Now I wish to compare it with the Feasibility Pump for mixed-integer nonlinear programms on a testbed from the MINLPlib library.
I have access to the BONMIN solver from the Coin OR project, where the Feasibility Pump is also implemented, via Pyomo. Here is a list of possible options for this solver.
My questions are
Are the following options correct to test (plain vanilla) feasibility pump?
opt = SolverFactory('bonmin')
opt.options['bonmin.algorithm'] = 'b-ifp' # Iterated Feasibility Pump as solver
opt.options['bonmin.pump_for_minlp'] = 'yes' # Is this needed?
opt.options['bonmin.solution_limit'] = '1' #For terminating after 1st feasible point
If not, any hint how to do it correctly is appreciated.
How do I access the number of iterations (i.e. pumping cycles) of the feasibility pump? I can see iteration information in the print output but it would be very helpful, if it was stored in some variable.
Pyomo calls Bonmin through the ASL (AMPL solver library) interface. Therefore, whatever options would work for AMPL should be the same ones that are appropriate here.
As for the iteration information, there are various ways of capturing the print output and parsing it to retrieve the desired information. The most straightforward way may be to pipe the output to a file and read it as part of a small post-processing script/function.

specifying tolerance for GLPK solver in PuLP Python

I am running PuLP Programming Library in Python 2.7.8, Windows 32 bit. I'm using GLPK as my solver for a mixed integer linear programming problem. The solver converges to approx. 1% of the optimal quickly, however time to compute the exact optimal solution is high. Is there a way to specify percent tolerance for GLPK solver using PuLP? I searched https://pythonhosted.org/PuLP/solvers.html but it doesn't give any answer for GLPK solver.
If you run "glpsol" on the command line with "--help" you see the "--mipgap tol", where tol is the tolerance.
So, in PuLP, have you tried this:
model.solve(GLPK(options=['--mipgap', '0.01']))
(from this discussion a while ago) (and notice how you can use this same method to pass in more arguments that you please).
Furthermore, I went into the source code ("solvers.py") and took a look at how GLPK expects its "options" arguments, and indeed it expects the arguments as above (look at line 345 or so in the file reproduced below):
proc = ["glpsol", "--cpxlp", tmpLp, "-o", tmpSol]
if not self.mip: proc.append('--nomip')
proc.extend(self.options)
So you see that "proc" (the command which is run using Python's "subprocess" later) is "extended" with what you specify via "options" (incidentally stored in the variable self.options). So, it looks like the approach above (using '--mipgap' etc. in a list) is (still) correct.
Finally, I have not tried that myself, but I hope this helps.

glpsol tool split MIP and LP solutions

I am using glpsol to solve a rather big integer optimisation problem. The Simplex algorithm runs for about 30 mins on it, and after that glpsol tries to find integer solution using MIP solver.
Question: Can I split this into two steps using only the glpsol command tool, or should I use glpk API ?
I have tried "read" and "nomip" option that according to the documentation is
-r filename, --read filename
to read the solution from the provided filename rather than to find it with the solver
in this format:
glpsol --cpxlp WhiskasModel.lp --write WhiskasSolution.mip --nomip
and after that
glpsol --cpxlp WhiskasModel.lp --read WhiskasSolution.mip
but I receive an error:
Reading MIP solution from `WhiskasModel.mip'...
WhiskasModel.mip:33702: non-integer column valueUnable to read problem solution
and it is of course true because WhiskasModel.mip is an LP solution with nonint values.
I find the glpsol toolkit rather powerful and I want to play with some MIP options but on each step to wait 30 minutes is rather boring. Can I tell it, "use this LP solution and start MIP" ?
One thing to try: write the LP basis to a plain text file, and then when re-starting, start with that LP solution as the basis.
Try
-w WhiskasBasis.txt
and when restarting to continue on as an IP, ask it to use that basis by adding the ini option.
--ini WhiskasBasis.txt
Other suggestions:
I wouldn't use the command-line option if you are going to be doing this often. The GLPK API (for your language of choice) and with an IDE, will give you so much more flexibility and control. This link mentions several.
If you post your MIP model formulation with the objective and the constraints (maybe as a different question), you might get suggestions to speed things up. Sometimes there are relaxations and sub-problems that can help tremendously.
Hope that helps.