Optaplanner rules NullPointerException
by ns
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-...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 4 months
How to deal with doubles in Optaplanner drools rules
by ns
Hi,
I am having trouble dealing with doubles in the Optaplanner drools rule drl
file. See error message below.
Exception in thread "main" java.lang.IllegalStateException: There are errors
in the scoreDrl's:
Error Messages:
Message [id=1, level=ERROR,
path=optaplanner-kie-namespace//be/ocmwturnhout/permanenties/solver/permanentiesScoreRules.drl,
line=96, column=0
text=Rule Compilation error The method
addSoftConstraintMatch(RuleContext, int) in the type HardSoftScoreHolder is
not applicable for the arguments (RuleContext, double)]
I have the following then rule part:
scoreHolder.addSoftConstraintMatch(kcontext, -(10 *
Math.abs(($employee.getArbeidsbreuk() * $assignmentTotal.intValue()) -
$assignmentTotalEmployee.intValue())) * (10 *
Math.abs(($employee.getArbeidsbreuk().intValue() *
$assignmentTotal.intValue()) - $assignmentTotalEmployee.intValue())) );
$employee.getArbeidsbreuk() is a double.
Aren't doubles allowed or can I convert it? Thanks.
Kind regards,
Ncik
--
View this message in context: http://drools.46999.n3.nabble.com/How-to-deal-with-doubles-in-Optaplanner...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 4 months
Optaplanner order schedule performance problem
by Mohr, Michael
Hi,
I must find start and end times for orders on different equipment's in requirement of a stock.
What can I do better to get faster a solution.
I read the forum entries but it don't helps.
- Scheduling events with varying durations - corrupted score
- Time Slots vs Time Periods
Graphics and detail description in the pdf.
Domain model
@PlanningEntity
EquipmentAllocation has a Equipment
EquipmentAllocation has a Order
EquipmentAllocation has a TimeSlot
------------------------------------------------------
@PlanningVariable
Order
Attribute: quantity
------------------------------------------------------
TimeSlot
Attribute: startTime, endTime, duration, sequenceNumber
------------------------------------------------------
Material
Attribute: stock, minStock, maxStock
------------------------------------------------------
Material Demand has a TimeSlot
Attribute: quantity
------------------------------------------------------
Conditions:
- Order is executable on each equipment.
- Orders has different sizes.
- Order running time is depending of the material and the equipment.
- Gaps between orders are possible if there is no demand.
- Gaps between orders are possible when there is a equipment setup time.
- Parallel orders with same material on different equipment's are possible.
Target:
- Calculate start and endtims for an order.
- Start and endtime is precisely one minute (maximum five minutes if runtime is to long).
- Satisfy only the demand of a material.
- Good result in 5 minutes.
- No exceed min or max stock.
Plan data:
- Plan for 24 hours.
- Plan 35 orders (normal order time is 2 hours).
- Plan 5 demands with different materials (7 orders per demand).
- Plan 3 equipment's.
Problem:
- No result in 5 minutes.
- Concept with timeslots has to many possible order positions.
- No restrictions are possible to find the best solution.
Use a pillar swap to create the possible order positions on each equipment.
Use a pillar swap to lay the order over a lot of timeslots on a equipment.
Example:
- 1 order (with 2 hours)
- 1 equipment
- 24 hours planning time with 1 timeslot per minute
- Possible order positions = 22 * 60 = 1320 (on one equipment)
- Possible order positions = 1320 * 3 = 3960 (on three equipment)
- Possible order positions = 3960 * 35 = 138.600 (all orders on all equipment)
rule "Check order not allocate to less."
when
$f : Order( $quantity : quantity , $m : material )
$result : Number( (intValue > 0) && ( intValue < $quantity ) )
from accumulate(
EquipmentAllocation( order != null && order == $f , $sp : equipment.speedMap ),
sum($sp.get($m))
)
then
int hard = $result.intValue() - $quantity;
scoreHolder.addHardConstraintMatch(kcontext, hard );
end
rule "Check order not allocate to many."
when
$f : Order( $quantity : quantity , $m : material )
$result : Number( (intValue > 0) && ( intValue > $quantity ) )
from accumulate(
EquipmentAllocation(order != null && order == $f , $map : equipment.orderMap )
sum( $map.get( $f ))
)
then
int hard = $quantity - $result.intValue();
scoreHolder.addHardConstraintMatch(kcontext, hard );
end
rule "Check demand"
when
$m : Material( $stock : stock )
$t : TimeSlot( $sequence : sequence )
$sumDemand : Number( )
from accumulate (
Demand ( timeSlot.sequence <= $sequence , material == $m , $quantity : quantity )
sum( $quantity )
)
$sumAllocation : Number( ($stock + intValue - $sumDemand.intValue()) < 0 )
from accumulate (
EquipmentAllocation( (order != null && order.material == $m) , timeSlot.sequence <= $sequence , $sp : equipment.speedMap),
sum( $sp.get($m) )
)
then
scoreHolder.addHardConstraintMatch(kcontext, -1);
end
rule "Check min stock"
when
$m : Material( $stock : stock , $minStock : minStock, $maxStock : maxStock )
$t : TimeSlot( $sequenceT : sequence )
$sumDemand : Number( )
from accumulate (
Demand ( timeSlot.sequence <= $sequenceT , material == $m , $quantityDemand : quantity )
sum( $quantityDemand )
)
$sumAllocation : Number( ($stock + (intValue) - $sumDemand.intValue()) < $minStock )
from accumulate (
EquipmentAllocation( order != null , order.material == $m , timeSlot.sequence <= $sequenceT , $sp : equipment.speedMap ),
sum( $sp.get($m) )
)
then
scoreHolder.addHardConstraintMatch(kcontext, -1);
end
rule "Check max stock"
when
$t : TimeSlot( $sequence : sequence )
$m : Material( $stock : stock , $maxStock : maxStock )
$sumDemand : Number( )
from accumulate (
Demand ( timeSlot.sequence <= $sequence , material == $m, $quantityDemand : quantity)
sum( $quantityDemand )
)
$sumAllocation : Number( ($stock + intValue - $sumDemand.intValue()) > $maxStock )
from accumulate (
EquipmentAllocation( (order != null && order.material == $m) , timeSlot.sequence <= $sequence , $sp : equipment.speedMap ),
sum( $sp.get($m) )
)
then
scoreHolder.addHardConstraintMatch(kcontext, -1);
end
Gruß
Michael Mohr
Software Engineer
________________________________
CONFIDENTIALITY : This e-mail and any attachments are confidential and may be privileged. If you are not a named recipient, please notify the sender immediately and delete the e-mail from your system. You are not authorized to disclose the contents to another person, to use it for any purpose or store or copy the information in any medium.
12 years, 4 months
Date equal comparison fails - don't understand why
by Saloojee, Karim
Hi
I am comparing SimpleAccount( dateAccountOpened == "5-Feb-2011")
where dateAccountOpened is "Sat Feb 05 00:00:00 GMT+02:00 2011" (if you
call toString()). The equal comparator fails (==) but the greater than
comparator passes (>) which I don't understand.
I feel I am missing something obvious here, but I have no idea what it
is.
rule "Test date equality"
when
$acc : SimpleAccount( dateAccountOpened == "5-Feb-2011")
then
System.out.println("Expected and found an account opened
on 5-Feb-2011: " + $acc);
end
rule "Some dates are more equal than others"
when
$acc : SimpleAccount( dateAccountOpened > "5-Feb-2011")
then
System.out.println("Unexpected match: " +
$acc.getDateAccountOpened());
end
Regards,
Karim
To read FirstRand Bank's Disclaimer for this email click on the following address or copy into your Internet browser:
https://www.fnb.co.za/disclaimer.html
If you are unable to access the Disclaimer, send a blank e-mail to
firstrandbankdisclaimer(a)fnb.co.za and we will send you a copy of the Disclaimer.
12 years, 4 months