1

我使用 CPLEX 作为求解器,在 MATLAB 中编写了我的问题。由于我无法控制的问题(这是可行的),CPLEX 类 API 在解决我的问题时搞砸了。因此,根据在互联网上其他地方找到的帖子,我正在尝试使用工具箱 API 来解决。

为了解决我的问题,我需要使用具有输入的 cplexmiqcp:

cplexmiqcp(H,f,Aineq,bineq,Aeq,beq,l,Q,r,sostype,sosind,soswt,varLB,varUB,vartype,x0,options);

我有多个 SOCP 约束,并且使用类 API,我能够使用结构定义它们中的每一个,例如:

for n=1:numQCs
    cplex.Model.qc(n).a=QC.a{n};
    cplex.Model.qc(n).Q=QC.Q{n,1};
    cplex.Model.qc(n).sense=QC.sense{n};
    cplex.Model.qc(n).rhs=QC.rhs{n};
    cplex.Model.qc(n).lhs=QC.lhs{n};
end

但是如何为 cplexmiqcp 输入定义多个二次约束?这些是l,Q,r。当我尝试像以前一样创建结构时,我得到“错误:不正确的 l、Q、r”。

4

1 回答 1

0

cplexmiqcp 工具箱函数的文档在这里。引用文档,对于lQr,我们有:

l:二次约束的线性部分的双列向量或矩阵
Q:二次约束的对称双矩阵或对称双矩阵的行元胞数组
r:二次不等式约束的 rhs 的双行向量或双行向量

因此,当我们想要创建一个二次约束时,我们可以分别给出一个双列向量、一个对称双精度矩阵和一个双精度l矩阵。当我们要创建多个二次约束时,我们需要分别提供一个矩阵、一个对称双精度矩阵的行元胞数组以及一个用于、和的行向量。QrlQr

考虑以下简单模型:

Minimize
 obj: x1 + x2 + x3 + x4 + x5 + x6
Subject To
 c1: x1 + x2 + x5  = 8
 c2: x3 + x5 + x6  = 10
 q1: [ - x1 ^2 + x2 ^2 + x3 ^2 ] <= 0
 q2: [ - x4 ^2 + x5 ^2 ] <= 0
Bounds
      x2 Free
      x3 Free
      x5 Free
End

MATLAB 代码如下所示:

   H = [];
   f = [1 1 1 1 1 1]';                                                          

   Aineq = []                                                                   
   bineq = []                                                                   

   Aeq = [1 1 0 0 1 0;                                                          
          0 0 1 0 1 1];                                                         
   beq = [8 10]';

   l = [0 0;
        0 0;
        0 0;
        0 0;
        0 0;
        0 0;];
   Q = {[-1 0 0 0 0 0;
         0 1 0 0 0 0;
         0 0 1 0 0 0;
         0 0 0 0 0 0;
         0 0 0 0 0 0;
         0 0 0 0 0 0], ...
        [0 0 0 0 0 0;
         0 0 0 0 0 0;
         0 0 0 0 0 0;
         0 0 0 -1 0 0;
         0 0 0 0 1 0;
         0 0 0 0 0 0]};
   r = [0 0];

   sostype = [];
   sosind = [];
   soswt = [];

   lb    = [ 0; -inf; -inf; 0; -inf; 0];
   ub    = []; % implies all inf
   ctype = []; % implies all continuous

   options = cplexoptimset;
   options.Display = 'on';
   options.ExportModel = 'test.lp';

   [x, fval, exitflag, output] = cplexmiqcp (H, f, Aineq, bineq, Aeq, beq,...
      l, Q, r, sostype, sosind, soswt, lb, ub, ctype, [], options);

   fprintf ('\nSolution status = %s \n', output.cplexstatusstring);
   fprintf ('Solution value = %f \n', fval);
   disp ('Values =');
   disp (x');
于 2018-05-01T16:41:58.347 回答