8.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! 可选: 要更改伪随机数生成器实现,请为下面的 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>
<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! 支持以下伪随机数生成器:
-
JDK
(默认):标准随机数生成器实现(java.util.Random
) -
MERSENNE_TWISTER
: Commons Math:随机数字生成器实现 -
WELL512A
,WELL1024A
,WELL19937A
,WELL19937C
,WELL44497A
和WELL44497B
: Commons Math
-
对于大多数用例,randomType
属性的值对多个数据集的最佳解决方案的平均质量没有严重影响。