Drools分数计算是否应该比EasyScoreCalculator更快?
根据我正在研究的问题大小,我注意到Drools的速度比EasyScoreCalculator慢2-5倍。
例如 流口水
2019-09-04 04:53:47,681 [main] INFO Solving started: time spent (86), best score (-306init/[0]hard/[0/0]soft), environment mode (REPRODUCIBLE), random (JDK with seed 0).
2019-09-04 04:53:50,263 [main] INFO Construction Heuristic phase (0) ended: time spent (2671), best score ([0]hard/[9272/0]soft), score calculation speed (24149/sec), step total (306).
2019-09-04 04:54:02,592 [main] INFO Local Search phase (1) ended: time spent (15000), best score ([0]hard/[9272/0]soft), score calculation speed (31552/sec), step total (38993).
2019-09-04 04:54:02,593 [main] INFO Solving ended: time spent (15001), best score ([0]hard/[9272/0]soft), score calculation speed (30079/sec), phase total (2), environment mode (REPRODUCIBLE).
EasyScoreCalculator
2019-09-04 04:53:10,282 [main] INFO Solving started: time spent (8), best score (-306init/[-306]hard/[0]soft), environment mode (REPRODUCIBLE), random (JDK with seed 0).
2019-09-04 04:53:10,972 [main] INFO Construction Heuristic phase (0) ended: time spent (699), best score ([0]hard/[9272]soft), score calculation speed (90657/sec), step total (306).
2019-09-04 04:53:25,273 [main] INFO Local Search phase (1) ended: time spent (15000), best score ([0]hard/[9272]soft), score calculation speed (109948/sec), step total (193419).
2019-09-04 04:53:25,273 [main] INFO Solving ended: time spent (15000), best score ([0]hard/[9272]soft), score calculation speed (108976/sec), phase total (2), environment mode (REPRODUCIBLE).
我在该测试中使用的唯一Drools规则如下:
rule "Maximise number of picked up parcels"
when
$job: Job(vehicle != null && vehicle.getVehicleType() != VehicleType.DUMMY)
then
scoreHolder.addSoftConstraintMatch(kcontext, 0, $job.getNumberOfParcels());
end
在EasyScoreCalculator中,它看起来像:
public void calculateScore(VehicleRoutingSolution solution) {
int numberOfPickedUpParcels = 0;
List<Job> jobsList = solution.getJobs();
for (Job job : jobsList) {
Vehicle vehicle = job.getVehicle();
if (vehicle!= null) {
if (VehicleType.DUMMY != vehicle.getVehicleType()) {
numberOfPickedUpParcels += job.getNumberOfParcels();
}
}
int[] constraints = new int[1];
int[] objectives = new int[1];
constraints[0] = 0;
objectives[0] = numberOfPickedUpParcels;
return BendableScore.of(constraints, objectives);
}
这不是很奇怪吗?是因为我的规则效率低下,还是Drools分数计算比简单容易慢?
答案 0 :(得分:3)
Drools分数计算是增量式的,因此它的扩展性比EasyScoreCalculator
(非增量式)好得多。
但是,Drools确实会带来性能开销,因此对于较小的数据集,该开销可能会抵消缩放增益。使用optaplanner-benchmark
来尝试3个不同的数据集,每次将其大小加倍,并查看基准测试报告中的效果图。