[rules-users] Using global variable in DRL file

Wolfgang Laun wolfgang.laun at gmail.com
Fri Jul 27 10:25:15 EDT 2012


Ah, yes - there are multiple updates of an Agent from several
different policies.

Now, it depend: Is the computed sum of the APEs in the Agent used in
any other rule? If not, the solution is simple. Do not use
modify/update; simply accumulate the values, using the setter, and in
this case you can even omit the no-loop.

rule "accumulate policy APEs into agent APE"
when
    $csvAgent : CSVBeanAgent( $agno: agentNo, $agAPE: agentAPE )
    $csvPolicy : CSVBeanPolicy( agentNo == $agno, $polAPE: policyAPE )
then
    $csvAgent.setAgentAPE(  $agAPE + $polAPE );
end

If you do need the updated CSVBeanAgent.agentAPE, it's a little more
complicated and I should test the solution before I post it. - Or if
you want to try untested: you'll need an accumulate, like this:

rule "accumulate policy APEs into agent APE"
no-loop true
when
    $csvAgent : CSVBeanAgent( $agno: agentNo, $agAPE: agentAPE )
    accumulate( CSVBeanPolicy( agentNo == $agno, $polAPE: policyAPE );
                         $sum: sum(  $polAPE ) )
then
     modify( $csvAgent ){ setAgentAPE( $sum ) }
end

Note that this assumes that the old value in agentAPE is 0 or can be
overwritten; otherwise you might need to add the old value to the
$sum.

-W







On 27/07/2012, zeeshan <zeeshan.spring at gmail.com> wrote:
> Hi Laune !
>
>
>               Thanks for ur solution , I resolved the heap Size problem
> with
> your solution but even using *no-loop* is not helping in solving infinite
> loop issue . Can u suggest why it is not accessing other agent objects and
> simply updating same agent object infinite times......After adding no-loop,
> console shows----
>
>
>
> *6.902394919998737E7ZZZZZZeeesshhaaannn1881.4
> 6.902583059998737E7ZZZZZZeeesshhaaannn2802.0
> 6.902863259998737E7ZZZZZZeeesshhaaannn1881.4
> 6.903051399998738E7ZZZZZZeeesshhaaannn2802.0
> 6.903331599998738E7ZZZZZZeeesshhaaannn1881.4
> 6.903519739998738E7ZZZZZZeeesshhaaannn2802.0
> 6.903799939998738E7ZZZZZZeeesshhaaannn1881.4
> 6.903988079998739E7ZZZZZZeeesshhaaannn2802.0
> 6.904268279998739E7ZZZZZZeeesshhaaannn1881.4
> 6.90445641999874E7ZZZZZZeeesshhaaannn2802.0
> 6.90473661999874E7ZZZZZZeeesshhaaannn1881.4
> 6.90492475999874E7ZZZZZZeeesshhaaannn2802.0
> 6.90520495999874E7ZZZZZZeeesshhaaannn1881.4
> 6.905393099998741E7ZZZZZZeeesshhaaannn2802.0
> 6.905673299998741E7ZZZZZZeeesshhaaannn1881.4
> 6.905861439998741E7ZZZZZZeeesshhaaannn2802.0
> 6.906141639998741E7ZZZZZZeeesshhaaannn1881.4
> 6.906329779998742E7ZZZZZZeeesshhaaannn2802.0
> 6.906609979998742E7ZZZZZZeeesshhaaannn1881.4
> 6.906798119998743E7ZZZZZZeeesshhaaannn2802.0
> 6.907078319998743E7ZZZZZZeeesshhaaannn1881.4
> 6.907266459998743E7ZZZZZZeeesshhaaannn2802.0
> 6.907546659998743E7ZZZZZZeeesshhaaannn1881.4
> 6.907734799998744E7ZZZZZZeeesshhaaannn2802.0
> 6.908014999998744E7ZZZZZZeeesshhaaannn1881.4
> 6.908203139998744E7ZZZZZZeeesshhaaannn2802.0
> 6.908483339998744E7ZZZZZZeeesshhaaannn1881.4
> 6.908671479998745E7ZZZZZZeeesshhaaannn2802.0
> 6.908951679998745E7ZZZZZZeeesshhaaannn1881.4
> 6.909139819998746E7ZZZZZZeeesshhaaannn2802.0
> 6.909420019998746E7ZZZZZZeeesshhaaannn1881.4
> *
> laune wrote
>>
>> Sorry, I think I missed this, all you  need is a no-loop in the rule :)
>> -W
>>
>>
>>
>> On 27/07/2012, zeeshan &lt;zeeshan.spring@&gt; wrote:
>>> Hi Laune !
>>>
>>> I applied your suggested changes but the loop is running infinitely and
>>> same
>>> policyAPE is used to generated cumulated value I mean for 1 agent it is
>>> expected that all the policy APEs should sum up to generate Agent APE
>>> but
>>> same policy APE getting summed up infinitely.....plz find attached of my
>>> console....we printing in console in following order --->  *
>>> System.out.println($agAPE+"ZZZZZZeeesshhaaannn"+$polAPE);*
>>>
>>> Also find my updated RuleMain and Sample.DRL...
>>>
>>>
>>> thanks very much again !
>>>
>>> http://drools.46999.n3.nabble.com/file/n4018946/Sample.drl Sample.drl
>>> http://drools.46999.n3.nabble.com/file/n4018946/console_snapshot.png
>>> console_snapshot.png
>>> http://drools.46999.n3.nabble.com/file/n4018946/RuleMain.java
>>> RuleMain.java
>>>
>>>
>>>
>>>
>>> --
>>> View this message in context:
>>> http://drools.46999.n3.nabble.com/Using-global-variable-in-DRL-file-tp4018911p4018946.html
>>> Sent from the Drools: User forum mailing list archive at Nabble.com.
>>> _______________________________________________
>>> rules-users mailing list
>>> rules-users at .jboss
>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users at .jboss
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>
>
>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/Using-global-variable-in-DRL-file-tp4018911p4018951.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>


More information about the rules-users mailing list