Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  OPL script

    Posted 12/20/18 01:53 AM

    Originally posted by: 18125514


    I created a two-dimensional array in the scripting language. Why can't I use it in the model?Thanks very much.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: OPL script

    Posted 12/20/18 01:57 AM

    Originally posted by: 18125514


    Use a script to create this two-dimensional array because one of the subscripts of the array is affected by another subscript


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: OPL script



  • 4.  Re: OPL script

    Posted 12/20/18 03:06 AM

    Originally posted by: 18125514


    OK,thanks much!

    The model is as follows:

    {string} Au = {"a","b"}; 
    {string} Am = {"c","d"};  
    {string} Ad = {"e","f"};
    {string} A =Au union Am union Ad;
    int S[A]=[1,1,1,2,2,2];
    int m=6;
    int n=card(A);
     
    // initialize the  2 dimensional array
    execute{
    var s = new Array (thisOplModel.A+thisOplModel.S[A]) ; 
        for( var i in thisOplModel.A){
             s[i] = new Array(S[A]);
             var a=thisOplModel.S[i]
             for(var j=1;j<=a;j++) {           
              s[i][j]= 123.0; 
              writeln( s[i][j]);     
                            }
                  }          
    }
    float f[A][s]=...;

    The problem is this:

    "A" represents the arc.

    "s" represents the fragment in each arc.

    The maximum number of s in each arc is S[A].

    Now I just want to show s, but s will be affected by A, so I wrote a two-dimensional array with a script. But it doesn't seem to work.

    At the same time, s will be used as a subscript to indicate other variables.

    Because s is affected by the specific arc, this problem has not solved me well in a week.

    Thank you very much for your attention.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: OPL script

    Posted 12/20/18 03:15 AM

    Hi,

    to compute s you could write

    {string} Au = {"a","b"};
    {string} Am = {"c","d"};  
    {string} Ad = {"e","f"};
    {string} A =Au union Am union Ad;
    int S[A]=[1,1,1,2,2,2];
    int m=6;
    int n=card(A);
     
    // initialize the  2 dimensional array
    execute{
    var s = new Array (thisOplModel.A.size) ;
        for( var i in thisOplModel.A){
             s[i] = new Array(S[i]);
             var a=thisOplModel.S[i]
             for(var j=1;j<=a;j++) {           
              s[i][j]= 123.0;
              writeln( s[i][j]);     
                            }
                  }          
    }

    and then you could have a look at

    https://www.ibm.com/developerworks/community/forums/html/topic?id=77f1dd38-2937-42b2-9fc1-4edb400b9c71&ps=25

     

    regards

     

    NB: Many how to at https://www.linkedin.com/pulse/how-opl-alex-fleischer/


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: OPL script

    Posted 12/20/18 04:56 AM

    Originally posted by: 18125514


    thanks very much!


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: OPL script

    Posted 12/20/18 06:41 AM

    Originally posted by: 18125514


    Thank you for your answers in the afternoon, which will benefit me a lot.

    There is another question here.

    A set can be used as a subscript for a variable. So what about arrays with subscripts?


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 8.  Re: OPL script

    Posted 12/20/18 06:48 AM

    Hi,

    int a[1..2];

    execute
    {
    a[1]=3;
    a[2]=4;
    writeln("a=",a);
    }

    gives

    a= [3 4]

    regards

     

    PS:

    Many links at https://www.linkedin.com/pulse/low-barrier-entry-optimization-through-cplex-alex-fleischer/


    #DecisionOptimization
    #OPLusingCPLEXOptimizer