[rules-users] Ask for help with OptaPlanner

2013-11-01 Thread Xi Gong
Hi Folks,

I am new to OptaPlanner, so please forgive me if this is a stupid question.

I developed a project to solve a worker assignment problem based on
OptaPlanner. I have a java class Demand which has the information of
capacity needed for each shift.
I added it to the solution class as a problem fact, since it should never
be changed. Then I wrote rules saying that when the supply on that shift
can not satisfy the demand there will be a point loss.

The problem I met is that when stepping into local search phase, the solver
can not access to this class.

For instance, I have the following rule:
rule  test rule
when
$s : Shift($i : index)
$d : Demand(shift.getIndex() == $i)
then
System.out.println(Test rule fired.);
end

From console log I observed that at local search phase this rule was never
fired.
Does anyone have any thoughts on why this happened and how I should solve
this problem? I will appreciate your help.

Thanks,
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

[rules-users] Drools 5.5 divide by 0 exception

2013-11-01 Thread gboro54
I have rules like the following:

rule Add Baseline to Context if it does not exists exists or not greater
then 0
no-loop true
when
$context:Context($id:id,baselineParticipation==null || 
  
baselineParticipation.baselineRatio==null||baselineParticipation.baselineRatio==0)
then
modify($firm) {setBaselineParticipation(new 
BaselineParticipation($id,new
BigDecimal(0.00485)))};

end

rule Calculate Participation Ratio
no-loop true
when

$context:Context(consolidatdVolume!=null,consolidatdVolume.avgVolume0,
   
volumeAccumulations[total]!=null,volumeAccumulations[total]0,
   
$ratio:(volumeAccumulations[total]/consolidatdVolume.avgVolume))
then
ConcurrentMap calculatedRatios=$firm.getCalculatedRatios();
calculatedRatios.put(fparticipationRatio,new 
BigDecimal($ratio));
modify($firm){setCalculatedRatios(calculatedRatios)};
end

Despite the checks I get the following exception and any insight into why
would be great:

Exception executing consequence for rule Calculate Firm Participation
Ratio in com.nasdaq.rms.nq.status: java.lang.ArithmeticException: / by zero
Exception executing consequence for rule Calculate Firm Participation
Ratio in com.nasdaq.rms.nq.status: java.lang.ArithmeticException: / by zero
at
org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
at 
org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1297)
at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1221)
at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1456)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:710)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:674)
at
org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:230)
at
com.nasdaq.fq.rms.workflow.processor.rules.PerformanceStatusAssignmentProcessor.doWork(PerformanceStatusAssignmentProcessor.java:156)
at com.ften.ssr.workqueue.WorkItemRunnable.run(WorkItemRunnable.java:48)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
Caused by: java.lang.ArithmeticException: / by zero
at ConditionEvaluatorda6271cf5a744b6bbdb9c717cae2edb7.evaluate(Unknown
Source)
at
org.drools.rule.constraint.MvelConstraint.evaluate(MvelConstraint.java:200)
at
org.drools.rule.constraint.MvelConstraint.isAllowed(MvelConstraint.java:157)
at org.drools.reteoo.AlphaNode.modifyObject(AlphaNode.java:154)
at
org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateModifyObject(CompositeObjectSinkAdapter.java:507)
at
org.drools.reteoo.CompositeObjectSinkAdapter.propagateModifyObject(CompositeObjectSinkAdapter.java:432)
at org.drools.reteoo.AlphaNode.modifyObject(AlphaNode.java:157)
at
org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateModifyObject(CompositeObjectSinkAdapter.java:507)
at
org.drools.reteoo.CompositeObjectSinkAdapter.propagateModifyObject(CompositeObjectSinkAdapter.java:432)
at 
org.drools.reteoo.ObjectTypeNode.modifyObject(ObjectTypeNode.java:314)
at 
org.drools.reteoo.EntryPointNode.modifyObject(EntryPointNode.java:265)
at org.drools.common.NamedEntryPoint.update(NamedEntryPoint.java:483)
at org.drools.common.NamedEntryPoint.update(NamedEntryPoint.java:383)
at
org.drools.base.DefaultKnowledgeHelper.update(DefaultKnowledgeHelper.java:337)
at
com.nasdaq.rms.nq.status.Rule_Calculate_Firm_Participation_Ratio_cfb033f33c2b404fb2bff8e1b9af0175.defaultConsequence(Unknown
Source)
at
com.nasdaq.rms.nq.status.Rule_Calculate_Firm_Participation_Ratio_cfb033f33c2b404fb2bff8e1b9af0175DefaultConsequenceInvokerGenerated.evaluate(Unknown
Source)
at
com.nasdaq.rms.nq.status.Rule_Calculate_Firm_Participation_Ratio_cfb033f33c2b404fb2bff8e1b9af0175DefaultConsequenceInvoker.evaluate(Unknown
Source)
at 
org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1287)
... 10 more



--
View this message in context: 
http://drools.46999.n3.nabble.com/Drools-5-5-divide-by-0-exception-tp4026582.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Drools 5.5 divide by 0 exception

2013-11-01 Thread Stephen Masters
Divide by zero exceptions usually occur when you try to divide by zero.

So … first question … is consolidatdVolume.avgVolume ever zero?


On 1 Nov 2013, at 16:17, gboro54 gbor...@gmail.com wrote:

 I have rules like the following:
 
 rule Add Baseline to Context if it does not exists exists or not greater
 then 0
   no-loop true
   when
   $context:Context($id:id,baselineParticipation==null || 
 
 baselineParticipation.baselineRatio==null||baselineParticipation.baselineRatio==0)
   then
   modify($firm) {setBaselineParticipation(new 
 BaselineParticipation($id,new
 BigDecimal(0.00485)))};
   
 end
 
 rule Calculate Participation Ratio
   no-loop true
   when
   
 $context:Context(consolidatdVolume!=null,consolidatdVolume.avgVolume0,
  
 volumeAccumulations[total]!=null,volumeAccumulations[total]0,
  
 $ratio:(volumeAccumulations[total]/consolidatdVolume.avgVolume))
   then
   ConcurrentMap calculatedRatios=$firm.getCalculatedRatios();
   calculatedRatios.put(fparticipationRatio,new 
 BigDecimal($ratio));
   modify($firm){setCalculatedRatios(calculatedRatios)};
 end
 
 Despite the checks I get the following exception and any insight into why
 would be great:
 
 Exception executing consequence for rule Calculate Firm Participation
 Ratio in com.nasdaq.rms.nq.status: java.lang.ArithmeticException: / by zero
 Exception executing consequence for rule Calculate Firm Participation
 Ratio in com.nasdaq.rms.nq.status: java.lang.ArithmeticException: / by zero
   at
 org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
   at 
 org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1297)
   at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1221)
   at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1456)
   at
 org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:710)
   at
 org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:674)
   at
 org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:230)
   at
 com.nasdaq.fq.rms.workflow.processor.rules.PerformanceStatusAssignmentProcessor.doWork(PerformanceStatusAssignmentProcessor.java:156)
   at com.ften.ssr.workqueue.WorkItemRunnable.run(WorkItemRunnable.java:48)
   at
 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
   at
 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
   at java.lang.Thread.run(Thread.java:724)
 Caused by: java.lang.ArithmeticException: / by zero
   at ConditionEvaluatorda6271cf5a744b6bbdb9c717cae2edb7.evaluate(Unknown
 Source)
   at
 org.drools.rule.constraint.MvelConstraint.evaluate(MvelConstraint.java:200)
   at
 org.drools.rule.constraint.MvelConstraint.isAllowed(MvelConstraint.java:157)
   at org.drools.reteoo.AlphaNode.modifyObject(AlphaNode.java:154)
   at
 org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateModifyObject(CompositeObjectSinkAdapter.java:507)
   at
 org.drools.reteoo.CompositeObjectSinkAdapter.propagateModifyObject(CompositeObjectSinkAdapter.java:432)
   at org.drools.reteoo.AlphaNode.modifyObject(AlphaNode.java:157)
   at
 org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateModifyObject(CompositeObjectSinkAdapter.java:507)
   at
 org.drools.reteoo.CompositeObjectSinkAdapter.propagateModifyObject(CompositeObjectSinkAdapter.java:432)
   at 
 org.drools.reteoo.ObjectTypeNode.modifyObject(ObjectTypeNode.java:314)
   at 
 org.drools.reteoo.EntryPointNode.modifyObject(EntryPointNode.java:265)
   at org.drools.common.NamedEntryPoint.update(NamedEntryPoint.java:483)
   at org.drools.common.NamedEntryPoint.update(NamedEntryPoint.java:383)
   at
 org.drools.base.DefaultKnowledgeHelper.update(DefaultKnowledgeHelper.java:337)
   at
 com.nasdaq.rms.nq.status.Rule_Calculate_Firm_Participation_Ratio_cfb033f33c2b404fb2bff8e1b9af0175.defaultConsequence(Unknown
 Source)
   at
 com.nasdaq.rms.nq.status.Rule_Calculate_Firm_Participation_Ratio_cfb033f33c2b404fb2bff8e1b9af0175DefaultConsequenceInvokerGenerated.evaluate(Unknown
 Source)
   at
 com.nasdaq.rms.nq.status.Rule_Calculate_Firm_Participation_Ratio_cfb033f33c2b404fb2bff8e1b9af0175DefaultConsequenceInvoker.evaluate(Unknown
 Source)
   at 
 org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1287)
   ... 10 more
 
 
 
 --
 View this message in context: 
 http://drools.46999.n3.nabble.com/Drools-5-5-divide-by-0-exception-tp4026582.html
 Sent from the Drools: User forum mailing list archive at Nabble.com.
 ___
 rules-users mailing list
 

Re: [rules-users] Drools 5.5 divide by 0 exception

2013-11-01 Thread gboro54
So move the math to the rhs? Will that resolve the issues in your opinion? 



--
View this message in context: 
http://drools.46999.n3.nabble.com/Drools-5-5-divide-by-0-exception-tp4026582p4026586.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Drools 5.5 divide by 0 exception

2013-11-01 Thread gboro54
Could you expand upon why this is a poor practice? I assumed that if a part
of the pattern doesn't match the expression evaluation is terminated


laune wrote
 I can anticipate the answer where OP says that there is a constraint
 restricting argVolume to  0. However, I don't think that independent
 constraints such as we see them in this rule are evaluated as if they
 were in a single logical expression, with Java semantics.
 
 The seductive possibility of binding to a half-baked expression (i.e.,
 $ratio:(volumeAccumulations[total]/consolidatdVolume.avgVolume))
 should be discarded. This value can safely be computed on the RHS
 where the denominator's  value being !=0 is asserted.
 
 -W
 
 On 01/11/2013, Stephen Masters lt;

 stephen.masters@

 gt; wrote:
 Divide by zero exceptions usually occur when you try to divide by zero.

 So … first question … is consolidatdVolume.avgVolume ever zero?


 On 1 Nov 2013, at 16:17, gboro54 lt;

 gboro54@

 gt; wrote:

 I have rules like the following:

 rule Add Baseline to Context if it does not exists exists or not
 greater
 then 0
 no-loop true
 when
 $context:Context($id:id,baselineParticipation==null ||
 
 baselineParticipation.baselineRatio==null||baselineParticipation.baselineRatio==0)
 then
 modify($firm) {setBaselineParticipation(new
 BaselineParticipation($id,new
 BigDecimal(0.00485)))};
 
 end

 rule Calculate Participation Ratio
 no-loop true
 when
 
 $context:Context(consolidatdVolume!=null,consolidatdVolume.avgVolume0,
   
 volumeAccumulations[total]!=null,volumeAccumulations[total]0,
   
 $ratio:(volumeAccumulations[total]/consolidatdVolume.avgVolume))
 then
 ConcurrentMap calculatedRatios=$firm.getCalculatedRatios();
 calculatedRatios.put(fparticipationRatio,new 
 BigDecimal($ratio));
 modify($firm){setCalculatedRatios(calculatedRatios)};
 end

 Despite the checks I get the following exception and any insight into
 why
 would be great:

 Exception executing consequence for rule Calculate Firm Participation
 Ratio in com.nasdaq.rms.nq.status: java.lang.ArithmeticException: / by
 zero
 Exception executing consequence for rule Calculate Firm Participation
 Ratio in com.nasdaq.rms.nq.status: java.lang.ArithmeticException: / by
 zero
 at
 org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
 at
 org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1297)
 at
 org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1221)
 at
 org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1456)
 at
 org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:710)
 at
 org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:674)
 at
 org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:230)
 at
 com.nasdaq.fq.rms.workflow.processor.rules.PerformanceStatusAssignmentProcessor.doWork(PerformanceStatusAssignmentProcessor.java:156)
 at
 com.ften.ssr.workqueue.WorkItemRunnable.run(WorkItemRunnable.java:48)
 at
 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
 at
 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
 at java.lang.Thread.run(Thread.java:724)
 Caused by: java.lang.ArithmeticException: / by zero
 at ConditionEvaluatorda6271cf5a744b6bbdb9c717cae2edb7.evaluate(Unknown
 Source)
 at
 org.drools.rule.constraint.MvelConstraint.evaluate(MvelConstraint.java:200)
 at
 org.drools.rule.constraint.MvelConstraint.isAllowed(MvelConstraint.java:157)
 at org.drools.reteoo.AlphaNode.modifyObject(AlphaNode.java:154)
 at
 org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateModifyObject(CompositeObjectSinkAdapter.java:507)
 at
 org.drools.reteoo.CompositeObjectSinkAdapter.propagateModifyObject(CompositeObjectSinkAdapter.java:432)
 at org.drools.reteoo.AlphaNode.modifyObject(AlphaNode.java:157)
 at
 org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateModifyObject(CompositeObjectSinkAdapter.java:507)
 at
 org.drools.reteoo.CompositeObjectSinkAdapter.propagateModifyObject(CompositeObjectSinkAdapter.java:432)
 at
 org.drools.reteoo.ObjectTypeNode.modifyObject(ObjectTypeNode.java:314)
 at
 org.drools.reteoo.EntryPointNode.modifyObject(EntryPointNode.java:265)
 at org.drools.common.NamedEntryPoint.update(NamedEntryPoint.java:483)
 at org.drools.common.NamedEntryPoint.update(NamedEntryPoint.java:383)
 at
 org.drools.base.DefaultKnowledgeHelper.update(DefaultKnowledgeHelper.java:337)
 at
 com.nasdaq.rms.nq.status.Rule_Calculate_Firm_Participation_Ratio_cfb033f33c2b404fb2bff8e1b9af0175.defaultConsequence(Unknown
 Source)
 at
 

Re: [rules-users] Drools 5.5 divide by 0 exception

2013-11-01 Thread Wolfgang Laun
If the left hand side guarantees that a  0, a right hand side
expression b/a must be safe.
-W

On 01/11/2013, gboro54 gbor...@gmail.com wrote:
 So move the math to the rhs? Will that resolve the issues in your opinion?



 --
 View this message in context:
 http://drools.46999.n3.nabble.com/Drools-5-5-divide-by-0-exception-tp4026582p4026586.html
 Sent from the Drools: User forum mailing list archive at Nabble.com.
 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Drools 5.5 divide by 0 exception

2013-11-01 Thread Stephen Masters
Given that you don’t seem to using the result as a constraint, then I can’t see 
any benefit to it being on the LHS. So yes, It would be better on the RHS.

Steve


On 1 Nov 2013, at 17:58, Wolfgang Laun wolfgang.l...@gmail.com wrote:

 I can anticipate the answer where OP says that there is a constraint
 restricting argVolume to  0. However, I don't think that independent
 constraints such as we see them in this rule are evaluated as if they
 were in a single logical expression, with Java semantics.
 
 The seductive possibility of binding to a half-baked expression (i.e.,
 $ratio:(volumeAccumulations[total]/consolidatdVolume.avgVolume))
 should be discarded. This value can safely be computed on the RHS
 where the denominator's  value being !=0 is asserted.
 
 -W
 
 On 01/11/2013, Stephen Masters stephen.mast...@me.com wrote:
 Divide by zero exceptions usually occur when you try to divide by zero.
 
 So … first question … is consolidatdVolume.avgVolume ever zero?
 
 
 On 1 Nov 2013, at 16:17, gboro54 gbor...@gmail.com wrote:
 
 I have rules like the following:
 
 rule Add Baseline to Context if it does not exists exists or not greater
 then 0
 no-loop true
 when
 $context:Context($id:id,baselineParticipation==null ||
 
 baselineParticipation.baselineRatio==null||baselineParticipation.baselineRatio==0)
 then
 modify($firm) {setBaselineParticipation(new
 BaselineParticipation($id,new
 BigDecimal(0.00485)))};
 
 end
 
 rule Calculate Participation Ratio
 no-loop true
 when
 
 $context:Context(consolidatdVolume!=null,consolidatdVolume.avgVolume0,

 volumeAccumulations[total]!=null,volumeAccumulations[total]0,

 $ratio:(volumeAccumulations[total]/consolidatdVolume.avgVolume))
 then
 ConcurrentMap calculatedRatios=$firm.getCalculatedRatios();
 calculatedRatios.put(fparticipationRatio,new 
 BigDecimal($ratio));
 modify($firm){setCalculatedRatios(calculatedRatios)};
 end
 
 Despite the checks I get the following exception and any insight into why
 would be great:
 
 Exception executing consequence for rule Calculate Firm Participation
 Ratio in com.nasdaq.rms.nq.status: java.lang.ArithmeticException: / by
 zero
 Exception executing consequence for rule Calculate Firm Participation
 Ratio in com.nasdaq.rms.nq.status: java.lang.ArithmeticException: / by
 zero
 at
 org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
 at
 org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1297)
 at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1221)
 at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1456)
 at
 org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:710)
 at
 org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:674)
 at
 org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:230)
 at
 com.nasdaq.fq.rms.workflow.processor.rules.PerformanceStatusAssignmentProcessor.doWork(PerformanceStatusAssignmentProcessor.java:156)
 at com.ften.ssr.workqueue.WorkItemRunnable.run(WorkItemRunnable.java:48)
 at
 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
 at
 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
 at java.lang.Thread.run(Thread.java:724)
 Caused by: java.lang.ArithmeticException: / by zero
 at ConditionEvaluatorda6271cf5a744b6bbdb9c717cae2edb7.evaluate(Unknown
 Source)
 at
 org.drools.rule.constraint.MvelConstraint.evaluate(MvelConstraint.java:200)
 at
 org.drools.rule.constraint.MvelConstraint.isAllowed(MvelConstraint.java:157)
 at org.drools.reteoo.AlphaNode.modifyObject(AlphaNode.java:154)
 at
 org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateModifyObject(CompositeObjectSinkAdapter.java:507)
 at
 org.drools.reteoo.CompositeObjectSinkAdapter.propagateModifyObject(CompositeObjectSinkAdapter.java:432)
 at org.drools.reteoo.AlphaNode.modifyObject(AlphaNode.java:157)
 at
 org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateModifyObject(CompositeObjectSinkAdapter.java:507)
 at
 org.drools.reteoo.CompositeObjectSinkAdapter.propagateModifyObject(CompositeObjectSinkAdapter.java:432)
 at
 org.drools.reteoo.ObjectTypeNode.modifyObject(ObjectTypeNode.java:314)
 at
 org.drools.reteoo.EntryPointNode.modifyObject(EntryPointNode.java:265)
 at org.drools.common.NamedEntryPoint.update(NamedEntryPoint.java:483)
 at org.drools.common.NamedEntryPoint.update(NamedEntryPoint.java:383)
 at
 org.drools.base.DefaultKnowledgeHelper.update(DefaultKnowledgeHelper.java:337)
 at
 

Re: [rules-users] Drools 5.5 divide by 0 exception

2013-11-01 Thread gboro54
I changed the rules to the following so I will test and see:

rule Add Baseline to Context if it does not exists exists or not greater
then 0 
no-loop true 
when 
$context:Context($id:id,baselineParticipation==null || 
  
baselineParticipation.baselineRatio==null||baselineParticipation.baselineRatio==0)
 
then 
modify($firm) {setBaselineParticipation(new
BaselineParticipation($id,new BigDecimal(0.00485)))}; 

end 

rule Calculate Participation Ratio 
no-loop true 
when 
   
$context:Context(consolidatdVolume!=null,consolidatdVolume.avgVolume!=0, 
  
volumeAccumulations[total]!=null,volumeAccumulations[total]!=0, 
  
$total:volumeAccumulations[total],$avg:consolidatdVolume.avgVolume) 
then 
ConcurrentMap calculatedRatios=$firm.getCalculatedRatios(); 
calculatedRatios.put(participationRatio,new
BigDecimal($total/$avg)); 
modify($firm){setCalculatedRatios(calculatedRatios)}; 
end 



--
View this message in context: 
http://drools.46999.n3.nabble.com/Drools-5-5-divide-by-0-exception-tp4026582p4026589.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Drools 5.5 divide by 0 exception

2013-11-01 Thread gboro54
Agreed. In this case it is possible to move to the RHS...but I have to ask
what if I need to use the math as part of a constraint. Is it not safe to
assume the divisor is 0 even if I do the check? That seems like an issue as
I do have cases which this will be required


Stephen Masters wrote
 Given that you don’t seem to using the result as a constraint, then I
 can’t see any benefit to it being on the LHS. So yes, It would be better
 on the RHS.
 
 Steve
 
 
 On 1 Nov 2013, at 17:58, Wolfgang Laun lt;

 wolfgang.laun@

 gt; wrote:
 
 I can anticipate the answer where OP says that there is a constraint
 restricting argVolume to  0. However, I don't think that independent
 constraints such as we see them in this rule are evaluated as if they
 were in a single logical expression, with Java semantics.
 
 The seductive possibility of binding to a half-baked expression (i.e.,
 $ratio:(volumeAccumulations[total]/consolidatdVolume.avgVolume))
 should be discarded. This value can safely be computed on the RHS
 where the denominator's  value being !=0 is asserted.
 
 -W
 
 On 01/11/2013, Stephen Masters lt;

 stephen.masters@

 gt; wrote:
 Divide by zero exceptions usually occur when you try to divide by zero.
 
 So … first question … is consolidatdVolume.avgVolume ever zero?
 
 
 On 1 Nov 2013, at 16:17, gboro54 lt;

 gboro54@

 gt; wrote:
 
 I have rules like the following:
 
 rule Add Baseline to Context if it does not exists exists or not
 greater
 then 0
no-loop true
when
$context:Context($id:id,baselineParticipation==null ||

 baselineParticipation.baselineRatio==null||baselineParticipation.baselineRatio==0)
then
modify($firm) {setBaselineParticipation(new
 BaselineParticipation($id,new
 BigDecimal(0.00485)))};

 end
 
 rule Calculate Participation Ratio
no-loop true
when

 $context:Context(consolidatdVolume!=null,consolidatdVolume.avgVolume0,
  
 volumeAccumulations[total]!=null,volumeAccumulations[total]0,
  
 $ratio:(volumeAccumulations[total]/consolidatdVolume.avgVolume))
then
ConcurrentMap calculatedRatios=$firm.getCalculatedRatios();
calculatedRatios.put(fparticipationRatio,new 
 BigDecimal($ratio));
modify($firm){setCalculatedRatios(calculatedRatios)};
 end
 
 Despite the checks I get the following exception and any insight into
 why
 would be great:
 
 Exception executing consequence for rule Calculate Firm Participation
 Ratio in com.nasdaq.rms.nq.status: java.lang.ArithmeticException: / by
 zero
 Exception executing consequence for rule Calculate Firm Participation
 Ratio in com.nasdaq.rms.nq.status: java.lang.ArithmeticException: / by
 zero
at
 org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
at
 org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1297)
at
 org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1221)
at
 org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1456)
at
 org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:710)
at
 org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:674)
at
 org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:230)
at
 com.nasdaq.fq.rms.workflow.processor.rules.PerformanceStatusAssignmentProcessor.doWork(PerformanceStatusAssignmentProcessor.java:156)
at
 com.ften.ssr.workqueue.WorkItemRunnable.run(WorkItemRunnable.java:48)
at
 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at
 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
 Caused by: java.lang.ArithmeticException: / by zero
at ConditionEvaluatorda6271cf5a744b6bbdb9c717cae2edb7.evaluate(Unknown
 Source)
at
 org.drools.rule.constraint.MvelConstraint.evaluate(MvelConstraint.java:200)
at
 org.drools.rule.constraint.MvelConstraint.isAllowed(MvelConstraint.java:157)
at org.drools.reteoo.AlphaNode.modifyObject(AlphaNode.java:154)
at
 org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateModifyObject(CompositeObjectSinkAdapter.java:507)
at
 org.drools.reteoo.CompositeObjectSinkAdapter.propagateModifyObject(CompositeObjectSinkAdapter.java:432)
at org.drools.reteoo.AlphaNode.modifyObject(AlphaNode.java:157)
at
 org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateModifyObject(CompositeObjectSinkAdapter.java:507)
at
 org.drools.reteoo.CompositeObjectSinkAdapter.propagateModifyObject(CompositeObjectSinkAdapter.java:432)
at
 org.drools.reteoo.ObjectTypeNode.modifyObject(ObjectTypeNode.java:314)
at
 org.drools.reteoo.EntryPointNode.modifyObject(EntryPointNode.java:265)
at 

Re: [rules-users] Drools 5.5 divide by 0 exception

2013-11-01 Thread Wolfgang Laun
I haven't read a statement yet that says that, in Drools, LHS terms,
separated by a comma (!) must be executed in the order they are
written, or that the C/Java semantics for logical expression
evaluation is applied.

-W


On 01/11/2013, gboro54 gbor...@gmail.com wrote:
 Could you expand upon why this is a poor practice? I assumed that if a part
 of the pattern doesn't match the expression evaluation is terminated


 laune wrote
 I can anticipate the answer where OP says that there is a constraint
 restricting argVolume to  0. However, I don't think that independent
 constraints such as we see them in this rule are evaluated as if they
 were in a single logical expression, with Java semantics.

 The seductive possibility of binding to a half-baked expression (i.e.,
 $ratio:(volumeAccumulations[total]/consolidatdVolume.avgVolume))
 should be discarded. This value can safely be computed on the RHS
 where the denominator's  value being !=0 is asserted.

 -W

 On 01/11/2013, Stephen Masters lt;

 stephen.masters@

 gt; wrote:
 Divide by zero exceptions usually occur when you try to divide by zero.

 So … first question … is consolidatdVolume.avgVolume ever zero?


 On 1 Nov 2013, at 16:17, gboro54 lt;

 gboro54@

 gt; wrote:

 I have rules like the following:

 rule Add Baseline to Context if it does not exists exists or not
 greater
 then 0
no-loop true
when
$context:Context($id:id,baselineParticipation==null ||

 baselineParticipation.baselineRatio==null||baselineParticipation.baselineRatio==0)
then
modify($firm) {setBaselineParticipation(new
 BaselineParticipation($id,new
 BigDecimal(0.00485)))};

 end

 rule Calculate Participation Ratio
no-loop true
when

 $context:Context(consolidatdVolume!=null,consolidatdVolume.avgVolume0,

 volumeAccumulations[total]!=null,volumeAccumulations[total]0,

 $ratio:(volumeAccumulations[total]/consolidatdVolume.avgVolume))
then
ConcurrentMap calculatedRatios=$firm.getCalculatedRatios();
calculatedRatios.put(fparticipationRatio,new 
 BigDecimal($ratio));
modify($firm){setCalculatedRatios(calculatedRatios)};
 end

 Despite the checks I get the following exception and any insight into
 why
 would be great:

 Exception executing consequence for rule Calculate Firm Participation
 Ratio in com.nasdaq.rms.nq.status: java.lang.ArithmeticException: / by
 zero
 Exception executing consequence for rule Calculate Firm Participation
 Ratio in com.nasdaq.rms.nq.status: java.lang.ArithmeticException: / by
 zero
at
 org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
at
 org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1297)
at
 org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1221)
at
 org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1456)
at
 org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:710)
at
 org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:674)
at
 org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:230)
at
 com.nasdaq.fq.rms.workflow.processor.rules.PerformanceStatusAssignmentProcessor.doWork(PerformanceStatusAssignmentProcessor.java:156)
at
 com.ften.ssr.workqueue.WorkItemRunnable.run(WorkItemRunnable.java:48)
at
 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at
 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
 Caused by: java.lang.ArithmeticException: / by zero
at ConditionEvaluatorda6271cf5a744b6bbdb9c717cae2edb7.evaluate(Unknown
 Source)
at
 org.drools.rule.constraint.MvelConstraint.evaluate(MvelConstraint.java:200)
at
 org.drools.rule.constraint.MvelConstraint.isAllowed(MvelConstraint.java:157)
at org.drools.reteoo.AlphaNode.modifyObject(AlphaNode.java:154)
at
 org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateModifyObject(CompositeObjectSinkAdapter.java:507)
at
 org.drools.reteoo.CompositeObjectSinkAdapter.propagateModifyObject(CompositeObjectSinkAdapter.java:432)
at org.drools.reteoo.AlphaNode.modifyObject(AlphaNode.java:157)
at
 org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateModifyObject(CompositeObjectSinkAdapter.java:507)
at
 org.drools.reteoo.CompositeObjectSinkAdapter.propagateModifyObject(CompositeObjectSinkAdapter.java:432)
at
 org.drools.reteoo.ObjectTypeNode.modifyObject(ObjectTypeNode.java:314)
at
 org.drools.reteoo.EntryPointNode.modifyObject(EntryPointNode.java:265)
at org.drools.common.NamedEntryPoint.update(NamedEntryPoint.java:483)
at org.drools.common.NamedEntryPoint.update(NamedEntryPoint.java:383)
at
 

Re: [rules-users] Drools 5.5 divide by 0 exception

2013-11-01 Thread gboro54
I made an assumption(thus why I am asking) for future cases I will use the 
separator to handle such cases as I would assume saying something like this
would work:

Object(a0  b0  a/b  100)


laune wrote
 I haven't read a statement yet that says that, in Drools, LHS terms,
 separated by a comma (!) must be executed in the order they are
 written, or that the C/Java semantics for logical expression
 evaluation is applied.
 
 -W
 
 
 On 01/11/2013, gboro54 lt;

 gboro54@

 gt; wrote:
 Could you expand upon why this is a poor practice? I assumed that if a
 part
 of the pattern doesn't match the expression evaluation is terminated


 laune wrote
 I can anticipate the answer where OP says that there is a constraint
 restricting argVolume to  0. However, I don't think that independent
 constraints such as we see them in this rule are evaluated as if they
 were in a single logical expression, with Java semantics.

 The seductive possibility of binding to a half-baked expression (i.e.,
 $ratio:(volumeAccumulations[total]/consolidatdVolume.avgVolume))
 should be discarded. This value can safely be computed on the RHS
 where the denominator's  value being !=0 is asserted.

 -W

 On 01/11/2013, Stephen Masters lt;

 stephen.masters@

 gt; wrote:
 Divide by zero exceptions usually occur when you try to divide by zero.

 So … first question … is consolidatdVolume.avgVolume ever zero?


 On 1 Nov 2013, at 16:17, gboro54 lt;

 gboro54@

 gt; wrote:

 I have rules like the following:

 rule Add Baseline to Context if it does not exists exists or not
 greater
 then 0
   no-loop true
   when
   $context:Context($id:id,baselineParticipation==null ||
   
 baselineParticipation.baselineRatio==null||baselineParticipation.baselineRatio==0)
   then
   modify($firm) {setBaselineParticipation(new
 BaselineParticipation($id,new
 BigDecimal(0.00485)))};
   
 end

 rule Calculate Participation Ratio
   no-loop true
   when
   
 $context:Context(consolidatdVolume!=null,consolidatdVolume.avgVolume0,
   
 volumeAccumulations[total]!=null,volumeAccumulations[total]0,
   
 $ratio:(volumeAccumulations[total]/consolidatdVolume.avgVolume))
   then
   ConcurrentMap calculatedRatios=$firm.getCalculatedRatios();
   calculatedRatios.put(fparticipationRatio,new 
 BigDecimal($ratio));
   modify($firm){setCalculatedRatios(calculatedRatios)};
 end

 Despite the checks I get the following exception and any insight into
 why
 would be great:

 Exception executing consequence for rule Calculate Firm Participation
 Ratio in com.nasdaq.rms.nq.status: java.lang.ArithmeticException: /
 by
 zero
 Exception executing consequence for rule Calculate Firm Participation
 Ratio in com.nasdaq.rms.nq.status: java.lang.ArithmeticException: /
 by
 zero
   at
 org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
   at
 org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1297)
   at
 org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1221)
   at
 org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1456)
   at
 org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:710)
   at
 org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:674)
   at
 org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:230)
   at
 com.nasdaq.fq.rms.workflow.processor.rules.PerformanceStatusAssignmentProcessor.doWork(PerformanceStatusAssignmentProcessor.java:156)
   at
 com.ften.ssr.workqueue.WorkItemRunnable.run(WorkItemRunnable.java:48)
   at
 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
   at
 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
   at java.lang.Thread.run(Thread.java:724)
 Caused by: java.lang.ArithmeticException: / by zero
   at
 ConditionEvaluatorda6271cf5a744b6bbdb9c717cae2edb7.evaluate(Unknown
 Source)
   at
 org.drools.rule.constraint.MvelConstraint.evaluate(MvelConstraint.java:200)
   at
 org.drools.rule.constraint.MvelConstraint.isAllowed(MvelConstraint.java:157)
   at org.drools.reteoo.AlphaNode.modifyObject(AlphaNode.java:154)
   at
 org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateModifyObject(CompositeObjectSinkAdapter.java:507)
   at
 org.drools.reteoo.CompositeObjectSinkAdapter.propagateModifyObject(CompositeObjectSinkAdapter.java:432)
   at org.drools.reteoo.AlphaNode.modifyObject(AlphaNode.java:157)
   at
 org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateModifyObject(CompositeObjectSinkAdapter.java:507)
   at
 org.drools.reteoo.CompositeObjectSinkAdapter.propagateModifyObject(CompositeObjectSinkAdapter.java:432)
   at
 org.drools.reteoo.ObjectTypeNode.modifyObject(ObjectTypeNode.java:314)
   at
 org.drools.reteoo.EntryPointNode.modifyObject(EntryPointNode.java:265)
   at 

Re: [rules-users] Drools 5.5 divide by 0 exception

2013-11-01 Thread gboro54
Another question(on error interpretation) the stack trace seems to indicate
an issue with the consequence and not the condition. Should it be assumed
that seeing such errors could indicate an issue on either side of the rule?  



--
View this message in context: 
http://drools.46999.n3.nabble.com/Drools-5-5-divide-by-0-exception-tp4026582p4026594.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Drools 5.5 divide by 0 exception

2013-11-01 Thread Davide Sottara
Am I wrong or these are not the (only) rules that are being run?

1) The exception is thrown as the consequence of a rule called

com.nasdaq.rms.nq.status.Rule_Calculate_Firm_Participation_Ratio_cfb033f33c2b404fb2bff8e1b9af0175

Rule Calculate Firm Participation Ratio, which is not shown.

2) The Rule Add baseline to context... modifies a $firm which is not
bound anywhere
in that rule..

3) Looking at the stack trace, the consequence happens in a MVEL
Constraint, which
is in an Alpha Node immediately after an ObjectTypeNode. This usually
means that
the failing constraint is the first in the pattern, which is not the
case in your
Calculate  Participation Ratio.
(to Wolfgang's point: it is not mandatory, since and is commutative,
but this is what
usually happens in practice)

You also have multiple threads... is that avgVolume computed using an
accumulate
somewhere? I wonder if there are critical races.

On 11/01/2013 11:17 AM, gboro54 wrote:
 Agreed. In this case it is possible to move to the RHS...but I have to ask
 what if I need to use the math as part of a constraint. Is it not safe to
 assume the divisor is 0 even if I do the check? That seems like an issue as
 I do have cases which this will be required


 Stephen Masters wrote
 Given that you don’t seem to using the result as a constraint, then I
 can’t see any benefit to it being on the LHS. So yes, It would be better
 on the RHS.

 Steve


 On 1 Nov 2013, at 17:58, Wolfgang Laun lt;
 wolfgang.laun@
 gt; wrote:

 I can anticipate the answer where OP says that there is a constraint
 restricting argVolume to  0. However, I don't think that independent
 constraints such as we see them in this rule are evaluated as if they
 were in a single logical expression, with Java semantics.

 The seductive possibility of binding to a half-baked expression (i.e.,
 $ratio:(volumeAccumulations[total]/consolidatdVolume.avgVolume))
 should be discarded. This value can safely be computed on the RHS
 where the denominator's  value being !=0 is asserted.

 -W

 On 01/11/2013, Stephen Masters lt;
 stephen.masters@
 gt; wrote:
 Divide by zero exceptions usually occur when you try to divide by zero.

 So … first question … is consolidatdVolume.avgVolume ever zero?


 On 1 Nov 2013, at 16:17, gboro54 lt;
 gboro54@
 gt; wrote:
 I have rules like the following:

 rule Add Baseline to Context if it does not exists exists or not
 greater
 then 0
   no-loop true
   when
   $context:Context($id:id,baselineParticipation==null ||
   
 baselineParticipation.baselineRatio==null||baselineParticipation.baselineRatio==0)
   then
   modify($firm) {setBaselineParticipation(new
 BaselineParticipation($id,new
 BigDecimal(0.00485)))};
   
 end

 rule Calculate Participation Ratio
   no-loop true
   when
   
 $context:Context(consolidatdVolume!=null,consolidatdVolume.avgVolume0,
 
 volumeAccumulations[total]!=null,volumeAccumulations[total]0,
 
 $ratio:(volumeAccumulations[total]/consolidatdVolume.avgVolume))
   then
   ConcurrentMap calculatedRatios=$firm.getCalculatedRatios();
   calculatedRatios.put(fparticipationRatio,new 
 BigDecimal($ratio));
   modify($firm){setCalculatedRatios(calculatedRatios)};
 end

 Despite the checks I get the following exception and any insight into
 why
 would be great:

 Exception executing consequence for rule Calculate Firm Participation
 Ratio in com.nasdaq.rms.nq.status: java.lang.ArithmeticException: / by
 zero
 Exception executing consequence for rule Calculate Firm Participation
 Ratio in com.nasdaq.rms.nq.status: java.lang.ArithmeticException: / by
 zero
   at
 org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
   at
 org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1297)
   at
 org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1221)
   at
 org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1456)
   at
 org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:710)
   at
 org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:674)
   at
 org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:230)
   at
 com.nasdaq.fq.rms.workflow.processor.rules.PerformanceStatusAssignmentProcessor.doWork(PerformanceStatusAssignmentProcessor.java:156)
   at
 com.ften.ssr.workqueue.WorkItemRunnable.run(WorkItemRunnable.java:48)
   at
 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
   at
 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
   at java.lang.Thread.run(Thread.java:724)
 Caused by: java.lang.ArithmeticException: / by zero
   at ConditionEvaluatorda6271cf5a744b6bbdb9c717cae2edb7.evaluate(Unknown
 Source)
   at
 

[rules-users] Optaplanner - Issue with real-time, chained and shadow variables

2013-11-01 Thread Juan Ignacio Barisich
Hi everybody
I am using optaplanner in real-time style. My application domain is similar
to the Vehicle Routing example (
http://docs.jboss.org/drools/release/6.0.0.CR5/optaplanner-docs/html_single/index.html#vehicleRouting).
I mean, I am using chained variables and shadow variables. I have a problem
while trying to remove a fact (an entity), via a ProblemFactChange:

java.lang.IllegalArgumentException: The entity instance (...) was never
added to this ScoreDirector. Usually the cause is that that specific
instance was not in your Solution's entities.

The fact removing that I made is like:

solver.addProblemFactChange(new ProblemFactChange() {

@Override
public void doChange(ScoreDirector scoreDirector) {
...
scoreDirector.beforeEntityRemoved(toRemove);
workingSolution.getCustomerList().remove(toRemove);
scoreDirector.afterEntityRemoved(toRemove);
}
});

I think the problem is there. Do you know what I'm doing wrong?
I have attached a test case based on the Vehicle Routing. To run it, just
put that file into the
optaplanner-distribution-6.0.0.CR5/examples/sources/src/test/java/org/optaplanner/examples/vehiclerouting/app/
directory.

http://drools.46999.n3.nabble.com/file/n4017760/serverlog.zipI'd
appreciate any ideas on how to resolve this.
Best regards,

Juan Ignacio Barisich
package org.optaplanner.examples.vehiclerouting.app;

import java.io.File;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.junit.Before;
import org.junit.Test;
import org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScore;
import org.optaplanner.core.api.solver.Solver;
import org.optaplanner.core.api.solver.SolverFactory;
import org.optaplanner.core.config.score.director.ScoreDirectorFactoryConfig;
import org.optaplanner.core.config.solver.EnvironmentMode;
import org.optaplanner.core.config.solver.SolverConfig;
import org.optaplanner.core.config.solver.XmlSolverFactory;
import org.optaplanner.core.config.termination.TerminationConfig;
import org.optaplanner.core.impl.score.director.ScoreDirector;
import org.optaplanner.core.impl.solution.Solution;
import org.optaplanner.core.impl.solver.ProblemFactChange;
import org.optaplanner.examples.common.persistence.SolutionDao;
import org.optaplanner.examples.vehiclerouting.domain.Customer;
import org.optaplanner.examples.vehiclerouting.domain.timewindowed.TimeWindowedVehicleRoutingSolution;
import org.optaplanner.examples.vehiclerouting.persistence.VehicleRoutingDao;
import org.optaplanner.examples.vehiclerouting.solver.score.VehicleRoutingSimpleScoreCalculator;

/**
 * Test of bug while removing an entity on real-time, chained with shadow
 * variables entities.
 * 
 * @author juan.baris...@gmail.com
 */
public class VehicleRoutingBugTest {

	protected SolutionDao solutionDao;
	private ExecutorService executor = Executors.newFixedThreadPool(1);
	protected File unsolvedDataFile;

	protected SolverFactory buildSolverFactory() {
		SolverFactory solverFactory = new XmlSolverFactory(
createSolverConfigResource());
		TerminationConfig terminationConfig = new TerminationConfig();
		solverFactory.getSolverConfig().setTerminationConfig(terminationConfig);
		return solverFactory;
	}

	protected ScoreDirectorFactoryConfig createOverwritingAssertionScoreDirectorFactory() {
		ScoreDirectorFactoryConfig assertionScoreDirectorFactoryConfig = new ScoreDirectorFactoryConfig();
		assertionScoreDirectorFactoryConfig
.setSimpleScoreCalculatorClass(VehicleRoutingSimpleScoreCalculator.class);
		return assertionScoreDirectorFactoryConfig;
	}

	protected SolutionDao createSolutionDao() {
		return new VehicleRoutingDao();
	}

	protected String createSolverConfigResource() {
		return /org/optaplanner/examples/vehiclerouting/solver/vehicleRoutingSolverConfig.xml;
	}

	private void removeFirstEntity(final Solver solver) {
		solver.addProblemFactChange(new ProblemFactChange() {

			@Override
			public void doChange(ScoreDirector scoreDirector) {
TimeWindowedVehicleRoutingSolution workingSolution = (TimeWindowedVehicleRoutingSolution) scoreDirector
		.getWorkingSolution();
// e.g., pick the first entity
final Customer toRemove = workingSolution.getCustomerList()
		.get(0);
// FIXME here is the problem
scoreDirector.beforeEntityRemoved(toRemove);
workingSolution.getCustomerList().remove(toRemove);
scoreDirector.afterEntityRemoved(toRemove);
			}
		});
	}

	@Before
	public void setUp() {
		solutionDao = createSolutionDao();
	}

	@Test
	public void testBug() throws InterruptedException {
		SolverFactory solverFactory = buildSolverFactory();
		@SuppressWarnings(unchecked)
		final SolutionHardSoftScore planningProblem = solutionDao
.readSolution(new File(
		data/vehiclerouting/unsolved/cvrptw-100customers-A.xml));
		solverFactory.getSolverConfig().getTerminationConfig()
.setMaximumMinutesSpend(2L);
		

Re: [rules-users] Drools 5.5 divide by 0 exception

2013-11-01 Thread gboro54
$firm should be $context...To post the rule in the public sphere I had to
modify some variables(legal company issues :-) ). The same goes for the rule
name(my replacement of text is not very good).

I understand Wolfgang's point...I just made a poor assumption(something as
someone who has used drools for several years I shouldn't have done...every
once and a while I guess I get a brain fart)


Davide Sottara wrote
 Am I wrong or these are not the (only) rules that are being run?
 
 1) The exception is thrown as the consequence of a rule called
 
 com.nasdaq.rms.nq.status.Rule_Calculate_Firm_Participation_Ratio_cfb033f33c2b404fb2bff8e1b9af0175
 
 Rule Calculate Firm Participation Ratio, which is not shown.
 
 2) The Rule Add baseline to context... modifies a $firm which is not
 bound anywhere
 in that rule..
 
 3) Looking at the stack trace, the consequence happens in a MVEL
 Constraint, which
 is in an Alpha Node immediately after an ObjectTypeNode. This usually
 means that
 the failing constraint is the first in the pattern, which is not the
 case in your
 Calculate  Participation Ratio.
 (to Wolfgang's point: it is not mandatory, since and is commutative,
 but this is what
 usually happens in practice)
 
 You also have multiple threads... is that avgVolume computed using an
 accumulate
 somewhere? I wonder if there are critical races.
 
 On 11/01/2013 11:17 AM, gboro54 wrote:
 Agreed. In this case it is possible to move to the RHS...but I have to
 ask
 what if I need to use the math as part of a constraint. Is it not safe to
 assume the divisor is 0 even if I do the check? That seems like an issue
 as
 I do have cases which this will be required


 Stephen Masters wrote
 Given that you don’t seem to using the result as a constraint, then I
 can’t see any benefit to it being on the LHS. So yes, It would be better
 on the RHS.

 Steve


 On 1 Nov 2013, at 17:58, Wolfgang Laun lt;
 wolfgang.laun@
 gt; wrote:

 I can anticipate the answer where OP says that there is a constraint
 restricting argVolume to  0. However, I don't think that independent
 constraints such as we see them in this rule are evaluated as if they
 were in a single logical expression, with Java semantics.

 The seductive possibility of binding to a half-baked expression (i.e.,
 $ratio:(volumeAccumulations[total]/consolidatdVolume.avgVolume))
 should be discarded. This value can safely be computed on the RHS
 where the denominator's  value being !=0 is asserted.

 -W

 On 01/11/2013, Stephen Masters lt;
 stephen.masters@
 gt; wrote:
 Divide by zero exceptions usually occur when you try to divide by
 zero.

 So … first question … is consolidatdVolume.avgVolume ever zero?


 On 1 Nov 2013, at 16:17, gboro54 lt;
 gboro54@
 gt; wrote:
 I have rules like the following:

 rule Add Baseline to Context if it does not exists exists or not
 greater
 then 0
  no-loop true
  when
  $context:Context($id:id,baselineParticipation==null ||
  
 baselineParticipation.baselineRatio==null||baselineParticipation.baselineRatio==0)
  then
  modify($firm) {setBaselineParticipation(new
 BaselineParticipation($id,new
 BigDecimal(0.00485)))};
  
 end

 rule Calculate Participation Ratio
  no-loop true
  when
  
 $context:Context(consolidatdVolume!=null,consolidatdVolume.avgVolume0,

 volumeAccumulations[total]!=null,volumeAccumulations[total]0,

 $ratio:(volumeAccumulations[total]/consolidatdVolume.avgVolume))
  then
  ConcurrentMap calculatedRatios=$firm.getCalculatedRatios();
  calculatedRatios.put(fparticipationRatio,new 
 BigDecimal($ratio));
  modify($firm){setCalculatedRatios(calculatedRatios)};
 end

 Despite the checks I get the following exception and any insight into
 why
 would be great:

 Exception executing consequence for rule Calculate Firm
 Participation
 Ratio in com.nasdaq.rms.nq.status: java.lang.ArithmeticException: /
 by
 zero
 Exception executing consequence for rule Calculate Firm
 Participation
 Ratio in com.nasdaq.rms.nq.status: java.lang.ArithmeticException: /
 by
 zero
  at
 org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
  at
 org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1297)
  at
 org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1221)
  at
 org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1456)
  at
 org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:710)
  at
 org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:674)
  at
 org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:230)
  at
 com.nasdaq.fq.rms.workflow.processor.rules.PerformanceStatusAssignmentProcessor.doWork(PerformanceStatusAssignmentProcessor.java:156)
  at
 

[rules-users] News from the community - 5.6.0.CR1 is out!

2013-11-01 Thread Davide Sottara
Finally Drools 5.6.0.CR1 community edition has been released!

It has been mainly a community effort, driven by the use of Drools in
several applications and research projects,
but it was possible thanks to the collaboration of the main developer's
team and the help of everybody
who reported bugs, asked for new features and contributed with patches
or additions.

5.6 consolidates and finalizes the 5.x series. It comes with a number of
bug fixes and a still experimental,
but much more robust, second generation trait system - I will blog and
document it as soon as I can find
a moment next week.

The release is candidate to allow for some broader testing by the
community without requiring to download
and compile the code. If no major issues are reported, it will become
Final in a few weeks.

Let's keep sharing, looking forward to even more exciting innovations in
the 6.x series!

Best
Davide

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] News from the community - 5.6.0.CR1 is out!

2013-11-01 Thread Michael Anstis
Great work Davide.

This shows the power of the community!

Sent on the move
On 1 Nov 2013 21:05, Davide Sottara dso...@gmail.com wrote:

 Finally Drools 5.6.0.CR1 community edition has been released!

 It has been mainly a community effort, driven by the use of Drools in
 several applications and research projects,
 but it was possible thanks to the collaboration of the main developer's
 team and the help of everybody
 who reported bugs, asked for new features and contributed with patches
 or additions.

 5.6 consolidates and finalizes the 5.x series. It comes with a number of
 bug fixes and a still experimental,
 but much more robust, second generation trait system - I will blog and
 document it as soon as I can find
 a moment next week.

 The release is candidate to allow for some broader testing by the
 community without requiring to download
 and compile the code. If no major issues are reported, it will become
 Final in a few weeks.

 Let's keep sharing, looking forward to even more exciting innovations in
 the 6.x series!

 Best
 Davide

 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

Re: [rules-users] News from the community - 5.6.0.CR1 is out!

2013-11-01 Thread Mark Proctor
Davide,

Thank you for al your hard work on this. It’s great when community people step 
up to help drive the project forward.

The core team won’t have time for any final QAing of this, so it’s up to the 
community to test this and make sure it’s ok.

Good luck :)

Mark
On 1 Nov 2013, at 21:04, Davide Sottara dso...@gmail.com wrote:

 Finally Drools 5.6.0.CR1 community edition has been released!
 
 It has been mainly a community effort, driven by the use of Drools in
 several applications and research projects,
 but it was possible thanks to the collaboration of the main developer's
 team and the help of everybody
 who reported bugs, asked for new features and contributed with patches
 or additions.
 
 5.6 consolidates and finalizes the 5.x series. It comes with a number of
 bug fixes and a still experimental,
 but much more robust, second generation trait system - I will blog and
 document it as soon as I can find
 a moment next week.
 
 The release is candidate to allow for some broader testing by the
 community without requiring to download
 and compile the code. If no major issues are reported, it will become
 Final in a few weeks.
 
 Let's keep sharing, looking forward to even more exciting innovations in
 the 6.x series!
 
 Best
 Davide
 
 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users


___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] News from the community - 5.6.0.CR1 is out!

2013-11-01 Thread Salaboy
Great work Davide! Please let me know if I can help with something! 
Cheers 

Sent from my iPhone

On 1 Nov 2013, at 22:51, Mark Proctor mproc...@codehaus.org wrote:

 Davide,
 
 Thank you for al your hard work on this. It’s great when community people 
 step up to help drive the project forward.
 
 The core team won’t have time for any final QAing of this, so it’s up to the 
 community to test this and make sure it’s ok.
 
 Good luck :)
 
 Mark
 On 1 Nov 2013, at 21:04, Davide Sottara dso...@gmail.com wrote:
 
 Finally Drools 5.6.0.CR1 community edition has been released!
 
 It has been mainly a community effort, driven by the use of Drools in
 several applications and research projects,
 but it was possible thanks to the collaboration of the main developer's
 team and the help of everybody
 who reported bugs, asked for new features and contributed with patches
 or additions.
 
 5.6 consolidates and finalizes the 5.x series. It comes with a number of
 bug fixes and a still experimental,
 but much more robust, second generation trait system - I will blog and
 document it as soon as I can find
 a moment next week.
 
 The release is candidate to allow for some broader testing by the
 community without requiring to download
 and compile the code. If no major issues are reported, it will become
 Final in a few weeks.
 
 Let's keep sharing, looking forward to even more exciting innovations in
 the 6.x series!
 
 Best
 Davide
 
 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users
 
 
 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

Re: [rules-users] News from the community - 5.6.0.CR1 is out!

2013-11-01 Thread Alexandre Porcelli
Davide,

 Congratulations! We're lucky to have you around, are people like you that 
makes open source really shine!

Thanks!
--- 
Alexandre Porcelli

On Nov 1, 2013, at 9:50 PM, Salaboy sala...@gmail.com wrote:

 Great work Davide! Please let me know if I can help with something! 
 Cheers 
 
 Sent from my iPhone
 
 On 1 Nov 2013, at 22:51, Mark Proctor mproc...@codehaus.org wrote:
 
 Davide,
 
 Thank you for al your hard work on this. It’s great when community people 
 step up to help drive the project forward.
 
 The core team won’t have time for any final QAing of this, so it’s up to the 
 community to test this and make sure it’s ok.
 
 Good luck :)
 
 Mark
 On 1 Nov 2013, at 21:04, Davide Sottara dso...@gmail.com wrote:
 
 Finally Drools 5.6.0.CR1 community edition has been released!
 
 It has been mainly a community effort, driven by the use of Drools in
 several applications and research projects,
 but it was possible thanks to the collaboration of the main developer's
 team and the help of everybody
 who reported bugs, asked for new features and contributed with patches
 or additions.
 
 5.6 consolidates and finalizes the 5.x series. It comes with a number of
 bug fixes and a still experimental,
 but much more robust, second generation trait system - I will blog and
 document it as soon as I can find
 a moment next week.
 
 The release is candidate to allow for some broader testing by the
 community without requiring to download
 and compile the code. If no major issues are reported, it will become
 Final in a few weeks.
 
 Let's keep sharing, looking forward to even more exciting innovations in
 the 6.x series!
 
 Best
 Davide
 
 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users
 
 
 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users
 
 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users





___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] News from the community - 5.6.0.CR1 is out!

2013-11-01 Thread Demian Calcaprina
Thanks a lot Davide! This is really nice.
We will be using it soon and let the community know if we find something to
report.

Thanks again,

Demian


On Fri, Nov 1, 2013 at 6:04 PM, Davide Sottara dso...@gmail.com wrote:

 Finally Drools 5.6.0.CR1 community edition has been released!

 It has been mainly a community effort, driven by the use of Drools in
 several applications and research projects,
 but it was possible thanks to the collaboration of the main developer's
 team and the help of everybody
 who reported bugs, asked for new features and contributed with patches
 or additions.

 5.6 consolidates and finalizes the 5.x series. It comes with a number of
 bug fixes and a still experimental,
 but much more robust, second generation trait system - I will blog and
 document it as soon as I can find
 a moment next week.

 The release is candidate to allow for some broader testing by the
 community without requiring to download
 and compile the code. If no major issues are reported, it will become
 Final in a few weeks.

 Let's keep sharing, looking forward to even more exciting innovations in
 the 6.x series!

 Best
 Davide

 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users