Accessing Pyomo user time with Neos - pyomo

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

Related

infeasible row in Cplex C++

I have a small question; I am solving MIP Model , coded on C++ and solving by Cplex solver. I remember that when I test the model with relatively smaller instances , it was giving me "infeasibility row …."; Now ,I test the same model on a large size instance and I get the infeasibility and it does not tell me which row causes infeasibility. How can I find the which parameter or constraint causes infeasibility ? While the larger instance is tested, the presolve is performed, may it cause the infeasibility? I googled about conflict refiner but could not find a small and clear example explaining how to invoke it ? I will be very happy, if you have any suggestions or ideas
Thank you
Another way to find where the infeasibility comes is to export your model as an LP file or similar, then try to solve it with the standalone cplex. It helps if you name your variables and constraints sensibly. Then you have all the interactive tools in cplex to help you find where the issues are.
in C++ you should have a look at FeasOpt
In the documentation see
CPLEX > User's Manual for CPLEX > Infeasibility and unboundedness
If you model in OPL you could call the relaxation from concert C++ APIs

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.

Get marginal values (dual) for constraints in Pyomo MIP

I want to access dual variables for a MIP problem developed in python with Pyomo. To my understanding the dual is not created for MIP problems, but in my opinion there should be a work around for this.
This should be possible to use as a minimal working example, I'm using Gurobi myself.
I can see two possible solutions to this; 1. Fixing the binary/integer variables and resolve as LP and recreate the dual. 2. Getting dual only for the necessary constraints.
I've not been able to figure out a way to try the second method, for the first I've done something like:
m.solve() #solves the MIP problem
m.instance.x.fix() #fixing the binary variables (only have one in actual model)
m.instance.y.fix()
m.instance.z.fix()
m.instance.preprocess()
m.instance.dual = Suffix(direction=Suffix.IMPORT)
m.solve() #hopefully solving LP problem with dual
Let me know if anything is unclear or more information is needed, any help is appreciated.

Using Microsoft Solver Foundation to solve a linear programming task requiring thousands of data points

Using Microsoft Solver Foundation,I am trying to solve a linear program of the form Ax <= b where A is a matrix containing thousands of data points.
I know that I can new up a Model object and then use the AddConstraint method to add constraints in equation form. However putting those equations together where each contains thousands of variables is just not possible. I looked at the Model Class and can not find a way to just give it the matrix and other info.
How can I do this?
Thanks!
You can make A a parameter and bind data to it. Warning: Microsoft Solver Foundation has been discontinued a while ago, so you are advised to consider an alternative modeling system.

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.