【问题标题】:Why does the CVXPY solver violate this simple constraint为什么 CVXPY 求解器会违反这个简单的约束
【发布时间】:2018-12-10 00:14:02
【问题描述】:
import cvxpy as cp
import numpy as np
x_1 = cp.Variable()
x_2 = cp.Variable()

objective = cp.Minimize(x_1)
constraints = [2*x_1 + x_2 >= 1, x_1+3*x_2>=1, x_1>=0, x_2>=0]
prob = cp.Problem(objective, constraints)

# The optimal objective value is returned by `prob.solve()`.
result = prob.solve()
# The optimal value for x is stored in `x.value`.
print(result)
print("x_1", x_1.value)
print("x_2", x_2.value)

我指定x_1 >= 0,但是求解器给了我这个结果:

-9.944117370034156e-05
x_1 -9.944117370034156e-05
x_2 3.4085428032616

结果 x_1 低于 0

【问题讨论】:

    标签: cvxpy


    【解决方案1】:

    大多数优化器都会允许违反您的约束,最多可以达到某个容差系数。它实际上只是归结为您愿意接受多少约束违规。在您的情况下,听起来您希望您的违规级别非常低。因此,你可以改变

    result = prob.solve()
    

    给了

    -2.2491441767693296e-10
    ('x_1', array(-2.24914418e-10))
    ('x_2', array(1.5537159)
    

    result = prob.solve(feastol=1e-24)
    

    给了

    1.139898310650857e-14
    ('x_1', array(1.13989831e-14))
    ('x_2', array(1.5537766))
    

    与默认设置feastol=1e-7 的结果相比,较低的feastol 设置会产生令人满意的约束违规。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-13
      • 1970-01-01
      • 2011-09-12
      • 2017-01-25
      • 2013-06-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多