Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  data array

    Posted 12/21/17 07:14 AM

    Originally posted by: Rym


    Hi,

     

    I would like to fill an already declared array from an execution Block:

    int p=...;

    range P=1..p;

    int PMx[P];

    int Qcpu=192:

    execute Qc
    {

    var x;

    var c=1;
     var px=0;
    var Q=0
    while(Q<(Qcpu))

    {
    x=1+Opl.rand(3-1);
    Q=Q+cpu[x];
    px=px+1;
    PMx[c]=(x);
    c++
    }  
    p=px;
    writeln("Qcpu=",Qcpu);
    writeln("Q=",Q);
    writeln("p=",p);

    }

     

    I had an error message with the red line

     

    Regards

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: data array

    Posted 12/21/17 08:22 AM

    Hi

     int p=3;

    range P=1..p;

    int PMx[P];

    int Qcpu=192;
    int cpu[i in 1..Qcpu]=i;

    execute Qc
    {

    var x;

    var c=1;
    var px=0;
    var Q=0
    while(Q<(Qcpu))

    {
    x=1+Opl.rand(3-1);
    Q=Q+cpu[x];
    px=px+1;
    if (c<=p) PMx[c]=(x);
    c++
    }  
    p=px;
    writeln("Qcpu=",Qcpu);
    writeln("Q=",Q);
    writeln("p=",p);

    }

    works fine

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: data array

    Posted 12/21/17 08:42 AM

    Originally posted by: Rym


    It doesn't work because :

    I don't know the value of p in the beginning, it is depends on the number of px

     int p=...;

    range P=1..p;

    int PMx[P];

    int Qcpu=192;
    int cpu[i in 3]=[96,80,64];

    execute Qc
    {

    var x;

    var c=1;
    var px=0;
    var Q=0
    while(Q<(Qcpu))

    {
    x=1+Opl.rand(3-1);
    Q=Q+cpu[x];
    px=px+1;
    if (c<=p) 
    PMx[c]=(x);
    c++
    }  
    p=px;
    writeln("Qcpu=",Qcpu);
    writeln("Q=",Q);
    writeln("p=",p);

     

    }

    I tried the followng and the result is

     

     

    execute Qc
    {var x;
    var RS=new Array();
    for (var j in 10)
    {
    RS[j]=0;
    }
    var c=1;
     var px=0;
    var Q=0
    while(Q<(Qcpu))

    {
    x=1+Opl.rand(3-1);
    writeln("x=",x);
    Q=Q+cpu[x];
    px=px+1;
    RS["c"]=(x);
    c++
    }  
    p=px;
    for (var df in p)
    {
    PMx[df]=parseInt(RS[df]);
    }
    writeln("Qcpu=",Qcpu);
    writeln("Q=",Q);
    writeln("p=",p);


    writeln(PMx);
    }

     

    Result

    p=3
    PMx=["NaN" "NaN" "NaN"];  //instead of [1,1,1] for example

     

     

    Regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: data array

    Posted 12/21/17 08:45 AM

    Hi

    then you should share a full example that should work but that does not work.

    Otherwise quite hard to help

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer