简体   繁体   English

有没有办法将 cplex 表达式 (docplex.mp.LinearExpr(...)) 提高到 python 中的 -1 或 3 次方?

[英]Is there a way to raise a cplex expression (docplex.mp.LinearExpr(...)) to the power -1 or 3 in python?

I have constructed a linear programming problem in Python and use the CPLEX solver.我在 Python 中构造了一个线性规划问题,并使用了 CPLEX 求解器。 The variables are expressed as cplex expressions like docplex.mp.LinearExpr(...).变量表示为 cplex 表达式,如 docplex.mp.LinearExpr(...)。 The goal is to construct an objective where we optimize over a variable with an expression like that to the power -1 or 3:我们的目标是构建一个目标,在该目标上我们使用类似的表达式对变量进行优化 -1 或 3:

Opt 1/variable选项1/变量

Unfortunately, I receive the following error message;不幸的是,我收到以下错误消息; docplex.mp.utils.DOcplexException: Cannot raise "docplex.mp.LinearExpr(...)" to the power -1. docplex.mp.utils.DOcplexException:无法将“docplex.mp.LinearExpr(...)”的幂次方提升为 -1。 A variable's exponent must be 0, 1 or 2.变量的指数必须是 0、1 或 2。

Does anyone know if there is a way to fix this problem?有谁知道是否有办法解决这个问题? So is there a way to divide a certain number by a value equivalent to docplex.mp.LinearExpr(...)?那么有没有办法将某个数字除以相当于 docplex.mp.LinearExpr(...) 的值?

Erwin is correct as always.埃尔文一如既往的正确。 However in some limited cases you maybe able to rearrange your expressions to avoid dividing by a variable, eg change a <= 1 / var to a * var <= 1 .但是在某些有限的情况下,您也许可以重新排列表达式以避免除以变量,例如将a <= 1 / var更改为a * var <= 1 Without seeing more of your model we cannot know if this kind of simple rearrangement could work for you.如果没有看到更多的 model,我们无法知道这种简单的重新排列是否适合您。

No, Cplex can only do linear and quadratic models.不,Cplex 只能做线性和二次模型。 It is not a general-purpose nonlinear solver.它不是通用的非线性求解器。

Note that: I have constructed a linear programming problem is not really true.注意:我构造的线性规划问题并不是真的。 This is now becoming a non-linear model.这现在变成了非线性 model。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM