Re: [rules-users] How to activate/deactivate a rule.

2010-09-17 Thread Ritesh

Thank you so much...  earlier I tried with both as below for each rule
with different salience values... but it was generating 4 exception as I
mentioned in my last email.

1.

agenda-group init

  auto-focus true

  no-loop true

salience 10 

  dialect 'java'

2.

  dialect 'java'

 

Now I am just using :

Rule 1

salience 100

  dialect 'java'

Rule 2

salience 50

  dialect 'java'

Rule 3

salience -1

  dialect 'java'

 

This is working just fine.

 

Thanks a lot..

 

Ritesh



From: Michael Anstis-2 [via Drools - Java Rules Engine]
[mailto:ml-node+1516613-244846131-167...@n3.nabble.com] 
Sent: Friday, September 17, 2010 4:46 PM
To: Khot, Ritesh
Subject: Re: How to activate/deactivate a rule.

 

Am I correct in thinking you want to calculate the sum of groups of
ABC.C's differentiated by ABC.A?

 

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.

 

What you want is to ensure that processing 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's activations execute after rules 1 and 2 are finished operating on
all facts.

 

2010/9/17 [hidden email]

Hi,

Thanks for the reply..

 

--The sequential option is set to false

--Using  StatelessKnowledgeSession

 

Summary what I intend to achieve,

1.  In first rule, I am doing calculation on three different columns
and putting it in sumOfThree property of ActualSum and inserting it in
WM. Let say I have four facts.
2.  In Second Rule, I am inserting distinct audit trail in
DistinctAT. Lets say I have two distinct AT.
3.  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.

 

OutPut I am getting:

AT :1001

Done!

Done Main Rule, total :-40.0

AT :1000

Done!

Done Main Rule, total :210.0

AT :1000

Done Main Rule, total :160.0

AT :1000

Done Main Rule, total :260.0

 

INFO: Number of generated exceptions   4

 

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.

 

Please advise.

 

P.S.  Please ignore $lfna_SEI and $r_SE.

 

 

Thanks,

Ritesh



From: [hidden email] [mailto:[hidden email]] On Behalf Of Michael Anstis
Sent: Friday, September 17, 2010 12:43 PM
To: Rules Users List
Subject: Re: [rules-users] How to activate/deactivate a rule.

 

Have you tried running what you have?

 

I'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 truth maintenance
ensures the result of their firing is consistent with the facts in WM
(either inserted by rules or the programmer). This is in essence how
inference engines work.

 

After you've called fireAllRules (and assuming you have a stateful
session) you insert more ABC's then you'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 correct answer depends upon when you
stop inserting ABC's.

 

On 17 September 2010 07:35, Ritesh [hidden email] wrote:


Hi,

I have 3 rules in my drl file and want the last one should get fired
only
after all the facts in rule1 and rule2 gets inserted in working memory.
Please see below code for more understanding. Please suggest.

Thanks

declare DistinctAT
d_auditT : String
end

declare ActualSum
auditT : String
sumOfThree : BigDecimal
end

rule insert combined sum
   dialect 'java'
when
   ABC( $a:A, $b:B, $c:C )

then
   BigDecimal actSum = $c.multiply(0.13);
   ActualSum $as = new ActualSum();
   $as.setAuditT($a);
   $as.setSumOfThree(actSum);
   insert($as);
   System.out.println(AT : + $movAuditT);
end

rule insert distinct AT

   dialect 'java'
when
   $a : ActualSum( $AT : auditT )
   not DistinctAT( d_auditT == $AT )
then
   DistinctAT $disAT = new DistinctAT();
   $disAT.setD_auditT($AT);
   insert($disAT);
   System.out.println(Done!);
end

rule Get Sum Group by AT

   dialect 'java'
when

DistinctAT( $dAT: d_auditT )

$total : Double()
from

[rules-users] Unable to Access Facts in second rule.

2010-08-25 Thread Ritesh

Hi, 

I am trying to work on below rules, there are no compilation errors and all
rules getting executed. 
Obersation: 
1. Able print message in first rule consequence. 
2. Unable to print message in second rule consequence. 
3. Not getting exception in the last rule. The Test Data i am working on
should generate one exception in the last rule. 

It would be really very helpful if anyone can help. 

Thanks and Regards, 
Ritesh 

Below is my DRL File: 

import java.util.List; 
import java.math.*; 
import java.util.*; 
import java.text.*; 
import org.apache.commons.lang.*; 

declare DistinctAT 
 d_auditT : String 
end 

declare ActualSum 
 auditT : String 
 tranType : String 
 sumOfThree : BigDecimal 
end 

rule insert combined sum 
agenda-group init 
auto-focus true 
no-loop true 
salience 10 
dialect 'java' 
when 
GNMVT( movTransactionType == 'OD', $movType : idMovMovementType,
$tradeSta : movTradeStatus, 
$fndCstPrc : movFundCostPrice, $movTranType : movTransactionType, 
$movAuditT : movAuditTrail ) 
//not ActualSum(auditT == $movAuditT, tranType == $movTranType) 
then 
BigDecimal actSum =
resltForMovTyp($movType).multiply(resltForMovTrdSts($tradeSta)).multiply($fndCstPrc);
 
ActualSum $as = new ActualSum(); 
$as.setAuditT($movAuditT); 
$as.setTranType($movTranType); 
$as.setSumOfThree(actSum); 
insert($as); 
System.out.println(AT : + $movAuditT +  Actual Sum : + actSum); 
   
//drools.getKnowledgeRuntime().getAgenda().getAgendaGroup(Second).setFocus(); 
   
//drools.getKnowledgeRuntime().getAgenda().getAgendaGroup(Third).setFocus(); 
end 

rule insert distinct AT 
agenda-group Second 
auto-focus true 
dialect 'java' 
when 
$a : ActualSum( $AT : auditT ) 
not DistinctAT( d_auditT == $AT ) 
then 
DistinctAT $disAT = new DistinctAT(); 
$disAT.setD_auditT($AT); 
insert($disAT); 
//System.out.println(Distinct Audit Trial : + $AT + TotlNet : +
$lfna_MO.getPtnaFundTotalNetAsset()); 
//System.out.println(TotlNet : +
$lfna_MO.getPtnaFundTotalNetAsset()); 
System.out.println(Done!); 
   
//drools.getKnowledgeRuntime().getAgenda().getAgendaGroup(Third).setFocus(); 
end 

global ExceptionList exceptions 

rule gpMiscellaneous_Operation 
agenda-group Third 
when 
$r_MO : RuleMetaData(ruleName == gpMiscellaneous_Operation ) 
$lfna_MO : GLFNA(ptnaFundTotalNetAsset != 0) 
DistinctAT( $dAT: d_auditT ) 

$total : BigDecimal() 
from accumulate( ActualSum( auditT == $dAT, $actSum_Main : sumOfThree ),
sum( $actSum_Main ) ) 

eval( 
chkRuleExpre( $total,$lfna_MO,$r_MO ) 
) 

then 
BaseExceptionBuilder builder =
BaseExceptionBuilder.createBaseExceptionBuilder($r_MO); 
BaseException e = builder.createException(); 

exceptions.add(e); 
System.out.println(Done Main Rule); 
end 

function boolean chkRuleExpre(BigDecimal ttl, GLFNA l, RuleMetaData r) 
{ 
   double val = Math.abs( 100 * ttl.doubleValue() /
l.getPtnaFundTotalNetAsset().doubleValue() ); 
   if (val  (Double) r.getRuleArg(Miscellaneous_Operation_Low)) 
   {return true;} 
   else{return false;} 
} 
function BigDecimal resltForMovTyp(String str) 
{ 
if (str.equals(E) || str.equals(R)) 
{ return BigDecimal.valueOf(-1.0); } 
else 
{ return BigDecimal.valueOf(1.0); } 
} 
function BigDecimal resltForMovTrdSts(String str) 
{ 
if (str.equals(XX)) 
{ return BigDecimal.valueOf(-1.0); } 
else 
{ return BigDecimal.valueOf(1.0); } 
} 
-- 
View this message in context: 
http://drools-java-rules-engine.46999.n3.nabble.com/Unable-to-Access-Facts-in-second-rule-tp1331348p1331348.html
Sent from the Drools - User mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users