[rules-users] Chart notation, update, and infinite loops
Dan Seaver
dan.seaver at ge.com
Tue Nov 4 14:55:13 EST 2008
Greg,
1) Yes, in this case I'm looking for the cartesian join.
2) No, I can't add a property to Charge as it's part of our corp Object
Model.
However, I could create a third object that manages whether the Charge has
been processed which works just fine. Unless there is a simpler strategy /
technique, I'll go with that.
Do you know of any way to keep the rule from being put back on the agenda
when amountFact is updated? I want other rules to know that it's been
updated, just not the rule that made the change.
Dan
Greg Barton wrote:
>
> 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
>
>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
--
View this message in context: http://www.nabble.com/Chart-notation%2C-update%2C-and-infinite-loops-tp20327483p20329780.html
Sent from the drools - user mailing list archive at Nabble.com.
More information about the rules-users
mailing list