将CPLEX参数传递给CVXPY [英] Passing CPLEX Parameters to CVXPY

查看:319
本文介绍了将CPLEX参数传递给CVXPY的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用CPLEX求解器时如何通过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, ...)

我看到 CPLEX参数尚不清楚哪些适用于我的二次问题。另外, CVXPY文档对于其他求解器(而非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.

推荐答案

这将在将来发生变化(请参见请求请求),但是对于cvxpy 1.0.6,您可以执行以下操作(注意:这是未记录的行为;有关更多信息,请参见下文):

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)

advance = 0 将关闭 高级启动开关参数。因此,如果CPLEX Python API中的参数名称为 parameters.advance ,您将在参数之后传递该部分。(即 advance ),并将值作为关键字参数。传递给 solve 的所有其他关键字参数方法是这样解释的。要进行调试,您可能应该设置 verbose = True solve 的标准关键字参数之一)以打开引擎日志;参数设置将显示在日志的顶部。

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.

出于充分的原因未记录此行为。它不允许您设置诸如数据一致性检查和建模帮助。 CPLEX Python API中的参数名称为 parameters.read.datacheck ,但 read.datacheck 不能用作关键字Python中的参数(会导致语法错误)。

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).

作为一种解决方法,请考虑使用 ILOG_CPLEX_PARAMETER_FILE 环境变量,记录在此处

As a workaround, consider using the ILOG_CPLEX_PARAMETER_FILE environment variable, which is documented here.

编辑:上述解决方法是使用cvxpy 1.0.8不再需要。也就是说,无论它们在参数层次结构中的什么位置,您现在都应该能够设置所有参数。不过,您需要使用可选的 cplex_params 参数。最好将它与 verbose = True 结合使用,以便您可以在引擎日志中查看参数设置。例如:

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})

这篇关于将CPLEX参数传递给CVXPY的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆