简体   繁体   English

Matlab CPLEX:在cplexmiqcp中添加多个SOCP约束

[英]Matlab CPLEX: add multiple SOCP constraints in cplexmiqcp

I have written my problem in MATLAB, using CPLEX as the solver. 我已经使用CPLEX作为求解器在MATLAB中编写了问题。 Due issues that are beyond my control (it is feasible), the CPLEX class API screws up when solving my problem. 由于某些问题超出了我的控制范围(这是可行的),因此CPLEX类API在解决我的问题时会搞砸。 So, based on post found elsewhere on the internet, I am trying to solve using the toolbox API. 因此,根据互联网上其他地方的帖子,我正在尝试使用工具箱API进行解决。

To solve my problem I need to use cplexmiqcp, which has the inputs: 为了解决我的问题,我需要使用cplexmiqcp,它具有以下输入:

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

I have multiple SOCP constraints, and using the class API, I am able to define each of them using a structure, such as: 我有多个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

But how do I define multiple quadratic constraints for cplexmiqcp inputs? 但是,如何为cplexmiqcp输入定义多个二次约束? These are l,Q,r . 这些是l,Q,r When I try creating a structure as before, I get "Error: incorrect l,Q,r." 当我尝试像以前一样创建结构时,出现“错误:不正确的l,Q,r”。

The documentation for the cplexmiqcp toolbox function is here . cplexmiqcp工具箱功能的文档在此处 Quoting the documentation, for l , Q , and r , we have: 引用文档,针对lQr ,我们有:

l: Double column vector or matrix for linear part of quadratic constraints l:二次约束线性部分的双列向量或矩阵
Q: Symmetric double matrix or row cell array of symmetric double matrices for quadratic constraints 问:对称二次矩阵的对称双重矩阵或行单元阵列是否具有二次约束
r: Double or double row vector for rhs of quadratic inequality constraints r:二次不等式约束的rhs的双行或双行向量

So, when we want to create one quadratic constraint, we can give a double column vector, a symmetric double matrix, and a double for l , Q , and r , respectively. 因此,当我们要创建一个二次约束时,可以分别给lQr给出双列向量,对称双矩阵和双精度。 When we want to create multiple quadratic constraints, we need to provide a matrix, a row cell array of symmetric double matrices, and a row vector for l , Q , and r , respectively. 当我们要创建多个二次约束时,我们需要提供一个矩阵,一个对称双矩阵的行单元阵列以及一个分别用于lQr 的行向量

Consider the following simple model: 考虑以下简单模型:

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

The MATLAB code would look like the following: 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');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM