[rules-users] Chart notation, update, and infinite loops

Greg Barton greg_barton at yahoo.com
Tue Nov 4 13:29:10 EST 2008


1) Do you want to apply all Charges in working memory to all "Amount" Facts?  I ask because the rule is a cartesian join (i.e. no relation between matched objects) and that sometimes performs in ways users don't expect. (i.e. all combinations of objects that match the conditions are affected by the rule)
2) Can you add a property to the Charge object?  Then you could use a boolean named "applied" to prevent future matches.

Rule "Update Amount"
   when
      amountFact : Fact(name == "Amount")
      charge : Charge(applied == false)
   then
      Double amount = amountFact.getAmount();
      Double chargeAmount = charge.getAmount();
      amountFact.setAmount(amount + chargeAmount);
      update(amountFact);
      charge.setApplied(true);
      update(charge);
end

If a charge could be applied to multiple Facts you could maintain an "appliedTo" list of Facts in the Charge, and check that instead of a simple boolean.

--- On Tue, 11/4/08, Dan Seaver <dan.seaver at ge.com> wrote:

> From: Dan Seaver <dan.seaver at ge.com>
> Subject: [rules-users] Chart notation, update, and infinite loops
> To: rules-users at lists.jboss.org
> Date: Tuesday, November 4, 2008, 11:50 AM
> I'm trying to find a good technique for updating
> specific facts in working
> memory. What I'm currently doing is something like
> this:
> 
> Rule "Update Amount"
>    when
>       amountFact : Fact(name == "Amount")
>       charge : Charge()
>    then
>       Double amount = amountFact.getAmount();
>       Double chargeAmount = charge.getAmount();
>       amountFact.setAmount(amount + chargeAmount);
>       update(amountFact);
> end
> 
> The update statement causes an infinite loop.
> I tried using no-loop, which works if there is 1 charge,
> but not if there
> are more than one.
> 
> Any help with solutions or strategies would be much
> appreciated.
> -- 
> View this message in context:
> http://www.nabble.com/Chart-notation%2C-update%2C-and-infinite-loops-tp20327483p20327483.html
> Sent from the drools - user 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