Ackerman
Ackerman

Reputation: 19

CPLEX can't read data from excell file because matrix is too big?

I am solving a optimization problem using a european electric grid with 9241 nodes. To do that I created a connectivity matrix and inserted it in an Excel file. Using code from smaller problems (less nodes), which takes the information from the Excel file to write a CPLEX matrix, I tried to apply it to this bigger problem and I get the following error:

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

Some important things to know:

- The Excel file is .xlsx

- I wrote the connectivity matrix into the Excel file using Matlab (worked for smaller problems)

When I try the same code with a smaller problem (3120 nodes) It works fine.

Model:

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];

 }

Data:

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

Upvotes: 0

Views: 1609

Answers (1)

Alex Fleischer
Alex Fleischer

Reputation: 10037

I think you have a memory issue. I managed to run the scalable example

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

til n=7000

So in your case I would divide your square into 4 squares. Let me share the full model to do that.

First to write into the Excel file in order to let you test.

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

and then in order to read 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);

Upvotes: 1

Related Questions