Topic
  • 4 replies
  • Latest Post - ‏2013-04-03T14:35:39Z by SystemAdmin
SystemAdmin
SystemAdmin
1883 Posts

Pinned topic How can we convert 'n' 2D data read from excel to 3D array in OPL CPLEX.

‏2013-04-03T10:54:59Z |
Dear all,

I would like to know how can I convert my 2D data, that is read from excel sheet, into 3D array.

I know, we can do this by using for loops, but its taking alot of memory since my problem is large.

Example to elaborate what exactly I want to do.
*/*Data File*/*

SheetConnection sheet("Question.xlsx");

p1 from SheetRead(sheet,"sheet1!A1:D10");
p2 from SheetRead(sheet,"sheet1!G1:J10");
p3 from SheetRead(sheet,"sheet1!M1:P10");

where number of rows are 10 and columns are 4.

I want to convert these three (p1,p2,p3) 2D arrays into single 3D array.

*/*mod file*/*
range rows=1..10;
range col=1..4;
range Tot=1..3;

int p1rowscol=...;
int p2rowscol=...;
int p3rowscol=...;
int pTotrowscol;

execute{
for (var r in rows){
for(var c in col){
p[1][r][c]=p1[r][c];
p[2][r][c]=p2[r][c];
p[3][r][c]=p3[r][c];
}}}

Though, its giving me few results, but this is not efficient way i guess.

Kindly, give some feedback to do efficiently.

Thankyou in anticipation

regards,
waqas
Updated on 2013-04-03T14:35:39Z at 2013-04-03T14:35:39Z by SystemAdmin
  • AlexFleischer
    AlexFleischer
    1204 Posts

    Re: How can we convert 'n' 2D data read from excel to 3D array in OPL CPLEX.

    ‏2013-04-03T11:14:01Z  
    Hi,

    what is not very efficient
    is

    int p[Tot][rows][col];
     
    execute{
    for (var r in rows){
    for(var c in col){
    p[1][r][c]=p1[r][c];
    p[2][r][c]=p2[r][c];
    p[3][r][c]=p3[r][c];
    }}}
    


    you could rewrite in something like

    int p[Tot][rows][col]=(tot==1)?(p1[r][c]):((tot==2)?(p2[r][c]):(p3[r][c]));
    


    regards
    Updated on 2014-03-26T05:49:40Z at 2014-03-26T05:49:40Z by AlexFleischer
  • SystemAdmin
    SystemAdmin
    1883 Posts

    Re: How can we convert 'n' 2D data read from excel to 3D array in OPL CPLEX.

    ‏2013-04-03T11:36:35Z  
    Thankx for your time.

    but, I am encountering some errors when i replaced the for loops with below commands.

    int pTotrowscol=(Tot==1)?(p1[r][c]):((Tot==2)?(p2[r][c]):(p3[r][c]));

    I think syntax need to be updated. I searched for help but could not get that.

    please share if you know excat syntax.

    thankx
  • AlexFleischer
    AlexFleischer
    1204 Posts

    Re: How can we convert 'n' 2D data read from excel to 3D array in OPL CPLEX.

    ‏2013-04-03T12:20:08Z  
    Thankx for your time.

    but, I am encountering some errors when i replaced the for loops with below commands.

    int pTotrowscol=(Tot==1)?(p1[r][c]):((Tot==2)?(p2[r][c]):(p3[r][c]));

    I think syntax need to be updated. I searched for help but could not get that.

    please share if you know excat syntax.

    thankx
    Hi,

    remember I wrote "something like"

    int p[tot in Tot][r in rows][c in col]=(tot==1)?(p1[r][c]):((tot==2)?(p2[r][c]):(p3[r][c]));
    


    should work better

    regards
    Updated on 2014-03-26T05:49:35Z at 2014-03-26T05:49:35Z by AlexFleischer
  • SystemAdmin
    SystemAdmin
    1883 Posts

    Re: How can we convert 'n' 2D data read from excel to 3D array in OPL CPLEX.

    ‏2013-04-03T14:35:39Z  
    Hi,

    remember I wrote "something like"

    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">int p[tot in Tot][r in rows][c in col]=(tot==1)?(p1[r][c]):((tot==2)?(p2[r][c]):(p3[r][c])); </pre>

    should work better

    regards
    Thankx.. Its working..!!

    Appreciate!!