Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Random Number with OPL

    Posted 01/10/12 10:31 AM

    Originally posted by: SystemAdmin


    Folks,

    Does any one knows how to generate different sequence of random numbers after each run with CPLEX by using OPL? FYI, I don't want to call external library from Java, C, etc.

    I'm using rand function, however, I'm getting the same numbers after each run. The srand function seems not to have any effect for seed initialization.

    The sample code is as follows:

    int mySeed = srand(50);
    int tabSize = 60;
    int myRandTabhttp://i in 1..20 = 1 + rand(tabSize);

    Appreciate your help.

    Alain
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Random Number with OPL

    Posted 01/10/12 02:36 PM

    Originally posted by: SystemAdmin


    Since your seed to the random number generator (srand) is the same for every run, you get the same set of numbers via the rand function every time. An easy way to generate a new seed for every run is the use of the Date function for the generator. Here's one such implementation:

    int mySeed;
    execute{
            var now = new Date();
            mySeed = Opl.srand(Math.round(now.getTime()/1000));
    }     
    int tabSize = 60;
    int myRandTab[i in 1..20] = 1 + rand(tabSize);
    

    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Random Number with OPL

    Posted 02/01/12 03:44 PM

    Originally posted by: matrus2


    Thank you for help.

    I tried to put it:
    main{
    for (var nnn=1;nnn<=ilN;nnn++){
    suma=0
    for (var scen=1;scen<=ilS;scen++){
    var now = new Date();
    ofile.writeln(now);
    masterData.s scen nnn=Opl.srand(Math.round(now.getTime()/1000));
    suma=masterData.s scen nnn +suma;
    ofile.writeln("scen " + scen + " nnnn " + nnn + " asdasd " + masterData.s scen nnn );
    }

    }
    }

    The output is:

    scen 1 nnnn 1 asdasd 1328128654
    02/01/2012 21:37:34 042
    scen 2 nnnn 1 asdasd 1328128654
    02/01/2012 21:37:34 043
    scen 3 nnnn 1 asdasd 1328128654
    02/01/2012 21:37:34 043
    scen 4 nnnn 1 asdasd 1328128654
    02/01/2012 21:37:34 043
    scen 5 nnnn 1 asdasd 1328128654
    02/01/2012 21:37:34 043
    scen 1 nnnn 2 asdasd 1328128654
    02/01/2012 21:37:34 043
    scen 2 nnnn 2 asdasd 1328128654
    02/01/2012 21:37:34 043
    scen 3 nnnn 2 asdasd 1328128654
    02/01/2012 21:37:34 043
    scen 4 nnnn 2 asdasd 1328128654
    02/01/2012 21:37:34 043
    scen 5 nnnn 2 asdasd 1328128654
    02/01/2012 21:37:34 043
    scen 1 nnnn 3 asdasd 1328128654
    02/01/2012 21:37:34 043

    As you may see the data (10 elements) was generated during 2msec so it is impossible to generate it by this function. Any idea?
    #DecisionOptimization
    #OPLusingCPLEXOptimizer