How to pass MIP gap parameter to Gurobi with PULP - python

How to pass MIP gap parameter to Gurobi with PULP?
I tried:
prob.solve(GUROBI_CMD(epgap = 0.9))
No luck
I used this wiki for all my failed attempts

Looking at the code, i would assume, that you have to give the arguments as defined in gurobi's docs (these are then passed when calling gurobi's cli), compatible with pulp's function-signature.
prob.solve(GUROBI_CMD(options=['MIPGap=0.9']))
But i probably recommend using the python-interface if you got gurobipy working (read gurobi's docs). This would look like:
prob.solve(GUROBI(epgap = 0.9))

Related

Solve optimization problem with python library which has a logarithmic objective function

How can I solve optimization problem:
subject to:
(I am looking for a library that its objective function can accept logarithms.)
I found glpk and gurobipy but they don't seem to be able to do it.
Based on your comments under the question, I am just going to refer you to one of the more standard libraries to solve this problem. Note the your objective concave and its a maximization problem. So, it is straightforward to rewrite it as a convex minimization problem and your constraints are linear. For such problems, you can use CVXOPT(https://cvxopt.org/index.html). In particular, look at some of the examples for how to use the library: https://cvxopt.org/examples/index.html#book-examples

Mixed Integer Linear Programming Using Python with Multiple Objectives Support

I am very new to this field. I am working on MILP type of problem, and I am using Python with Pyomo.
Pyomo is very easy to use when you are having Single Objective Model. but in my case.
it is solving a very complicated type of Model that requires multiple objectives. I have seen some ppl suggesting to add a weight an implement it as (10*objective1 + objective2) as now objective1 will have bigger weight that objective2, but that wont solve my problem, as I am trying to do is to Maximize objective 1 and Minimize Objective 2
I am not strict to use only Pyomo, but i would like to use something easy as Pyomo with the support of Multiple Objectives.
What should i Use.
Thanks
You can check out PolySCIP for multi-criteria optimization. Another easy way to use multiple objectives is the Python interface of Gurobi.
I cannot give you a detailed answer because is quite broad and generic.

PWL constraint in cplex Python API v12.8

When I tried to use piecewise linear (PWL) function in Python, after I set the problem type to cplex.Cplex.problem_type.LP, the PWL cpnstraint (or function) disappear when I write out the model to the file. However if I specified the problem type is cplex.Cplex.problem_type.MILP, it said that no solution, although there exist solution in LP. So I want to ask if someone face this problem before and how to solve it
The behavior you describe is expected. PWL constraints are considered MILP modeling objects. When you change the problem type to an LP, the MILP modeling objects are removed. Given that the LP is feasible, it sounds like your PWL constraint has introduced a conflict or there is something wrong with the definition of the PWL.
What exactly is the solution status code that you are getting when solving the MILP? That is, what is the value of Cplex.solution.get_status()? What does the engine log contain? These will likely give you some useful information.
In case you haven't found it, the CPLEX User's Manual contains a section on piecewise linear constraints here. See also the transport.py example that is included when you install CPLEX.

Passing CPLEX Parameters to CVXPY

How do i pass tolerances and other parameters through CVXPY when using the CPLEX solver?
from cvxpy import Problem, Minimize
from cvxpy.settings import CPLEX
costs = ...
constraints = ...
prob = Problem(Minimize(costs), constraints)
prob.solve(solver=CPLEX, ...)
I see a page of CPLEX Parameters though it is unclear which ones apply to my quadratic problem. Also, the CVXPY documentation has pass through options for other solvers but not CPLEX.
This will change in the future (see this pull request), but with cvxpy 1.0.6, you can do the following (NOTE: this is undocumented behavior; see below for more):
prob.solve(solver=CPLEX, advance=0)
The advance=0 will turn "off" the advanced start switch parameter. So, if the parameter name is parameters.advance in the CPLEX Python API, you would pass in the part after parameters. (i.e., advance) and the value as a keyword argument. Any extra keyword arguments that are passed to the solve method are interpreted this way. For debugging, you should probably set verbose=True (one of the standard keyword arguments to solve) to turn on the engine log; the parameter settings will be displayed at the top of the log.
This behavior was not documented for good reason. It doesn't allow you to set parameters like data consistency checking and modeling assistance. That parameter name in the CPLEX Python API is parameters.read.datacheck but read.datacheck cannot be used as a keyword argument in Python (it would result in a syntax error).
As a workaround, consider using the ILOG_CPLEX_PARAMETER_FILE environment variable, which is documented here.
EDIT: the workaround above is no longer necessary with cvxpy 1.0.8. That is, you should be able to set all of the parameters now regardless of where they are in the parameter hierarchy. You need to use the optional cplex_params argument, though. It's nice to combine this with verbose=True so that you can see the parameter settings in the engine log. For example:
prob.solve(solver=cvxpy.CPLEX,
verbose=True,
cplex_params={"mip.tolerances.absmipgap": 1e-07,
"benders.strategy": 3})

Difference between scipy.optimize.fmin and scipy.optimize.minimize

I'm learning python to make models these days. I read the documentation of scipy.optimize.fmin. It also recommends scipy.optimize.minimize. It seems that scipy.optimize.minimize is a more advanced method. Real wonder what's the difference between these two.
scipy.optimize.minimize is a high-level interface that lets you choose from a broad range of solvers, one of which is Nelder–Mead. scipy.optimize.fmin is a special solver using Nelder–Mead. For a specific subdocumentation of minimize with Nelder–Mead, see here.

Categories

Resources