【发布时间】:2016-12-01 21:53:54
【问题描述】:
我正在尝试使用 optaplanner 解决轮班分配问题。 这是多对多的关系,因为一个班次可以有很多员工。
在试运行中,我有两名员工,三班倒。 其中一个班次需要两名员工。
所以我创建了一个新的 ShiftAssignment 类来处理多对多关系。 ShiftAssignment 是计划实体,员工是计划变量。
我通过了两班四班分配班(因为一班需要两名员工) 到规划解决方案
我在分数计算器中只有一个硬性规则,基本上是员工应该 具备轮班所需的必要技能
当我运行求解器时,我在下面的代码中打印分数(我没有任何软约束,所以我将它硬编码为零)
public HardSoftScore calculateScore(AuditAllocationSolution auditAllocationSolution) {
int hardScore = 0;
for (Auditor auditor : auditAllocationSolution.getAuditors()) {
for (AuditAssignment auditAssignment : auditAllocationSolution.getAuditAssignments()) {
if (auditor.equals(auditAssignment.getAuditor())) {
List<String> auditorSkils = auditor.getQualifications().stream().map(skill -> skill.getSkillName())
.collect(Collectors.toList());
String requiredSkillForThisAuditInstance = auditAssignment.getRequiredSkill().getSkillName();
if ( !auditorSkils.contains(requiredSkillForThisAuditInstance))
{
// increement hard score since skill match contraint is violated
hardScore = hardScore + 1;
}
}
}
}
System.out.println(" hardScore " + hardScore);
return HardSoftScore.valueOf(hardScore, 0);
}
当我在分数计算器中打印解决方案类的值时,我可以看到硬分数为零的解决方案很少。解决方案满足规则并符合预期结果。但根据日志不接受它
08:16:35.549 [main] TRACE o.o.c.i.l.decider.LocalSearchDecider - Move index (0), score (0hard/0soft), accepted (false), move (AuditAssignment-2 {Auditor-1} <-> AuditAssignment-3 {Auditor-0}).
08:16:35.549 [main] TRACE o.o.c.i.l.decider.LocalSearchDecider - Move index (0), score (0hard/0soft), accepted (false), move (AuditAssignment-2 {Auditor-1} <-> AuditAssignment-3 {Auditor-0}).
我想在日志中澄清的另一个观察结果。 我知道每一个新的解决方案,即每一步的结果,都会传递给分数计算器。但有时我会看到,对于一个步骤,分数计算器会使用不同的解决方案多次调用。这是我从日志中观察到的。假设这是单线程并且日志排序是正确的,为什么会发生这种情况?
最终输出不正确。选择的最佳分数是具有高硬分数的东西。并且得分最高的解决方案不被接受
我还在日志中看到了我无法理解的以下行。我的配置有什么问题吗?
23:53:01.242 [main] DEBUG o.o.c.i.l.DefaultLocalSearchPhase - LS step (26), time spent (121), score (2hard/0soft), best score (4hard/0soft), accepted/selected move count (1/1), picked move (AuditAssignment-2 {Auditor-1} <-> AuditAssignment-0 {Auditor-0}).
23:53:01.242 [main] DEBUG o.o.c.i.l.DefaultLocalSearchPhase - LS step (26), time spent (121), score (2hard/0soft), best score (4hard/0soft), accepted/selected move count (1/1), picked move (AuditAssignment-2 {Auditor-1} <-> AuditAssignment-0 {Auditor-0}).
这是一个小问题,我觉得我没有正确设置它。请建议。
【问题讨论】:
-
在这里大声思考:您是否真的有一条规则说“对于每个未完成的班次,减少分数”?
-
我应该这样做吗?我已经粘贴了分数计算逻辑。每当审核员的技能不匹配时,我都会增加硬分
-
还添加了对未完成班次的检查 - 但问题仍然存在
-
抱歉 - 分数计算器出现问题。当约束失败时,我将硬分增加一。应该是相反的。
-
很高兴你发现了你的错误:) 它现在有效吗?在这种情况下,您可能想发布答案。
标签: optaplanner