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 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>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 可选: 要更改伪随机数生成器实现,请为下面的 resolver 配置文件中列出的
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>
<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>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 支持以下伪随机数生成器:
-
JDK
(默认):标准随机数生成器实现(java.util.Random
) -
MERSENNE_TWISTER
: Commons Math的随机数生成器实现 -
WELL512A
,WELL1024A
,WELL19937A
,WELL19937C
,WELL44497A
和WELL44497B
: Commons Math的 Random 数生成器实现
-
对于大多数用例,randomType
属性的值不会影响对多个数据集的最佳解决方案的平均质量。