【问题标题】:Use or operator in constraint cvxpy在约束 cvxpy 中使用或运算符
【发布时间】:2022-10-12 21:18:31
【问题描述】:

我正在尝试使用 cvxpy 但我不知道如何使用或操作符。

我有

x = cp.Variable(N, integer=True)

我试试

x[i]==0 or x>=m[i]

我收到了这个错误

> Cannot evaluate the truth value of a constraint or chain constraints, e.g., 1 >= x >= 0.

然后我尝试:

for i in range(N):
    constraints += [
        x[i]*(x[i]-m[i])>=0,
    ]

我得到了

> Problem does not follow DCP rules.

有人能帮我吗?谢谢

【问题讨论】:

    标签: python optimization cvxpy convex-optimization


    【解决方案1】:

    约束

     x=0 or x≥L
    

    被称为x 是一个半连续变量。一些求解器和工具为此提供了专门的工具。否则,添加一个二进制变量 y 并使用:

     y*L ≤ x ≤ y*U
     x ∈ [0,U]        (U is an upperbound on x)
     y ∈ {0,1} 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-03
      • 2021-04-21
      相关资源
      最近更新 更多