Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Update the random seed in the main

    Posted 06/20/16 05:29 AM

    Originally posted by: VictoireD.


    Hello,

    I would like to update the seed for generating random numbers, in the main section. My understanding is that the function Opl.srand is specifically for the model part, not for the main. 

    Thanks in advance for your help,

    Victoire D.

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Update the random seed in the main

    Posted 06/20/16 05:50 AM

    Hi,

    in the main part you may use

    Opl.srand();

    and that will change the random seed for Opl.rand()

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Update the random seed in the main

    Posted 06/20/16 08:37 AM

    Originally posted by: VictoireD.


    Hi Alex,

    Thanks. Just to be sure, this will also change the seed for Math.random?

    Best regards,

    Victoire


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: Update the random seed in the main

    Posted 06/20/16 11:40 AM

    Hi,

    no, it will change the random seed for Opl.rand only

    int a=srand(1);

    execute
    {
    a;
    }

    range r=1..10;
    int b[i in r]=rand(10);
    int b2[i in r];
    float c[r];

    execute
    {
    for(var i in r)
    {
    b2[i]=Opl.rand(10);

    c[i]=Math.random();
    }
    writeln("a= ",a);
    writeln("b= ",b);
    writeln("b2= ",b2);
    writeln("c= ",c);
    }

    gives

    a= 1
    b=  [8 2 9 0 2 7 3 7 0 8]
    b2=  [2 2 2 1 4 9 6 8 5 0]
    c=  [0.0012512 0.56357 0.1933 0.80872 0.58499 0.47986 0.35028 0.89594 0.82281 0.74658]

    but if I change to

    int a=srand(2);

    I get

    a= 2
    b=  [7 2 3 4 8 5 4 0 4 2]
    b2=  [2 3 2 6 0 9 9 1 3 5]
    c=  [0.0012512 0.56357 0.1933 0.80872 0.58499 0.47986 0.35028 0.89594 0.82281 0.74658]

    regards

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: Update the random seed in the main

    Posted 06/20/16 12:12 PM

    Originally posted by: VictoireD.


    Got it, thanks.

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer