[jboss-jira] [JBoss JIRA] (DROOLS-349) Optaplanner rules NullPointerException
Geoffrey De Smet (JIRA)
jira-events at lists.jboss.org
Fri Nov 22 07:14:06 EST 2013
[ https://issues.jboss.org/browse/DROOLS-349?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Geoffrey De Smet updated DROOLS-349:
------------------------------------
Description:
I reported my issue with a Drools rule in Optaplanner on the Drools user forum (http://drools.46999.n3.nabble.com/Optaplanner-rules-NullPointerException-td4026875.html). I was adviced to create a JIRA ticket.
=============
I am trying to accomplish the following, a part time employee (eg 50%) needs to do only half the shifts a full time employee needs to do. I have created a rule, that
1. count number of shifts of certain shiftType
2. count number of shifts of a certain shiftType per employee
3. count the total number of "arbeidsbreuken" per employee and within a certain shiftType
4. do something with these numbers so that an part time employee only gets half the shifts assigned that a full time employee gets
The complete rule is:
{code}
rule "arbeidsbreuk"
when
//System.out.println("arbeidsbreuk, Drools!");
ShiftAssignment($employee : employee, $shiftType : shiftType)
//count aantal shifts
$assignmentTotal : Number() from accumulate(
$assignment : ShiftAssignment(shiftType == $shiftType),
count($assignment)
)
//count aantal shifts per medewerker
$assignmentTotalEmployee : Number() from accumulate(
$assignmentEmployee : ShiftAssignment(employee == $employee, shiftType == $shiftType),
count($assignmentEmployee)
)
//count arbeidsbreuken van alle medewerkers
$arbeidsbreukTotal : Number() from accumulate(
//Employee($breuk : arbeidsbreuk),
ShiftAssignment(employee == $employee, shiftType == $shiftType),
sum($employee.getArbeidsbreuk())
)
$assignmentTotalEmployee.intValue())
then
System.out.println("Arbeidsbreuk drools: " + $employee.getArbeidsbreuk() + " - " + $assignmentTotal.intValue() + " - " + $assignmentTotalEmployee.intValue() + " - " + $arbeidsbreukTotal);
scoreHolder.addSoftConstraintMatch(kcontext, -(Math.abs(($employee.getArbeidsbreuk() * $assignmentTotal.intValue()) - $assignmentTotalEmployee.intValue()) * (Math.abs(($employee.getArbeidsbreuk() * $assignmentTotal.intValue()) - $assignmentTotalEmployee.intValue()))) );
end
{code}
I get the following error:
{code}
Exception in thread "main" org.drools.core.RuntimeDroolsException: java.lang.NullPointerException
at org.drools.core.rule.Accumulate.accumulate(Accumulate.java:182)
at org.drools.core.phreak.PhreakAccumulateNode.addMatch(PhreakAccumulateNode.java:756)
at org.drools.core.phreak.PhreakAccumulateNode.doLeftInserts(PhreakAccumulateNode.java:164)
at org.drools.core.phreak.PhreakAccumulateNode.doNode(PhreakAccumulateNode.java:81)
at org.drools.core.phreak.RuleNetworkEvaluator.switchOnDoBetaNode(RuleNetworkEvaluator.java:524)
at org.drools.core.phreak.RuleNetworkEvaluator.evalBetaNode(RuleNetworkEvaluator.java:494)
at org.drools.core.phreak.RuleNetworkEvaluator.innerEval(RuleNetworkEvaluator.java:277)
at org.drools.core.phreak.RuleNetworkEvaluator.outerEval(RuleNetworkEvaluator.java:161)
at org.drools.core.phreak.RuleNetworkEvaluator.evaluateNetwork(RuleNetworkEvaluator.java:116)
at org.drools.core.phreak.RuleExecutor.reEvaluateNetwork(RuleExecutor.java:205)
at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:65)
at org.drools.core.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:936)
at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1183)
at org.drools.core.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:935)
at org.drools.core.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:909)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:233)
at org.optaplanner.core.impl.score.director.drools.DroolsScoreDirector.calculateScore(DroolsScoreDirector.java:98)
at org.optaplanner.core.impl.solver.scope.DefaultSolverScope.calculateScore(DefaultSolverScope.java:101)
at org.optaplanner.core.impl.bestsolution.BestSolutionRecaller.solvingStarted(BestSolutionRecaller.java:58)
at org.optaplanner.core.impl.solver.DefaultSolver.solvingStarted(DefaultSolver.java:177)
at org.optaplanner.core.impl.solver.DefaultSolver.solve(DefaultSolver.java:154)
at be.ocmwturnhout.permanenties.Main.main(Main.java:495)
Caused by: java.lang.NullPointerException
at be.ocmwturnhout.permanenties.solver.Rule_arbeidsbreuk654888368.accumulateExpression2(Rule_arbeidsbreuk654888368.java:23)
at be.ocmwturnhout.permanenties.solver.Rule_arbeidsbreuk654888368AccumulateExpression2Invoker.evaluate(Rule_arbeidsbreuk654888368AccumulateExpression2Invoker.java:25)
at org.drools.core.base.accumulators.JavaAccumulatorFunctionExecutor.accumulate(JavaAccumulatorFunctionExecutor.java:107)
at org.drools.core.rule.Accumulate.accumulate(Accumulate.java:173)
... 21 more
{code}
was:
I reported my issue with a Drools rule in Optaplanner on the Drools user forum (http://drools.46999.n3.nabble.com/Optaplanner-rules-NullPointerException-td4026875.html). I was adviced to create a JIRA ticket.
=============
I am trying to accomplish the following, a part time employee (eg 50%) needs to do only half the shifts a full time employee needs to do. I have created a rule, that
1. count number of shifts of certain shiftType
2. count number of shifts of a certain shiftType per employee
3. count the total number of "arbeidsbreuken" per employee and within a certain shiftType
4. do something with these numbers so that an part time employee only gets half the shifts assigned that a full time employee gets
The complete rule is:
rule "arbeidsbreuk"
when
//System.out.println("arbeidsbreuk, Drools!");
ShiftAssignment($employee : employee, $shiftType : shiftType)
//count aantal shifts
$assignmentTotal : Number() from accumulate(
$assignment : ShiftAssignment(shiftType == $shiftType),
count($assignment)
)
//count aantal shifts per medewerker
$assignmentTotalEmployee : Number() from accumulate(
$assignmentEmployee : ShiftAssignment(employee == $employee, shiftType == $shiftType),
count($assignmentEmployee)
)
//count arbeidsbreuken van alle medewerkers
$arbeidsbreukTotal : Number() from accumulate(
//Employee($breuk : arbeidsbreuk),
ShiftAssignment(employee == $employee, shiftType == $shiftType),
sum($employee.getArbeidsbreuk())
)
$assignmentTotalEmployee.intValue())
then
System.out.println("Arbeidsbreuk drools: " + $employee.getArbeidsbreuk() + " - " + $assignmentTotal.intValue() + " - " + $assignmentTotalEmployee.intValue() + " - " + $arbeidsbreukTotal);
scoreHolder.addSoftConstraintMatch(kcontext, -(Math.abs(($employee.getArbeidsbreuk() * $assignmentTotal.intValue()) - $assignmentTotalEmployee.intValue()) * (Math.abs(($employee.getArbeidsbreuk() * $assignmentTotal.intValue()) - $assignmentTotalEmployee.intValue()))) );
end
I get the following error:
Exception in thread "main" org.drools.core.RuntimeDroolsException: java.lang.NullPointerException
at org.drools.core.rule.Accumulate.accumulate(Accumulate.java:182)
at org.drools.core.phreak.PhreakAccumulateNode.addMatch(PhreakAccumulateNode.java:756)
at org.drools.core.phreak.PhreakAccumulateNode.doLeftInserts(PhreakAccumulateNode.java:164)
at org.drools.core.phreak.PhreakAccumulateNode.doNode(PhreakAccumulateNode.java:81)
at org.drools.core.phreak.RuleNetworkEvaluator.switchOnDoBetaNode(RuleNetworkEvaluator.java:524)
at org.drools.core.phreak.RuleNetworkEvaluator.evalBetaNode(RuleNetworkEvaluator.java:494)
at org.drools.core.phreak.RuleNetworkEvaluator.innerEval(RuleNetworkEvaluator.java:277)
at org.drools.core.phreak.RuleNetworkEvaluator.outerEval(RuleNetworkEvaluator.java:161)
at org.drools.core.phreak.RuleNetworkEvaluator.evaluateNetwork(RuleNetworkEvaluator.java:116)
at org.drools.core.phreak.RuleExecutor.reEvaluateNetwork(RuleExecutor.java:205)
at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:65)
at org.drools.core.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:936)
at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1183)
at org.drools.core.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:935)
at org.drools.core.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:909)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:233)
at org.optaplanner.core.impl.score.director.drools.DroolsScoreDirector.calculateScore(DroolsScoreDirector.java:98)
at org.optaplanner.core.impl.solver.scope.DefaultSolverScope.calculateScore(DefaultSolverScope.java:101)
at org.optaplanner.core.impl.bestsolution.BestSolutionRecaller.solvingStarted(BestSolutionRecaller.java:58)
at org.optaplanner.core.impl.solver.DefaultSolver.solvingStarted(DefaultSolver.java:177)
at org.optaplanner.core.impl.solver.DefaultSolver.solve(DefaultSolver.java:154)
at be.ocmwturnhout.permanenties.Main.main(Main.java:495)
Caused by: java.lang.NullPointerException
at be.ocmwturnhout.permanenties.solver.Rule_arbeidsbreuk654888368.accumulateExpression2(Rule_arbeidsbreuk654888368.java:23)
at be.ocmwturnhout.permanenties.solver.Rule_arbeidsbreuk654888368AccumulateExpression2Invoker.evaluate(Rule_arbeidsbreuk654888368AccumulateExpression2Invoker.java:25)
at org.drools.core.base.accumulators.JavaAccumulatorFunctionExecutor.accumulate(JavaAccumulatorFunctionExecutor.java:107)
at org.drools.core.rule.Accumulate.accumulate(Accumulate.java:173)
... 21 more
Any idea how I can solve this? Thanks.
Kind regards,
Nick
> Optaplanner rules NullPointerException
> --------------------------------------
>
> Key: DROOLS-349
> URL: https://issues.jboss.org/browse/DROOLS-349
> Project: Drools
> Issue Type: Bug
> Security Level: Public(Everyone can see)
> Affects Versions: 6.0.0.CR1
> Environment: Windows 7 64 bit, Optaplanner 6.0.0.CR1, Java 1.7.0_17-b02
> Reporter: Nick Snels
> Assignee: Mark Proctor
>
> I reported my issue with a Drools rule in Optaplanner on the Drools user forum (http://drools.46999.n3.nabble.com/Optaplanner-rules-NullPointerException-td4026875.html). I was adviced to create a JIRA ticket.
> =============
> I am trying to accomplish the following, a part time employee (eg 50%) needs to do only half the shifts a full time employee needs to do. I have created a rule, that
> 1. count number of shifts of certain shiftType
> 2. count number of shifts of a certain shiftType per employee
> 3. count the total number of "arbeidsbreuken" per employee and within a certain shiftType
> 4. do something with these numbers so that an part time employee only gets half the shifts assigned that a full time employee gets
> The complete rule is:
> {code}
> rule "arbeidsbreuk"
> when
> //System.out.println("arbeidsbreuk, Drools!");
> ShiftAssignment($employee : employee, $shiftType : shiftType)
> //count aantal shifts
> $assignmentTotal : Number() from accumulate(
> $assignment : ShiftAssignment(shiftType == $shiftType),
> count($assignment)
> )
>
> //count aantal shifts per medewerker
> $assignmentTotalEmployee : Number() from accumulate(
> $assignmentEmployee : ShiftAssignment(employee == $employee, shiftType == $shiftType),
> count($assignmentEmployee)
> )
>
> //count arbeidsbreuken van alle medewerkers
> $arbeidsbreukTotal : Number() from accumulate(
> //Employee($breuk : arbeidsbreuk),
> ShiftAssignment(employee == $employee, shiftType == $shiftType),
> sum($employee.getArbeidsbreuk())
> )
> $assignmentTotalEmployee.intValue())
> then
> System.out.println("Arbeidsbreuk drools: " + $employee.getArbeidsbreuk() + " - " + $assignmentTotal.intValue() + " - " + $assignmentTotalEmployee.intValue() + " - " + $arbeidsbreukTotal);
> scoreHolder.addSoftConstraintMatch(kcontext, -(Math.abs(($employee.getArbeidsbreuk() * $assignmentTotal.intValue()) - $assignmentTotalEmployee.intValue()) * (Math.abs(($employee.getArbeidsbreuk() * $assignmentTotal.intValue()) - $assignmentTotalEmployee.intValue()))) );
> end
> {code}
> I get the following error:
> {code}
> Exception in thread "main" org.drools.core.RuntimeDroolsException: java.lang.NullPointerException
> at org.drools.core.rule.Accumulate.accumulate(Accumulate.java:182)
> at org.drools.core.phreak.PhreakAccumulateNode.addMatch(PhreakAccumulateNode.java:756)
> at org.drools.core.phreak.PhreakAccumulateNode.doLeftInserts(PhreakAccumulateNode.java:164)
> at org.drools.core.phreak.PhreakAccumulateNode.doNode(PhreakAccumulateNode.java:81)
> at org.drools.core.phreak.RuleNetworkEvaluator.switchOnDoBetaNode(RuleNetworkEvaluator.java:524)
> at org.drools.core.phreak.RuleNetworkEvaluator.evalBetaNode(RuleNetworkEvaluator.java:494)
> at org.drools.core.phreak.RuleNetworkEvaluator.innerEval(RuleNetworkEvaluator.java:277)
> at org.drools.core.phreak.RuleNetworkEvaluator.outerEval(RuleNetworkEvaluator.java:161)
> at org.drools.core.phreak.RuleNetworkEvaluator.evaluateNetwork(RuleNetworkEvaluator.java:116)
> at org.drools.core.phreak.RuleExecutor.reEvaluateNetwork(RuleExecutor.java:205)
> at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:65)
> at org.drools.core.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:936)
> at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1183)
> at org.drools.core.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:935)
> at org.drools.core.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:909)
> at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:233)
> at org.optaplanner.core.impl.score.director.drools.DroolsScoreDirector.calculateScore(DroolsScoreDirector.java:98)
> at org.optaplanner.core.impl.solver.scope.DefaultSolverScope.calculateScore(DefaultSolverScope.java:101)
> at org.optaplanner.core.impl.bestsolution.BestSolutionRecaller.solvingStarted(BestSolutionRecaller.java:58)
> at org.optaplanner.core.impl.solver.DefaultSolver.solvingStarted(DefaultSolver.java:177)
> at org.optaplanner.core.impl.solver.DefaultSolver.solve(DefaultSolver.java:154)
> at be.ocmwturnhout.permanenties.Main.main(Main.java:495)
> Caused by: java.lang.NullPointerException
> at be.ocmwturnhout.permanenties.solver.Rule_arbeidsbreuk654888368.accumulateExpression2(Rule_arbeidsbreuk654888368.java:23)
> at be.ocmwturnhout.permanenties.solver.Rule_arbeidsbreuk654888368AccumulateExpression2Invoker.evaluate(Rule_arbeidsbreuk654888368AccumulateExpression2Invoker.java:25)
> at org.drools.core.base.accumulators.JavaAccumulatorFunctionExecutor.accumulate(JavaAccumulatorFunctionExecutor.java:107)
> at org.drools.core.rule.Accumulate.accumulate(Accumulate.java:173)
> ... 21 more
> {code}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the jboss-jira
mailing list