Am I correct in thinking you want to calculate the sum of groups of ABC.C&#39;s differentiated by ABC.A?<div><br></div><div>An activation for the third rule is being created each time an ABC is inserted into WM. First with one ABC, then with two and so fourth.</div>
<div><br></div><div>What you want is to ensure that &quot;processing&quot; for rules 1 and 2 complete first and then rule 3 works on the results in WM. This can be achieved with salience on the three rules; lower on rule 3 than 1 and 2 to ensure it&#39;s activations execute after rules 1 and 2 are finished operating on all facts.</div>
<div><div><div><div><br><div class="gmail_quote">2010/9/17  <span dir="ltr">&lt;<a href="mailto:Ritesh.khot@sungard.com">Ritesh.khot@sungard.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">










<div lang="EN-US" link="blue" vlink="blue">

<div>

<p class="MsoNormal"><font size="2" color="navy" face="Calibri"><span style="font-size:11.0pt;font-family:Calibri;color:navy">Hi,</span></font></p>

<p class="MsoNormal"><font size="2" color="navy" face="Calibri"><span style="font-size:11.0pt;font-family:Calibri;color:navy">Thanks for the reply..</span></font></p>

<p class="MsoNormal"><font size="2" color="navy" face="Calibri"><span style="font-size:11.0pt;font-family:Calibri;color:navy"> </span></font></p>

<p class="MsoNormal"><font size="2" color="navy" face="Calibri"><span style="font-size:11.0pt;font-family:Calibri;color:navy">--The sequential option is set to <b><i><span style="font-weight:bold;font-style:italic">false</span></i></b></span></font></p>


<p class="MsoNormal"><font size="2" color="navy" face="Calibri"><span style="font-size:11.0pt;font-family:Calibri;color:navy">--Using  <i><span style="font-style:italic">StatelessKnowledgeSession</span></i></span></font></p>


<p class="MsoNormal"><i><font size="2" color="navy" face="Calibri"><span style="font-size:11.0pt;font-family:Calibri;color:navy;font-style:italic"> </span></font></i></p>

<p class="MsoNormal"><font size="2" color="navy" face="Calibri"><span style="font-size:11.0pt;font-family:Calibri;color:navy">Summary what I intend to achieve,</span></font></p>

<ol style="margin-top:0in" start="1" type="1">
 <li class="MsoNormal"><font size="2" color="navy" face="Calibri"><span style="font-size:11.0pt;font-family:Calibri;color:navy">In
     first rule, I am doing calculation on three different columns and putting it
     in </span></font><b><i><span style="font-weight:bold;font-style:italic">sumOfThree</span></i>
     </b>property of ActualSum and inserting it in WM. Let say I have four
     facts.</li>
 <li class="MsoNormal" style="color:navy"><font size="2" color="navy" face="Calibri"><span style="font-size:11.0pt;font-family:Calibri">In
     Second Rule, I am inserting distinct audit trail in DistinctAT. Lets say I
     have two distinct AT.</span></font></li>
 <li class="MsoNormal" style="color:navy"><font size="2" color="navy" face="Calibri"><span style="font-size:11.0pt;font-family:Calibri">In
     Third Rule, I am assuming 4 Facts of ActualSum and 2 Facts of DistinctAT
     already available in WM. Now I want to get sum of sumOfThree group by AT,
     which I am trying to get using Accumulate function.</span></font></li>
</ol>

<p class="MsoNormal" style="margin-left:.25in"><font size="2" color="navy" face="Calibri"><span style="font-size:11.0pt;font-family:Calibri;color:navy"> </span></font></p>

<p class="MsoNormal" style="margin-left:.25in"><b><i><font size="2" color="navy" face="Calibri"><span style="font-size:11.0pt;font-family:Calibri;color:navy;font-weight:bold;font-style:italic">OutPut I am getting:</span></font></i></b></p>


<p class="MsoNormal" style="margin-left:.25in"><font size="2" color="navy" face="Calibri"><span style="font-size:11.0pt;font-family:Calibri;color:navy">AT
:1001</span></font></p>

<p class="MsoNormal" style="margin-left:.25in"><font size="2" color="navy" face="Calibri"><span style="font-size:11.0pt;font-family:Calibri;color:navy">Done!</span></font></p>

<p class="MsoNormal" style="margin-left:.25in"><font size="2" color="navy" face="Calibri"><span style="font-size:11.0pt;font-family:Calibri;color:navy">Done
Main Rule, total :-40.0</span></font></p>

<p class="MsoNormal" style="margin-left:.25in"><font size="2" color="navy" face="Calibri"><span style="font-size:11.0pt;font-family:Calibri;color:navy">AT
:1000</span></font></p>

<p class="MsoNormal" style="margin-left:.25in"><font size="2" color="navy" face="Calibri"><span style="font-size:11.0pt;font-family:Calibri;color:navy">Done!</span></font></p>

<p class="MsoNormal" style="margin-left:.25in"><font size="2" color="navy" face="Calibri"><span style="font-size:11.0pt;font-family:Calibri;color:navy">Done
Main Rule, total :210.0</span></font></p>

<p class="MsoNormal" style="margin-left:.25in"><font size="2" color="navy" face="Calibri"><span style="font-size:11.0pt;font-family:Calibri;color:navy">AT
:1000</span></font></p>

<p class="MsoNormal" style="margin-left:.25in"><font size="2" color="navy" face="Calibri"><span style="font-size:11.0pt;font-family:Calibri;color:navy">Done
Main Rule, total :160.0</span></font></p>

<p class="MsoNormal" style="margin-left:.25in"><font size="2" color="navy" face="Calibri"><span style="font-size:11.0pt;font-family:Calibri;color:navy">AT
:1000</span></font></p>

<p class="MsoNormal" style="margin-left:.25in"><font size="2" color="navy" face="Calibri"><span style="font-size:11.0pt;font-family:Calibri;color:navy">Done
Main Rule, total :260.0</span></font></p>

<p class="MsoNormal" style="margin-left:.25in"><font size="2" color="navy" face="Calibri"><span style="font-size:11.0pt;font-family:Calibri;color:navy"> </span></font></p>

<p class="MsoNormal" style="margin-left:.25in"><font size="2" color="navy" face="Calibri"><span style="font-size:11.0pt;font-family:Calibri;color:navy">INFO:
Number of generated exceptions                       4</span></font></p>

<p class="MsoNormal"><font size="2" color="navy" face="Calibri"><span style="font-size:11.0pt;font-family:Calibri;color:navy"> </span></font></p>

<p class="MsoNormal"><font size="2" color="navy" face="Calibri"><span style="font-size:11.0pt;font-family:Calibri;color:navy">Here I see the last rule is getting
fired every time ActualSum fact is inserted in first rule. And as the facts are
available one by one, these are available to Accumulate function used in third
Rule. Actually I am expecting only two exceptions one for AT:1001 and AT:1000
with total of -40 and 260 resp.</span></font></p>

<p class="MsoNormal"><font size="2" color="navy" face="Calibri"><span style="font-size:11.0pt;font-family:Calibri;color:navy"> </span></font></p>

<p class="MsoNormal"><font size="2" color="navy" face="Calibri"><span style="font-size:11.0pt;font-family:Calibri;color:navy">Please advise.</span></font></p>

<p class="MsoNormal"><font size="2" color="navy" face="Calibri"><span style="font-size:11.0pt;font-family:Calibri;color:navy"> </span></font></p>

<p class="MsoNormal"><font size="2" color="navy" face="Calibri"><span style="font-size:11.0pt;font-family:Calibri;color:navy">P.S.  Please ignore “</span></font>$lfna_SEI
and $r_SE<font size="2" color="navy" face="Calibri"><span style="font-size:11.0pt;font-family:Calibri;color:navy">”.</span></font></p>

<p class="MsoNormal"><font size="2" color="navy" face="Calibri"><span style="font-size:11.0pt;font-family:Calibri;color:navy"> </span></font></p>

<p class="MsoNormal"><font size="2" color="navy" face="Calibri"><span style="font-size:11.0pt;font-family:Calibri;color:navy"> </span></font></p>

<p class="MsoNormal"><font size="2" color="navy" face="Calibri"><span style="font-size:11.0pt;font-family:Calibri;color:navy">Thanks,</span></font></p>

<p class="MsoNormal"><font size="2" color="navy" face="Calibri"><span style="font-size:11.0pt;font-family:Calibri;color:navy">Ritesh</span></font></p>

<div>

<div class="MsoNormal" align="center" style="text-align:center"><font size="3" face="Times New Roman"><span style="font-size:12.0pt">

<hr size="2" width="100%" align="center">

</span></font></div>

<p class="MsoNormal"><b><font size="2" face="Tahoma"><span style="font-size:10.0pt;font-family:Tahoma;font-weight:bold">From:</span></font></b><font size="2" face="Tahoma"><span style="font-size:10.0pt;font-family:Tahoma"> <a href="mailto:rules-users-bounces@lists.jboss.org" target="_blank">rules-users-bounces@lists.jboss.org</a>
[mailto:<a href="mailto:rules-users-bounces@lists.jboss.org" target="_blank">rules-users-bounces@lists.jboss.org</a>] <b><span style="font-weight:bold">On
Behalf Of </span></b>Michael Anstis<br>
<b><span style="font-weight:bold">Sent:</span></b> Friday, September 17, 2010
12:43 PM<br>
<b><span style="font-weight:bold">To:</span></b> Rules Users List<br>
<b><span style="font-weight:bold">Subject:</span></b> Re: [rules-users] How to
activate/deactivate a rule.</span></font></p>

</div>

<p class="MsoNormal"><font size="3" face="Times New Roman"><span style="font-size:12.0pt"> </span></font></p>

<p class="MsoNormal"><font size="3" face="Times New Roman"><span style="font-size:12.0pt">Have you tried running what you have?</span></font></p>

<div>

<p class="MsoNormal"><font size="3" face="Times New Roman"><span style="font-size:12.0pt"> </span></font></p>

</div>

<div>

<p class="MsoNormal"><font size="3" face="Times New Roman"><span style="font-size:12.0pt">I&#39;d expect it to give the result you expect already (other than
throwing an error because $lfna_SEI and $r_SE are not bound in the last
rule and assuming chkRuleExpre is constant over time). Rules do not
normally execute in any sequential order (unless you explicitly make them so).
As the facts are inserted into WM they are matched against your rules and
activations scheduled. When all facts are inserted into WM and you call
fireAllRules the activations are played out and &quot;truth maintenance&quot;
ensures the &quot;result&quot; of their firing is consistent with the facts in
WM (either inserted by rules or the programmer). This is in essence &quot;how
inference engines&quot; work.</span></font></p>

</div>

<div>

<p class="MsoNormal"><font size="3" face="Times New Roman"><span style="font-size:12.0pt"> </span></font></p>

</div>

<div>

<p class="MsoNormal"><font size="3" face="Times New Roman"><span style="font-size:12.0pt">After you&#39;ve called fireAllRules (and assuming you have a stateful
session) you insert more ABC&#39;s then you&#39;d have to expect the last rule to be
re-evaluated - following another call to fireAllRules. So in part when rule 3
ultimately gives the &quot;correct&quot; answer depends upon when you stop
inserting ABC&#39;s.</span></font></p>

</div>

<div>

<div>

<p class="MsoNormal"><font size="3" face="Times New Roman"><span style="font-size:12.0pt"> </span></font></p>

<div>

<p class="MsoNormal"><font size="3" face="Times New Roman"><span style="font-size:12.0pt">On 17 September 2010 07:35, Ritesh &lt;<a href="mailto:ritesh.khot@sungard.com" target="_blank">ritesh.khot@sungard.com</a>&gt; wrote:</span></font></p>


<p class="MsoNormal"><font size="3" face="Times New Roman"><span style="font-size:12.0pt"><br>
Hi,<br>
<br>
I have 3 rules in my drl file and want the last one should get fired only<br>
after all the facts in rule1 and rule2 gets inserted in working memory.<br>
Please see below code for more understanding. Please suggest.<br>
<br>
Thanks<br>
<br>
declare DistinctAT<br>
    d_auditT : String<br>
end<br>
<br>
declare ActualSum<br>
    auditT : String<br>
    sumOfThree : BigDecimal<br>
end<br>
<br>
rule &quot;insert combined sum&quot;<br>
       dialect &#39;java&#39;<br>
when<br>
   ABC( $a:A, $b:B, $c:C )<br>
<br>
then<br>
       BigDecimal actSum = $c.multiply(0.13);<br>
       ActualSum $as = new ActualSum();<br>
       $as.setAuditT($a);<br>
       $as.setSumOfThree(actSum);<br>
       insert($as);<br>
       System.out.println(&quot;AT :&quot; + $movAuditT);<br>
end<br>
<br>
rule &quot;insert distinct AT&quot;<br>
<br>
       dialect &#39;java&#39;<br>
when<br>
   $a : ActualSum( $AT : auditT )<br>
       not DistinctAT( d_auditT == $AT )<br>
then<br>
       DistinctAT $disAT = new DistinctAT();<br>
       $disAT.setD_auditT($AT);<br>
       insert($disAT);<br>
       System.out.println(&quot;Done!&quot;);<br>
end<br>
<br>
rule &quot;Get Sum Group by AT&quot;<br>
<br>
       dialect &#39;java&#39;<br>
when<br>
<br>
DistinctAT( $dAT: d_auditT )<br>
<br>
$total : Double()<br>
from accumulate( ActualSum( auditT == $dAT, $actSum_Main : sumOfThree ),<br>
sum( $actSum_Main ) )<br>
<br>
eval(<br>
       chkRuleExpre( $total,$lfna_SEI,$r_SEI )<br>
)<br>
<br>
then<br>
       System.out.println(&quot;Done Main Rule, total
:&quot; + $total);<br>
end<br>
<font color="#888888"><span style="color:#888888"><br>
--<br>
View this message in context: <a href="http://drools-java-rules-engine.46999.n3.nabble.com/How-to-activate-deactivate-a-rule-tp1516088p1516088.html" target="_blank">http://drools-java-rules-engine.46999.n3.nabble.com/How-to-activate-deactivate-a-rule-tp1516088p1516088.html</a><br>

Sent from the Drools - User mailing list archive at Nabble.com.<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a></span></font></span></font></p>

</div>

<p class="MsoNormal"><font size="3" face="Times New Roman"><span style="font-size:12.0pt"> </span></font></p>

</div>

</div>

</div>

</div>


<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br></div></div></div></div>