Hi,
in order to cope with simulation, robustness, Monte Carlo ... random functions are very useful.
In OPL, we have 4 random generators and with 3 of them you can set the random seed.
Let me list them and then show examples on how to set random seeds and then use them.
-
Cplex random seed
-
CPO random seed
-
OPL random seed
-
OPL scripting random
int sr=srand(2); // OPL random seed
execute
{
sr;
writeln("OPL random seed=",sr);
}
int oplrandomnumber=rand(20);
execute
{
writeln("OPL random number =",oplrandomnumber);
}
execute
{
cplex.randomseed=3; // CPLEX random seed
}
execute
{
writeln("scripting random function = ",Math.random()); // scripting random function
writeln("cplex random seed =",cplex.randomseed);
}
gives
OPL random seed=2
OPL random number =5
scripting random function = 0.001251221
cplex random seed =3
and
using CP;
int sr=srand(2); // OPL random seed
execute
{
sr;
writeln("OPL random seed=",sr)
}
int oplrandomnumber=rand(20);
execute
{
writeln("OPL random number =",oplrandomnumber);
}
execute
{
cp.param.RandomSeed=4; // CPO random seed
}
execute
{
writeln(Math.random()); // scripting random function
writeln("cpo random seed=",cp.param.randomseed);
}
gives
OPL random seed=2
OPL random number =5
0.001251221
cpo random seed=4
regards
#DecisionOptimization#OPLusingCPLEXOptimizer