7.7. 配置随机数字生成器
许多 Heuristics 和 metaheuristics 依赖于伪随机数字生成器来移动选择,以解决分数绑定、基于迁移接受的可能性等。在解决期间,重复利用相同的随机实例,以提高随机值的可重复性、性能和统一分布。
随机 seed 是一个用于初始化伪随机数生成器的数字。
流程
可选:要更改随机实例的随机 seed,请指定一个
randomSeed
:<solver xmlns="https://www.optaplanner.org/xsd/solver" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://www.optaplanner.org/xsd/solver https://www.optaplanner.org/xsd/solver/solver.xsd"> <randomSeed>0</randomSeed> ... </solver>
可选:要更改伪随机数生成器实现,请为以下 solver 配置文件中列出的
randomType
属性指定一个值,其中 <RANDOM_NUMBER_GENERATOR&
gt; 是一个伪随机数生成器:<solver xmlns="https://www.optaplanner.org/xsd/solver" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://www.optaplanner.org/xsd/solver https://www.optaplanner.org/xsd/solver/solver.xsd"> <randomType><RANDOM_NUMBER_GENERATOR></randomType> ... </solver>
支持以下伪随机数生成器:
-
JDK
(默认):标准随机数生成器实施(java.util.Random
) -
MERSENNE_TWISTER
: Random number generator implementation by Commons Math -
WELL512A
,WELL1024A
,WELL19937A
,WELL19937C
,WELL44497A
和WELL44497B
: Random number generator implementation by Commons Math
-
对于大多数用例,randomType
属性的值不会影响到多个数据集上最佳解决方案的平均质量。