Earnie,
I could certainly qualify which charges I want to use to increment the total
in amountFact. The example is illustratrating the problem with using the
technique of assigning a variable name, via chart notation, to an object in
Working Memory so that you can update the object in the consequences section
(then clause) of the rule.
Because amountFact is updated, it puts the rule back on the agenda to be
processed again, even though the properties that are being used by the rule
qualification (when clause) have not changed.
So, if I remove the update statement, the rule behaves properly and
amountFact contains a total of all of the amounts in the charges that have
been inserted into Working Memory.
However, if I have another rule that looks at the amountFact's amount, it
won't see the updates to the property and won't fire. For example:
rule "Test Amount"
when
Fact(name == "Amount", amount > 150)
then
System.out.println("Amount is greater than 150");
end
Earnie D wrote:
Dan,
Why would you have more than one Charge when you are not qualifying it?
Are they all the same? Do you not care which one matches?
Earnie!
________________________________
From: Dan Seaver <dan.seaver(a)ge.com>
To: rules-users(a)lists.jboss.org
Sent: Tuesday, November 4, 2008 12:50:09 PM
Subject: [rules-users] Chart notation, update, and infinite loops
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-tp20...
Sent from the drools - user mailing list archive at
Nabble.com.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
rules-users(a)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-tp20...
Sent from the drools - user mailing list archive at
Nabble.com.