cvxpy如何制定取决于决策变量符号的表达式

问题描述

优化问题 public class main{ public static void main(String[] args) throws Exception { ArrayList<A> arrayListA = JsonConverter.convertFromJson("a.json",new A()); ArrayList<B> arrayListB = JsonConverter.convertFromJson("b.json",new B()); ArrayList<C> arrayListC = JsonConverter.convertFromJson("c.json",new C()); } } 有两个约束条件列表:

  • Maximize(-obj_Sigma - obj_Cost) 项是决策变量向量 obj_Sigma 的四元形式。
  • x 项是一个线性项,它取决于决策变量向量 obj_Cost 中条目的符号。

在这个例子中:

  • 如果 x 中的条目与 x 的符号相同,则将 5 添加prev_x
  • 如果 obj_Cost 中的条目与 x 的符号相反,则从 prev_x 中减去 5

我的代码如下:

obj_Cost

我知道 import cvxpy as cp import numpy as np # Generate a random non-trivial quadratic program. n = 10 np.random.seed(1) P = np.random.randn(n,n) Sigma = P.T @ P # prevIoUs result prev_x = np.random.randn(n) # Define and solve the CVXPY problem. x = cp.Variable(n) # objective function first term obj_Sigma = 1/2*cp.quad_form(x,Sigma) # objective function 2nd term. # if x has same sign as the corresponding entry in prev_x,# then add 5.0 to the cost. # otherwise substract 5 from the cost # ---- This formulation has problem. obj_Cost = cp.sum(5*cp.sign(cp.multiply(prev_x,x))) obj = -obj_Sigma - obj_Cost prob = cp.Problem(cp.Maximize(obj),[cp.norm(x,1) <= 1.0,cp.abs(x) <= 0.01 ]) prob.solve(verbose=True,solver=cp.MOSEK) 表达式有问题。但是我应该如何制定这个成本条款?一般来说,我如何用依赖于决策变量符号的组件来表述问题。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)