由于矩阵太大,CPLEX无法从excell文件读取数据?

时间:2019-04-18 10:05:49

标签: matrix cplex opl

我正在使用具有9241个节点的欧洲电网解决优化问题。为此,我创建了一个连接矩阵并将其插入Excel文件中。使用来自较小问题(较少节点)的代码,该代码从Excel文件获取信息以编写CPLEX矩阵,我尝试将其应用于此较大问题,并得到以下错误:

Exception from IBM ILOG Concert: Can not read data from excel. PEGASE-9241data.dat /Teste 8:36-37 E:\Program Files\IBM\ILOG\CPLEX_Studio129\opl\oplide\workspace\Teste\PEGASE-9241data.dat OPL Problem Marker

一些重要的事情要知道:

- Excel文件为.xlsx

-我使用Matlab将连通性矩阵写入Excel文件中(适用于较小的问题)

当我尝试使用相同的代码解决一个较小的问题(3120个节点)时,效果很好。

型号:

range n = 1..9241;

dvar boolean x[n];
dvar boolean y[n][n];

 //Conectivity matrix
 int A[n][n] =...;

 //Vector ZIB
 int z[n] =...;

 //Objective Function
 dexpr int total = sum (p in n) x[p];


 minimize (total);

 subject to {

   forall (i in n)
      sum (j in n)             
       (A[i][j]*x[j] +A[i][j]*z[j]*y[i][j]) >= 1;

    forall (j in n)
      sum(i in n)
        A[i][j]*y[i][j] == z[j];

 }

数据:

SheetConnection sheet("E:\\Program Files\\IBM\\ILOG\\CPLEX_Studio129\\opl\\oplide\\workspace\\Teste\\PEGASEmatriz9241.xlsx");
A from SheetRead(sheet,"matriz9241");

z from SheetRead(sheet,"zib9241");

1 个答案:

答案 0 :(得分:1)

我认为您遇到内存问题。 我设法运行了可扩展示例

https://www.ibm.com/developerworks/community/forums/html/topic?id=c2469c56-db27-4816-9cf2-f596513ce555&ps=25

直到n = 7000

所以在您的情况下,我会将您的正方形分为4个正方形。

让我分享完整的模型来做到这一点。

首先要写入excel文件以便进行测试:

.mod

execute
{

// http://cwestblog.com/2013/09/05/javascript-snippet-convert-number-to-column-name/
function toColumnName(num) {
  for (var ret = '', a = 1, b = 26; (num -= a) >= 0; a = b, b *= 26) {
    ret = String.fromCharCode(parseInt((num % b) / a) + 65) + ret;
  }
  return ret;
}

// 1,1 => A1  1,4 => D1 2,27 => AA2
function convertR1C1toA1(r,c)
{
return(toColumnName(c)+r);
}

}

int n=4;

int cell[i in 1..n][j in 1..n]=i*j;

int cell1[i in 1..n div 2][j in 1..n div 2]=cell[i][j];
int cell2[i in 1..n div 2][j in n div 2+1..n]=cell[i][j];
int cell3[i in n div 2+1..n][j in 1..n div 2]=cell[i][j];
int cell4[i in n div 2+1..n][j in n div 2+1 ..n]=cell[i][j];

string sheetWriteString1;
string sheetWriteString2;
string sheetWriteString3;
string sheetWriteString4;



execute
{
sheetWriteString1=convertR1C1toA1(1,1)+":"+convertR1C1toA1(n/2,n/2);
writeln("sheetWriteString1=",sheetWriteString1);
sheetWriteString2=convertR1C1toA1(1,n/2+1)+":"+convertR1C1toA1(n/2,n);
writeln("sheetWriteString2=",sheetWriteString2);
sheetWriteString3=convertR1C1toA1(n/2+1,1)+":"+convertR1C1toA1(n,n/2);
writeln("sheetWriteString3=",sheetWriteString3);
sheetWriteString4=convertR1C1toA1(n/2+1,n/2+1)+":"+convertR1C1toA1(n,n);
writeln("sheetWriteString4=",sheetWriteString4);

}

.dat

SheetConnection s("f2.xlsx");

    cell1 to SheetWrite(s,sheetWriteString1);
    cell2 to SheetWrite(s,sheetWriteString2);
    cell3 to SheetWrite(s,sheetWriteString3);
    cell4 to SheetWrite(s,sheetWriteString4);

然后为了读取f2.xls

.mod

int n=...;
    string sheetWriteString1=...;
    string sheetWriteString2=...;
    string sheetWriteString3=...;
    string sheetWriteString4=...;

    int cell1[i in 1..n div 2][j in 1..n div 2]=...;
    int cell2[i in 1..n div 2][j in n div 2+1..n]=...;
    int cell3[i in n div 2+1..n][j in 1..n div 2]=...;
    int cell4[i in n div 2+1..n][j in n div 2+1..n]=...;

    int cell[i in 1..n][j in 1..n]=
    (i<=n div 2)?((j<=n div 2)?cell1[i][j]:cell2[i][j]):((j<=n div 2)?cell3[i][j]:cell4[i][j]);



    assert forall(i,j in 1..n) cell[i][j]==i*j;

.dat

SheetConnection s("f2.xlsx");

    n=4;
    sheetWriteString1="A1:B2";
    sheetWriteString2="C1:D2";
    sheetWriteString3="A3:B4";
    sheetWriteString4="C3:D4";

    cell1 from SheetRead(s,sheetWriteString1);
    cell2 from SheetRead(s,sheetWriteString2);
    cell3 from SheetRead(s,sheetWriteString3);
    cell4 from SheetRead(s,sheetWriteString4);

致谢