【问题标题】:Arbitrary dimension for CVXGEN programCVXGEN 程序的任意尺寸
【发布时间】:2016-09-29 19:42:05
【问题描述】:

我想使用CVXGEN 解决MatLab 中的QP/LP 问题。我更喜欢CVXGEN 而不是CVX,因为CVXGEN 要快得多。特别想解决

min f(x) s.t. x in X

其中f(x) 是二次形式,X 是紧凑的、凸的并由线性函数定义。问题的大小因运行而异。我想尽可能地自动化这个过程。为了说明,CVXGEN 代码的示例是:

dimensions
  n = 10  
end

parameters
  Q (n,n) psd  # quadratic penalty.
end

variables
  x (n)
end

minimize
  quad(x, Q)
end​​​​​​​​​​​​​

​此代码在cvxgen.com输入。然后,在这个网站上,我可以生成给我一个唯一编号的 C 代码。然后我可以使用唯一编号将其编译成 MEX 代码。最后,我可以通过运行以下代码从 MatLab 调用此 MEX 代码 (csolve)

n=10; % dimension of the problem
params.Q = eye(n,n); % assume that the Hessian is the identity
[vars, status] = csolve(params); % this outputs optimal x* = 0.

但是,此过程需要我要运行的问题n 的每个维度,我需要转到cvxgen.com,更改n,编译代码,然后运行我的MatLab 代码。是否可以让n作为参数输入?这样,我只需要编译一次代码,然后在我的MatLab代码集中params.n = nparams.Q = eye(n,n),然后调用[vars, status] = csolve(params);

【问题讨论】:

    标签: matlab mathematical-optimization hessian-matrix cvx


    【解决方案1】:

    简而言之,我认为不可能在cvxgen.com 上指定任意维度。我确实有一个解决方案:首先,在 MatLab 中,允许用户为cvxgen.com 指定他/她的电子邮件地址和密码。接下来,使用MatLab中的system命令,调用pythonjavascript程序,执行以下步骤:

    1) 将用户登录到cvxgen.com

    2) 转到网站上的edit 选项卡

    3) 复制并粘贴cvxgen 代码

    4) 转到generate c 选项卡

    5) 点击generate code

    6) 转到matlab 选项卡

    7) 复制要下载的编译C代码的唯一标识号

    8) 将唯一标识号传回MatLab,并通过调用标识号编译MatLab 中的Mex 文件。

    现在可以通过以下命令在MatLab 中调用Mex 文件:

    n=10; % dimension of the problem
    params.Q = eye(n,n); % assume that the Hessian is the identity
    [vars, status] = csolve(params); % this outputs optimal x* = 0.
    

    【讨论】:

      猜你喜欢
      • 2023-03-07
      • 1970-01-01
      • 2018-12-30
      • 1970-01-01
      • 2020-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-06
      相关资源
      最近更新 更多