For repeated changes of a fact (the Score thing, in your case) a stateful
session should be used. Then, the update of your Score fact would be
modify( s ){
setValue( s.getValue() + 4 ) // 4 or whatever
}
Repeated firing of the "threshold" rule is due to the Engine's reassessment
of your Score fact after each increment, irrespective of its value field
being below or above the threshold. Therefore, firing happens after each
change above the limit.
You could reduce this to a single firing by adding another boolean field
"alerted" which is set to true in the RHS of this rule and included in the
rule's LHS:
when
s : Score( value > 40, alerted == false )
then
modify( s ){
setAlerted( true )
}
-W
On Sun, May 17, 2009 at 7:27 PM, David Boaz <davidb(a)dbmotion.com> wrote:
Dear all,
First, let me inform that we are using stateless sessions in Drools 5 CR1.
In my application I have to compute a score and if the score is above a
threshold, an alert is created. The score is accumulated from many small
rules (actually, generated from excel using drools decision-tables).
Initially, many input objects and a Score object initialized to zero are
inserted. The form of my rules is:
1 rule “accumulate #1”
2 when
3 Input(....)
4 s:Score()
5 then
6 s.add(4) // 4 is just an example
7 end
8
9 rule “threshold”
10 when
11 Score(value>40)
12 then
13 Alert.create(..)
14 end
1.The Score object was actually accumulated as expected. But for some
reason, the “threshold” rule fired once when the score.value was still ==0.
2.I tried to set the salience of the “threshold” rule to -1 (low priority).
But it didn't affect the rule firing.
3.I suspected that the engine was not informed that the score object was
updated in the first rules. So, I added a call to drools.update(s) after
line 6. That solved the issue and the “threshold” rule actually fired. But
now, I noticed that several alerts were created because the score was set
several times to a value>40.
4.To solve that new issue, I set again the salience of the threshold rule
to
-1. This time, only one alert was created.
My concern is that I don't understand what happened. Can someone please
explain?
To my understanding, the situation described in my second bullet should
work. Initially, all the inserted objects are checked in the RETE network
and an agenda is created. The activation for the “threshold” rule is the
last one. I don't see the reason how can the threshold rule fire before all
the accumulate rules were fired.
Thanks for the help, David
--
View this message in context:
http://www.nabble.com/rule-with-low-Salience-is-fired-too-early-tp2358559...
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