Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  help : random value using uniform distribution

    Posted 02/21/12 11:37 AM

    Originally posted by: yulian


    i have a set of number x={1, 4, 3} and i would like to assign each number into a random value in the interval 0,1 by using uniform distribution.
    for example, for x(1)=0.3452 , x(4)=0. 4529 etc.

    please help
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: help : random value using uniform distribution

    Posted 02/22/12 04:49 AM
    Hi

    could

    {int} x={1, 4, 3} ;
     
    float v[x];
     
    execute
    {
     for(var i in x)  v[i]=Math.random();
     writeln(v);
    }
    


    help you?

    NB:

    Math.random() Returns a pseudo-random number between 0, inclusive, and 1, exclusive.

    Regards

    Alex
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: help : random value using uniform distribution

    Posted 02/27/12 10:08 AM

    Originally posted by: yulian


    i have tried to use the code for several datas.
    for example
    {int} x={4,6,8} ;
     
    v= [0.0012512 0.56357 0.1933]
    


    and another example

    {int} x={2,9,14} ;
     
    v=[0.0012512 0.56357 0.1933]
    


    which means the code generated the same numbers.
    and whenever i tried for different size of x

    {int} x={1,3,5,8,6} ;
     
    v=[0.0012512 0.56357 0.1933 0.80872 0.58499]
    


    and i saw that the numbers generated by this code arent changed.
    is there any other way that i can generate the numbers randomly? because im gonna use it for classifying a group of nodes based on the random numbers.

    please help me
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: help : random value using uniform distribution

    Posted 02/28/12 02:44 AM

    Originally posted by: SystemAdmin


    Yulian,

    the numbers you generate are independent of the actual numbers in your set.
    random() just generates a number from the interval 0,1.
    Maybe you will have to multiply them with the value, or alike (whatever
    you have in mind with your approach).

    Actually there are different numbers generated.
    See e.g. th following code snippet
    {int} x={1, 4, 3} ;
     
    float v[x];
     
    execute
    {
     for(var j=1;j<=2;j++){
       for(var i in x)  v[i]=Math.random();
       writeln(v);
     } 
    }
    

    which yields to
    [0.0012512 0.56357 0.1933]
      [0.80872 0.58499 0.47986]
    


    When you restart the whole OPl-RunConfiguration you will get
    the same numbers as the seed for the random number generator
    did not change. If you want that, you will have to explicitely set the
    seed of the generator.

    Hope this helps a bit.

    Best regards
    Norbert
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: help : random value using uniform distribution

    Posted 02/28/12 07:58 AM

    Originally posted by: yulian


    i have tried to run your code, and actually because i need to make a pair of a number from the original set with a number generated from the code, i actually expect the result of the code will have the same size as the original set (so i can make three pairs of numbers in the example)

    do u have any idea about "setting the seed of the generator" ? can u please help me to give the example in a code?

    thank in advance
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: help : random value using uniform distribution

    Posted 02/29/12 03:25 AM

    Originally posted by: SystemAdmin


    Yulian,

    as far as I know there is no way to set the seed for the random number generator in the Math
    library. Maybe someone from the OPL-team can clarify this.

    What you could do is to use the random number generator in the Opl-namespace.
    Below a short code-snippet that might help you

    {int} x={1, 4, 3} ;
    int v[x];
    int seed = 4711;
    execute{
      d = new Date();
      seed = d.getMilliseconds() * d.getSeconds(); 
      writeln("seed = ", seed); 
     
     Opl.srand(seed);
     for(var j=1;j<=2;j++){
       for(var i in x)  v[i]=Opl.rand();
       writeln(v);
     } 
    }
    


    Best regards
    Norbert
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: help : random value using uniform distribution

    Posted 02/29/12 10:35 PM

    Originally posted by: yulian


    actually i need the values of the result exist in the interval 0,1 because in my case, i would need to make a pair of a several numbers inside a set to a number which will represent the values generated by uniform distribution.

    do u have any idea so i can manage to get the result in the interval 0,1 ?
    thank in advance
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 8.  Re: help : random value using uniform distribution

    Posted 03/01/12 02:04 AM

    Originally posted by: SystemAdmin


    you could use rand(m) instead of ranmd() which generates numbers from the interval 0,m and
    then divide by m.
    #DecisionOptimization
    #OPLusingCPLEXOptimizer