如何在 Gurobi 的 objective 方程中定义多项式的更高次幂?
How to define higher power of polynomials in equation of objective in Gurobi?
我想在我的 objective 方程中添加不同幂的多项式。我尝试在等式中使用 Python 的 math.pow
但它没有用。以下是我的代码:
modal = Model("modal")
temp = modal.addVar(-26,48, vtype=GRB.CONTINUOUS, name = "temp")
EC = gurobi.QuadExpr(math.exp(7e-7)*math.pow(temp,6) - math.exp(9e-5)*math.pow(temp,5) + 0.0022*math.pow(temp,4) + 0.0887*math.pow(temp,3)- 0.5655*pow(temp,2) - 69.606*temp + 4979.7)
mAggresive.setObjective(EC + EUC + ELAggresive, GRB.MINIMIZE)
Gurobi 只能处理(部分)二次型。当然 x^6 是一样的:
x2 = x^2
x4 = x2^2
x6 = x4*x2
这看起来不错,但通常事情必须是凸的。这意味着我们不能有二次等式约束。在某些情况下,您可以将事物转化为不等式,但通常 Gurobi 无法处理您想要的。
当然,另一种方法是使用分段线性近似。 Gurobi 拥有让这一切变得简单的设施。
我想在我的 objective 方程中添加不同幂的多项式。我尝试在等式中使用 Python 的 math.pow
但它没有用。以下是我的代码:
modal = Model("modal")
temp = modal.addVar(-26,48, vtype=GRB.CONTINUOUS, name = "temp")
EC = gurobi.QuadExpr(math.exp(7e-7)*math.pow(temp,6) - math.exp(9e-5)*math.pow(temp,5) + 0.0022*math.pow(temp,4) + 0.0887*math.pow(temp,3)- 0.5655*pow(temp,2) - 69.606*temp + 4979.7)
mAggresive.setObjective(EC + EUC + ELAggresive, GRB.MINIMIZE)
Gurobi 只能处理(部分)二次型。当然 x^6 是一样的:
x2 = x^2
x4 = x2^2
x6 = x4*x2
这看起来不错,但通常事情必须是凸的。这意味着我们不能有二次等式约束。在某些情况下,您可以将事物转化为不等式,但通常 Gurobi 无法处理您想要的。
当然,另一种方法是使用分段线性近似。 Gurobi 拥有让这一切变得简单的设施。