Matlab CPLEX:在cplexmiqcp

时间:2018-04-30 20:53:45

标签: matlab constraints cplex quadratic-programming

我在MATLAB中使用CPLEX作为求解器编写了我的问题。由于我无法控制的问题(这是可行的),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。”

1 个答案:

答案 0 :(得分:0)

cplexmiqcp工具箱函数的文档是here。引用lQr的文档,我们有:

  

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

因此,当我们想要创建一个二次约束时,我们可以给出一个双列向量,一个对称双矩阵,以及lQr的双精度数,分别。当我们想要创建多个二次约束时,我们需要为lQ提供矩阵,对称双矩阵的行单元阵列和行向量,以及分别为r

考虑以下简单模型:

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');