问题
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.
回答1:
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})
来源:https://stackoverflow.com/questions/51772382/passing-cplex-parameters-to-cvxpy