You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I found a bug in the way the random seed is used when creating a Search.randomStrategy. The same seed is used for the VariableSelector and the ValueSelector. This makes the two selectors not independent, and is an issue, for example in the next model:
Whatever the value of the seed, the first solution returned by the solving process will be [0,1,2]. This happens because on this particular example, the calls to the random will always be done on the same values on the ValueSelector and on the VariableSelector.
By generating seeds with the random generator, the seeds will be independent.
Modifying the type of Search.randomSearch(...)
An other solution is to give an instance of java.util.Random to Search.randomSearch(...), and proceed as the previous . That way, the user would input the random generator.
Having a global random generator
Maybe the best but most expensive way to do is to have a random generator initialized at the beginning of the program (either by a seed given by the user, or another random generator given by the user), and pass this random generator to all the classes that need to generate random numbers. The same random generator will be used by every class, ensuring that each call to generate a new number is independent from the previous ones.
This fix raises a big problem on how to deal with parallelism.
I hope you will be able to find a solution. I don't know if there is a canonical way to deal with randomness in software, my solutions may not be the best ones.
Have a great day.
The text was updated successfully, but these errors were encountered:
I agree with Arnaud that the seed should remain fixed to ensure reproducibility.
Note that only the first decision will always be of the form xi = i, then decisions will be xi = ith value in the domain which, because of constraint propagation, will not always be i. This being said, it is true there is a bias here.
I am not expert in seeds but I guess giving to the value selector the variable selector seed +1 would do the job. At least there is a 100% guarantee to have a different seed...
Hello,
The issue
I found a bug in the way the random seed is used when creating a Search.randomStrategy. The same seed is used for the VariableSelector and the ValueSelector. This makes the two selectors not independent, and is an issue, for example in the next model:
Whatever the value of the seed, the first solution returned by the solving process will be [0,1,2]. This happens because on this particular example, the calls to the random will always be done on the same values on the ValueSelector and on the VariableSelector.
Some possible fixes
Modifying the body of Search.randomSearch(...)
Replace the body of the function by
By generating seeds with the random generator, the seeds will be independent.
Modifying the type of Search.randomSearch(...)
An other solution is to give an instance of java.util.Random to Search.randomSearch(...), and proceed as the previous . That way, the user would input the random generator.
Having a global random generator
Maybe the best but most expensive way to do is to have a random generator initialized at the beginning of the program (either by a seed given by the user, or another random generator given by the user), and pass this random generator to all the classes that need to generate random numbers. The same random generator will be used by every class, ensuring that each call to generate a new number is independent from the previous ones.
This fix raises a big problem on how to deal with parallelism.
I hope you will be able to find a solution. I don't know if there is a canonical way to deal with randomness in software, my solutions may not be the best ones.
Have a great day.
The text was updated successfully, but these errors were encountered: