OptaPlanner护士排班累积总和Null指针异常 [英] OptaPlanner Nurse Rostering accumulate sum Null Pointer Exception

查看:106
本文介绍了OptaPlanner护士排班累积总和Null指针异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试修改OptaPlanner护士名册示例. 到目前为止,我想在drl文件中编写一条规则,当员工每天工作超过13个小时时,该规则会做出反应. 我扩展了shiftType类,使每个Shift可以获得小时数.

I try to modify the OptaPlanner nurse Roster example. So far, I want to write a rule in the drl file which reacts when an employee works more than 13 hours per day. I expanded the class shiftType to get hours per Shift.

乍一看,该规则似乎有效,但是过一会儿没有可行的解决方案时,我会收到NullPointerException.

At first look, the rule seems to work but when there is no feasible solution after a while I get a NullPointerException.

以下是一些相关代码:

rule "dailyRestPeriod"
when


ShiftAssignment($employee : employee, $shiftType : shiftType, $shiftDate : shiftDate, $employee!=null)
$dailyTotalHours : Number( intValue > 13) from accumulate(
                 $assignmentEmployee:  ShiftAssignment(employee == $employee, shiftDate == $shiftDate),
            sum($assignmentEmployee.getShiftType().getShiftDurationHours())
        )
then

System.out.println("Employee " +$employee +" dailyTotal " +$dailyTotalHours);
 scoreHolder.addHardConstraintMatch(kcontext, - 1);
end

部分例外情况

Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: Solving failed.
    at org.optaplanner.examples.common.swingui.SolverAndPersistenceFrame$SolveWorker.done(SolverAndPersistenceFrame.java:319)
    at javax.swing.SwingWorker$5.run(Unknown Source)
    at javax.swing.SwingWorker$DoSubmitAccumulativeRunnable.run(Unknown Source)
    at sun.swing.AccumulativeRunnable.run(Unknown Source)
    at javax.swing.SwingWorker$DoSubmitAccumulativeRunnable.actionPerformed(Unknown Source)
    at javax.swing.Timer.fireActionPerformed(Unknown Source)
    at javax.swing.Timer$DoPostEvent.run(Unknown Source)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$500(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.RuntimeException: java.lang.NullPointerException
    at org.drools.core.rule.SingleAccumulate.reverse(SingleAccumulate.java:124)
    at org.drools.core.phreak.PhreakAccumulateNode.removeMatch(PhreakAccumulateNode.java:806)
    at org.drools.core.phreak.PhreakAccumulateNode.removePreviousMatchesForRightTuple(PhreakAccumulateNode.java:865)
    at org.drools.core.phreak.PhreakAccumulateNode.doRightUpdates(PhreakAccumulateNode.java:444)
    at org.drools.core.phreak.PhreakAccumulateNode.doNode(PhreakAccumulateNode.java:87)
    at org.drools.core.phreak.RuleNetworkEvaluator.switchOnDoBetaNode(RuleNetworkEvaluator.java:534)
    at org.drools.core.phreak.RuleNetworkEvaluator.evalBetaNode(RuleNetworkEvaluator.java:505)
    at org.drools.core.phreak.RuleNetworkEvaluator.evalNode(RuleNetworkEvaluator.java:341)
    at org.drools.core.phreak.RuleNetworkEvaluator.innerEval(RuleNetworkEvaluator.java:301)
    at org.drools.core.phreak.RuleNetworkEvaluator.outerEval(RuleNetworkEvaluator.java:136)
    at org.drools.core.phreak.RuleNetworkEvaluator.evaluateNetwork(RuleNetworkEvaluator.java:94)
    at org.drools.core.phreak.RuleExecutor.reEvaluateNetwork(RuleExecutor.java:194)
    at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:73)
    at org.drools.core.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:970)
    at org.drools.core.common.DefaultAgenda.fireLoop(DefaultAgenda.java:1312)
    at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1251)

推荐答案

我不明白为什么,但是当我稍微修改规则时,当我分解规则时它就可以正常工作. 也许这与计划变量和计划实体有关,但是我不确定. 这是现在的代码:

I don't understand why but when i change the rule a little bit it works fine when i broke down the rule. Perhaps it has something to do with planning variables and planning entity,.. but I'm not sure. Here is the code how it looks like now:

rule "dailyRestPeriod"
when
$employee : Employee()
$shift : Shift( $shiftType : shiftType ,  $shiftDate :shiftDate )
$dailyTotalHours : Number( intValue >= 13) from accumulate(
                 $assignmentEmployee:  ShiftAssignment(employee == $employee, shiftDate == $shiftDate),
            sum($assignmentEmployee.getShiftType().getShiftDurationHours())
        )
then
scoreHolder.addHardConstraintMatch(kcontext, - 1);
end

这篇关于OptaPlanner护士排班累积总和Null指针异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆