Yay, a great improvement :)<br><br><div class="gmail_quote">2011/11/23 Vincent Legendre <span dir="ltr"><<a href="mailto:vincent.legendre@eurodecision.com">vincent.legendre@eurodecision.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div bgcolor="#FFFFFF" text="#000000">
It will work properly in a stateless session ... in sequential mode
... may be.<br>
This rule for instance, will loop by itself (and all other will also
loop), in a stateless or statefull session :<div class="im"><br>
<br>
rule "one"<br>
when<br>
$r : Result( $score : score )<br>
Applicant( numberOfLoans > 1 )<br>
then<br>
$r.setScore( $score + 5 );<br></div>
update( $r ); // update $r, so re-trigger the rule, which
re-update $r, etc etc etc ...<br>
end<br>
<br>
May be a no-loop could work, but no-loop is dangerous (hard to
debug/maintain, and does not handle cycles between rules firing, ie
"rule one" will trigger "rule two", which will trigger "rule one"
again etc etc)<br>
<br>
The second set of rules could be better, if modified that way (test
is the updated field is null in conditions)<div class="im"><br>
rule "one"<br>
salience 100<br>
when<br></div>
$r : Result(<b>numberOfLoans == null</b>)<div class="im"><br>
Applicant( $nl : numberOfLoans )<br>
then<br>
$r.setNumberOfLoans( $nl );<br>
update( $r );<br>
end <br></div>
...<br>
<br>
Another option is to add some flags in the Result object, holding
the fact that a rule (or a rule group, for instance the rule group
that manage the numberOfLoans, another the income ...) has been
fire, meaning that the corresponding applicant attribute has been
taken into account. This flag is used in the conditions to exclude
all other rules in the same group.<br>
<br>
May be a last option is something that I already use for a use-case
close to this one. This was about computing counter (agregate a
value in a single object, and avoiding infinite loop), then check
them (so I need the updated value). My solution was a rule-flow with
3 boxes : [compute counter]->[update counters in
RETE]->[check counters].<br>
The main trick is to update the value but not the object in
[compute counter] group, like this<br>
<br>
rule "one"<br>
when<br>
$r : Result()<div class="im"><br>
Applicant( numberOfLoans > 1 )<br>
then<br></div>
$r.addScore( 5 );<br>
end<br>
<br>
-> $r fact is not updated in RETE here, so no infinite loop
problem<br>
-> The main point to care about is to avoid getting the actual
score in condition, but uise the getter in the action part. Indeed,
as the $r fact is not updated, the original binding would be kept
and all "computing" rules will update the same initial value (so
forget about agregate).<br>
<br>
<br>
Then update all Results in [update counters in RETE] group :<br>
rule "update_results"<br>
when<br>
$r : Result()<br>
then<br>
update ( $r );<br>
end<br>
<br>
-> this will update all object for their further use for
validation rules<br>
<br>
And finally, use your Result object with score updated to perform
other actions in the [check counters] group :<br>
<br>
rule "decide_reject"<br>
when<br>
$r : Result(decision == null, score < 25)<br>
then<br>
$r.setDecision( Decision.REJECT );<br>
update ( $r );<br>
end<br>
<br>
-> Note the null check to avoid loops, again ...<br>
<br>
<br>
<br>
Le 23/11/2011 11:22, Geoffrey De Smet a écrit :
<div><div class="h5"><blockquote type="cite">
Good idea,<br>
<br>
but note that it will only work properly in a stateless session
(which is most likely in his case).<br>
<br>
In a stateful session, with multiple fireAllRules and when the
applicant's properties change between those fireAllRules call,<br>
the trick is to do an insertLogical of a ScoreDiff instead of
setScore()<br>
and then add 1 general rule to accumulate all those ScoreDiffs and
put the resulting score into the Result.<br>
<br>
Op 23-11-11 10:56, Michael Anstis schreef:
<blockquote type="cite">Why not use a Fact that contains your result?<br>
<br>
In DRL terms it'd look like this:-<br>
<br>
rule "one"<br>
when<br>
$r : Result( $score : score )<br>
Applicant( numberOfLoans > 1 )<br>
then<br>
$r.setScore( $score + 5 );<br>
update( $r );<br>
end<br>
<br>
rule "two"<br>
when<br>
$r : Result( $score : score )<br>
Applicant( disposableIncome < 20000 )<br>
then<br>
$r.setScore( $score + 10 );<br>
update( $r );<br>
end<br>
<br>
The result could equally just contain the factors influencing
the score with a low salience rule then calculating the final
score:-<br>
<br>
rule "one"<br>
salience 100<br>
when<br>
$r : Result()<br>
Applicant( $nl : numberOfLoans )<br>
then<br>
$r.setNumberOfLoans( $nl );<br>
update( $r );<br>
end<br>
<br>
rule "two"<br>
salience 100<br>
when<br>
$r : Result()<br>
Applicant( $di : disposableIncome )<br>
then<br>
$r.setDisposableIncome( $di );<br>
update( $r );<br>
end<br>
<br>
rule "calculate score"<br>
salience 200<br>
when<br>
$r : Result( $nl : numberOfLoans > 1, $di :
disposableIncome < 20000 )<br>
then<br>
$r.setScore( 20 );<br>
update( $r );<br>
end<br>
<br>
<br>
<div class="gmail_quote">On 23 November 2011 09:44, lansyj <span dir="ltr"><<a href="mailto:lansyjp@gmail.com" target="_blank">lansyjp@gmail.com</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> hi folks<br>
<br>
We are working on a requirement that requires us to have
multiple rules that<br>
could fire for a given input and for all the rules that
fire, we would want<br>
to cumulate the consequence to reach the final consequence.<br>
<br>
As an example, if we want to identify the credit score for a
person, based<br>
on his gender you might want to assign/increment/decrement
the score, then<br>
based on nationality, and so on.<br>
<br>
So, considering the long list of such criteria, having rules
that cover all<br>
scenarios and are still mutually exclusive isnt a scalable
solution. Could<br>
you please advice on how this could be achieved.<br>
<br>
We run Drools 5.1.1 and Guvnor; rules are made using the
guided editor with<br>
DSLs.<br>
<br>
Awaiting your support,<br>
<br>
Best Regards<br>
<br>
-lj<br>
<span><font color="#888888"><br>
--<br>
View this message in context: <a href="http://drools.46999.n3.nabble.com/Rules-that-cumulate-on-consequence-tp3530214p3530214.html" target="_blank">http://drools.46999.n3.nabble.com/Rules-that-cumulate-on-consequence-tp3530214p3530214.html</a><br>
Sent from the Drools: User forum mailing list archive at
Nabble.com.<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</font></span></blockquote>
</div>
<br>
<pre><fieldset></fieldset>
_______________________________________________
rules-users mailing list
<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a>
</pre>
</blockquote>
<br>
<pre cols="72">--
With kind regards,
Geoffrey De Smet</pre>
<br>
<fieldset></fieldset>
<br>
<pre>_______________________________________________
rules-users mailing list
<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a>
</pre>
</blockquote>
<br>
</div></div></div>
<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br>