anyone please let me know how to solve multivariate problems in python. The objective function is given in picture 1 and few constraints in picture 2
Objective function
Constraints
You are asking how to solve a linear integer programming problem in python. You could use Pyomo, PuLP or python-MIP to model your optimization problem and solve it with a suitable solver of your choice. Gurobi and Cplex are common commercial solvers (both offering a free academic-licence) while GLPK, SCIP or CBC are common used non-commercial ones.
Related
As the title says, I'm trying to find out what linear solver is used within GEKKO, for solving problems with remote=True and remote=False. I'm also curious if it's possible to change this, as you can in Pyomo. I was unable to find any reference to this within the either the Gekko documentation (https://gekko.readthedocs.io/en/latest/) or the APMonitor documentation (https://apmonitor.com/wiki/).
Is anyone familiar with the internals of Gekko / how I could find this out?
Thank you!
All of the solvers in Gekko are Nonlinear Programming (NLP) or Mixed Integer Nonlinear Programming (MINLP). The Nonlinear Programming solvers use linear solvers to iteratively solve the line-search problem. The public server (remote=True) uses MA57 while the version distributed locally (remote=False) uses a linear solver called MUMPS that can be distributed. However, there are no linear programming solvers to directly solve LPs. The MINLP solver can solve LP, QP, QPQC, MILP, NLP, and MINLP problems. Here is example code to specify MA57 solver in IPOPT.
from gekko import GEKKO
m = GEKKO(remote=True)
m.options.SOLVER=3
m.solver_options = ['linear_solver ma57']
From the documentation:
SOLVER selects the solver to use in an attempt to find a solution. There are free solvers: 1: APOPT, 2: BPOPT, 3: IPOPT distributed with the public version of the software. There are additional solvers that are not included with the public version and require a commercial license. IPOPT is generally the best for problems with large numbers of degrees of freedom or when starting without a good initial guess. APOPT is generally the best when warm-starting from a prior solution or when the number of degrees of freedom (Number of Variables - Number of Equations) is less than 2000. APOPT is also the only solver that handles Mixed Integer problems. Use option 0 to compare all available solvers.
Here, X1 and X2 take integer values. I want to use branch-and-bound technique to solve this problem. What are the python tools available to solve this problem?
Let me start saying that I am by no means expert in optimization, so any suggestion would be greatly appreciated. I have a non-convex quadratic optimization problem for which I need a solver. I myself am used to working with the modelling language CVXPY, using some of the default solvers there (ECOS, CVXOPT,...) so something similar to it would be great. I cannot use cvxpy on this problem because it is only suitable for convex optimization problems.
After googling, I saw some people recommending Pyomo, saying it could deal with non convex problems, but my problem requires matrix algebra, and as far as I know, Pyomo does not include matrix algebra capabilities. So I would require a non convex modeling language or solver for non convex quadratic problems.
The type of problem I am actually interested in solving has the following structure:
where wis the vector variable to be optimized, Xis a known data matrix and tis a prespecified parameter value.
How can I code a bi-level optimization problem using scipy.optimize.minimize which consists of the following two levels, (1) being the upper-level problem, which is subject to (2) being the lower-level:
minimize linear programming problem, subject to a
minimize quadratic programming problem
I know how to write a single objective function for quadratic programming as a typical scipy.optimize.minimize routine (step 2 by itself), but how can I add an upper level minimization problem as well that has its own objective function? Can scipy handle a minimization problem subject to a lower minimization problem? A rough outline of the code using minimize and linprog would help
I don't think scipy solvers are very suited for this.
A standard approach for bilevel problems is to form the KKT conditions of the inner problem and add these as constraints to the outer problem. The complementarity conditions make the problem hard. You need a global NLP solver or a MIP solver to solve this thing to proven optimality. Here are some formulations for linear bilevel problems. If the inner problem is a (convex) QP problem, things become a little bit more difficult, but the same idea can be applied (form KKT conditions of the inner problem).
For more information see Bard, Practical Bilevel Optimization: Algorithms And Applications, Springer, 1998.
I use pyomo and gurobi for solving a nonlinear optimization problem.
but when I run my code, I get this error:
RuntimeError: Cannot write legal LP file. Objective 'Maximum_profit' has nonlinear terms that are not quadratic.
(I don't have any problem when I use gurobi as a solver in a linear optimization problem.)
My objective function is:
Maximum_profit=pyo.Objective(doc="Profit Maximization", rule=lambda model: sum(pyo.log10(1+sum(pyo.log10(1.0 + model.t[i,k]) for i in model.N)) for k in model.J) - sum(sum(model.t[i,k] * model.p[i,k] for k in model.J) for i in model.N),sense=-1)
how can I fix it?
Disclaimer: I work for Gurobi.
The problem here is pyomo, since Gurobi is able to solve non-convex mixed-integer quadratically constrained quadratic programming problems. In particular, the issue arises in the file cpxlp.py, which originally handled only the writing the CPLEX LP file, but now also handles the LP files for Gurobi. There, in line 500-650 you can see all the restrictions that apply, and that is where the exception is thrown.
I will post a github issue (if one does not already exist) so as to hopefully clarify this.
Gurobi cannot solve nonlinear optimization models (except for some instances of quadratic models). With log terms in your objective you need a solver that can handle them, such as BARON or IPOPT.