[rules-users] Optaplanner rules NullPointerException

ns nick.snels at ocmwturnhout.be
Thu Nov 21 08:40:46 EST 2013


Hi,

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



--
View this message in context: http://drools.46999.n3.nabble.com/Optaplanner-rules-NullPointerException-tp4026875.html
Sent from the Drools: User forum mailing list archive at Nabble.com.


More information about the rules-users mailing list