<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body 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 :<br>
    <br>
    rule "one"<br>
    &nbsp;&nbsp;&nbsp; when<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $r : Result( $score : score )<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Applicant( numberOfLoans &gt; 1 )<br>
    &nbsp;&nbsp;&nbsp; then<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $r.setScore( $score + 5 );<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 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)<br>
    rule "one"<br>
    &nbsp;&nbsp;&nbsp; salience 100<br>
    &nbsp;&nbsp;&nbsp; when<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $r : Result(<b>numberOfLoans == null</b>)<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Applicant( $nl : numberOfLoans )<br>
    &nbsp;&nbsp;&nbsp; then<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $r.setNumberOfLoans( $nl );<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; update( $r );<br>
    end <br>
    &nbsp;...<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 :&nbsp; [compute counter]-&gt;[update counters in
    RETE]-&gt;[check counters].<br>
    The main trick is to update the value but not the object in&nbsp;
    [compute counter] group, like this<br>
    <br>
    rule "one"<br>
    &nbsp;&nbsp;&nbsp; when<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $r : Result()<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Applicant( numberOfLoans &gt; 1 )<br>
    &nbsp;&nbsp;&nbsp; then<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $r.addScore( 5 );<br>
    end<br>
    <br>
    -&gt; $r fact is not updated in RETE here, so no infinite loop
    problem<br>
    -&gt; 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>
    &nbsp;&nbsp;&nbsp; when<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $r : Result()<br>
    &nbsp;&nbsp;&nbsp; then<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; update ( $r );<br>
    end<br>
    <br>
    -&gt; 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>
    &nbsp;&nbsp;&nbsp; when<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $r : Result(decision == null, score &lt; 25)<br>
    &nbsp;&nbsp;&nbsp; then<br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $r.setDecision( Decision.REJECT );<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; update ( $r );<br>
    end<br>
    <br>
    -&gt; Note the null check to avoid loops, again ...<br>
    <br>
    <br>
    <br>
    Le 23/11/2011 11:22, Geoffrey De Smet a &eacute;crit&nbsp;:
    <blockquote cite="mid:jaihh2$q8f$1@dough.gmane.org" type="cite">
      <meta content="text/html; charset=ISO-8859-1"
        http-equiv="Content-Type">
      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
cite="mid:CAAG9P0smYEsu+wsTFtYBLmy_-1PDj2bW2QDsWntLZ53FeDb5QQ@mail.gmail.com"
        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>
        &nbsp;&nbsp;&nbsp; when<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $r : Result( $score : score )<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Applicant( numberOfLoans &gt; 1 )<br>
        &nbsp;&nbsp;&nbsp; then<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $r.setScore( $score + 5 );<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; update( $r );<br>
        end<br>
        <br>
        rule "two"<br>
        &nbsp;&nbsp;&nbsp; when<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $r : Result( $score : score )<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Applicant( disposableIncome &lt; 20000 )<br>
        &nbsp;&nbsp;&nbsp; then<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $r.setScore( $score + 10 );<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 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>
        &nbsp;&nbsp;&nbsp; salience 100<br>
        &nbsp;&nbsp;&nbsp; when<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $r : Result()<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Applicant( $nl : numberOfLoans )<br>
        &nbsp;&nbsp;&nbsp; then<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $r.setNumberOfLoans( $nl );<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; update( $r );<br>
        end<br>
        <br>
        rule "two"<br>
        &nbsp;&nbsp;&nbsp; salience 100<br>
        &nbsp;&nbsp;&nbsp; when<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $r : Result()<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Applicant( $di : disposableIncome )<br>
        &nbsp;&nbsp;&nbsp; then<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $r.setDisposableIncome( $di );<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; update( $r );<br>
        end<br>
        <br>
        rule "calculate score"<br>
        &nbsp;&nbsp;&nbsp; salience 200<br>
        &nbsp;&nbsp;&nbsp; when<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $r : Result( $nl : numberOfLoans &gt; 1, $di :
        disposableIncome &lt; 20000 )<br>
        &nbsp;&nbsp;&nbsp; then<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $r.setScore( 20 );<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; update( $r );<br>
        end<br>
        <br>
        <br>
        <div class="gmail_quote">On 23 November 2011 09:44, lansyj <span
            dir="ltr">&lt;<a moz-do-not-send="true"
              href="mailto:lansyjp@gmail.com">lansyjp@gmail.com</a>&gt;</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 class="HOEnZb"><font color="#888888"><br>
                --<br>
                View this message in context: <a moz-do-not-send="true"
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 moz-do-not-send="true"
                  href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
                <a moz-do-not-send="true"
                  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 wrap=""><fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
rules-users mailing list
<a moz-do-not-send="true" class="moz-txt-link-abbreviated" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a>
</pre>
      </blockquote>
      <br>
      <pre class="moz-signature" cols="72">-- 
With kind regards,
Geoffrey De Smet</pre>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
rules-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>