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

2010-09-17 Thread Ritesh.khot
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: rules-users-boun...@lists.jboss.org
[mailto:rules-users-boun...@lists.jboss.org] 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 ritesh.k...@sungard.com 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 accumulate( ActualSum( auditT == $dAT, $actSum_Main : sumOfThree ),
sum( $actSum_Main ) )

eval(
   chkRuleExpre( $total,$lfna_SEI,$r_SEI )
)

then
   System.out.println(Done Main Rule, total : + $total);
end

--
View this message in context:
http://drools-java-rules-engine.46999.n3.nabble.com/How-to-activate-deac
tivate-a-rule-tp1516088p1516088.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

 

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


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

2010-09-17 Thread Ritesh.khot
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. And I am not modifying any
facts in any of the rules consequence (just insertion).

 

 

Thanks,

Ritesh

 

 

Ritesh Khot

SunGard Technology Services, Lohia Jain, S.B. Road, Pune - 411016, India


Direct Tel: +91-20-3021 6084 * Cell: +91- 9850960259 *
ritesh.k...@sungard.com mailto:ritesh.k...@sungard.com  *
www.sungard.com/sts http://www.sungard.com/sts 

__

CONFIDENTIALITY: This email (including any attachments) may contain
confidential, proprietary and privileged information, and unauthorized
disclosure or use is prohibited. If you received this email in error,
please notify the sender and delete this email from your system. Thank
you.



From: rules-users-boun...@lists.jboss.org
[mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Wolfgang Laun
Sent: Friday, September 17, 2010 1:00 PM
To: Rules Users List
Subject: Re: [rules-users] How to activate/deactivate a rule.

 

I think this overly complex (unless other things have to be considered
as well.

As I interpret these three rules, it is required to compute the sum
of all values ABC.C with equal ABC.A

declare DistinctAT
d_auditT : String
d_sum: Double
end

rule create DistinctAT on first ABC
when
ABC( $a:A )
not DistinctAT( d_auditT == $a )
then
DistinctAT $disAT = new DistinctAT();
$disAT.setD_auditT($AT);
insert( $disAT );
end

rule update d_sum in DistinctAT
when
$disAT: DistinctAT( $a: d_auditT )
ABC( A == $a, $c:C )
then
$disAT.setD_sum( $disAT.getD_sum() + $c*0.13 );
end

Notice that I do not update/modify $disAT in the second rule since this
would cause a loop.
If you need the update to fire other rules, add no-loop true.

To get all results, you can use a query; run it after all ABCs have been
inserted.

-W



On 17 September 2010 08:35, Ritesh ritesh.k...@sungard.com 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 accumulate( ActualSum( auditT == $dAT, $actSum_Main : sumOfThree ),
sum( $actSum_Main ) )

eval(
   chkRuleExpre( $total,$lfna_SEI,$r_SEI )
)

then
   System.out.println(Done Main Rule, total : + $total);
end

--
View this message in context:
http://drools-java-rules-engine.46999.n3.nabble.com/How-to-activate-deac
tivate-a-rule-tp1516088p1516088.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

 

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