[rules-users] Modifying the fact more than once within a rule

Natraj Gudla natraj.forums at gmail.com
Thu Jul 19 23:43:08 EDT 2007


Hello Edson,

It is the modifications in different rule consequences and not the single
one. I have pasted the 4 rules which are involved here...

My frist two rules are mutually exclusive as are the next two. When i
execute, Calculate Business Profit,1 fires, followed by Calcualte AIC. As
soon as this second rule fires, i see the system going into an infinite
loop, reevluating all the rules once again. the no-loop true does not work
here.

I have a business scenario where i need to modify the object in the second
rule, as there are further rules which use it.

Is this an expected behavior??? Or is My Code wrong?



*rule "Calculate Business profit,1"*
 salience 1000
 no-loop true
 when
  emi : EMIAgainstProperty ( businessProfit2  > (businessProfit1 * 1.5) )
 then
  modifyRetract(emi);
  emi.setBusinessProfit((emi.getBusinessProfit1
()+emi.getBusinessProfit2())/2);
  modifyInsert(emi);
end

*rule "Calculate Business profit,2"*
 salience 999
 no-loop true
 when
  emi : EMIAgainstProperty ( businessProfit2 <= (businessProfit1 * 1.5) )
 then
  modifyRetract(emi);
  emi.setBusinessProfit(emi.getBusinessProfit2());
  modifyInsert(emi);
end

*rule "Calculate AIC"*
 salience 998
 no-loop true
 when
  emi: EMIAgainstProperty( businessProfit > ( businessProfit1 * 2) )
 then
  System.out.println(" AIC "+emi.getBusinessProfit());
  modifyRetract(emi);
  emi.setAIC(emi.getBusinessProfit1()*2);
  modifyInsert(emi);
end


*rule "Calculate AIC1"*
 no-loop true
 salience 997
 when
  emi: EMIAgainstProperty( businessProfit <= ( businessProfit1 * 2) )
 then
  modifyRetract(emi);
  System.out.println(" AIC Less "+emi.getBusinessProfit());
  emi.setAIC(emi.getBusinessProfit());
  modifyInsert(emi);
end





On 7/19/07, Edson Tirelli <tirelli at post.com> wrote:

>
>    Natraj,
>
>    You mean modifying twice inside the same rule consequence?
>    There should be no problem in modifying a fact twice inside the same
> consequence besides wasted effort, so if you are going into an infinite
> loop, that is a bug. Would you please open a JIRA with a test case showing
> the problem? Having said that, there is no reason to modify a fact twice
> inside the same consequence block, so if that is the case, you may also
> check your code again.
>
>    Now, if you are talking about modifying a fact in the consequence of 2
> different rules, then you need to verify if your modification is not causing
> rules to be reevaluated and fired in loops, what is possible to happen and
> you need to fix your rules to avoid that.
>
>     []s
>     Edson
>
> 2007/7/19, Natraj Gudla <natraj.forums at gmail.com>:
> >
> >  Hello All,
> >
> > Has anyone faced a situation where a fact gets modified more than once
> > within a given DRL. The modification is required so that the other rules
> > properly fire based on the consequence of the earlier.
> > I am able to get through the modifyRetract() and modifyInsert() once in
> > a rule consequence, but the second time i do it, it goes into an infinite
> > loop and results in out of memory.
> >
> > Why is it that i cant modify the object more than once. In such a case,
> > how to deal with business scenarios which need this.
> >
> > Also, is it possible to handle the execution of another DRL within one
> > DRL.
> >
> > Thanks
> > Natraj Gudla
> >
> > _______________________________________________
> > rules-users mailing list
> > rules-users at lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/rules-users
> >
> >
>
>
> --
>   Edson Tirelli
>   Software Engineer - JBoss Rules Core Developer
>   Office: +55 11 3529-6000
>   Mobile: +55 11 9287-5646
>   JBoss, a division of Red Hat @ www.jboss.com
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20070720/cb7e30cb/attachment.html 


More information about the rules-users mailing list