Ok.

I have to compute the gravity for a large number of debts. (It must be done as fast as possible). The customer give me the rules 'in natural language' and a ruleflow.

The ruleflow : attached to this mail, I hope

Problems :

1) no more than 1 rule can be activated in each ruleflowgroup (thats why I used the "computed")

2) using "computed", I realize that the value of "computed" in the real object was true after the first rule activated, but still false in his shadow.

3) so I used update. It worked fine for the first ruleflow group, but in the second ruleflow group (compute C), the first rule was activated again and again (I absolutely need to know the new value of C in order to compute D, so I also used update in this group).

4) Solution : use booleans to control the ruleflow ... without  ruleflow.

That's where I am.


Subject: RE: [rules-users] Synch Business Object / Working Memory
Date: Fri, 11 Apr 2008 15:57:03 +0100
From: manstis1@ford.com
To: rules-users@lists.jboss.org

I am confident Drools supports what you are looking for; did you try update() - or modify() - in the 'then' part of the rule (and not in Java as you code snippet)?
 
Can you explain more the need for the 'computed' flag on the fact? Is the value of a property set sometimes whilst calculated at other times?
 
Stick with both Drools and the group - we'll get you to where you want to be.


From: rules-users-bounces@lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Jonathan Guéhenneux
Sent: 11 April 2008 15:41
To: Rules Users List
Subject: RE: [rules-users] Synch Business Object / Working Memory

First, thank you for yours answers which are very clear. Your solution will probably work. I'm just desapointed that there is no way to synchronized the shadow with the object. That would be great for my work.


Subject: RE: [rules-users] Synch Business Object / Working Memory
Date: Fri, 11 Apr 2008 14:57:52 +0100
From: manstis1@ford.com
To: rules-users@lists.jboss.org

Do you need ruleflow? Perhaps this is too simple and I misunderstood.
 
package com.sample;
 
public class Test {
 
    private Integer a;
    private Integer b;
    private Integer c;
 
    public Integer getA() {
        return a;
    }
 
    public Integer getB() {
        return b;
    }
 
    public Integer getC() {
        return c;
    }
 
    public void setA(Integer a) {
        this.a = a;
    }
 
    public void setB(Integer b) {
        this.b = b;
    }
 
    public void setC(Integer c) {
        this.c = c;
    }
 
}
 
package com.sample
 
import com.sample.Test
 
rule 'rule 1'
    salience 90
    when
        a : Test( a != null, b == null )
    then
     System.out.println('setting b to 10');
        a.setB(10);
        update(a);
end
 
rule 'rule 2'
    salience 80
    when
        a : Test( b : b != null, c == null )
    then
     System.out.println('setting c to b x 5');
        a.setC(b * 5);
        update(a);
end
 
rule 'rule 3'
    salience 70
    when
        a : Test( c != null )
    then
     System.out.println('c = ' + a.getC());
end
 


From: rules-users-bounces@lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Jonathan Guéhenneux
Sent: 11 April 2008 13:23
To: Rules Users List
Subject: RE: [rules-users] Synch Business Object / Working Memory

Indeed, it works but I will have to use such booleans for a lot of rules.

Cause my rule flow is schematically :

compute A
compute B(A)
compute C(B)
...

Perhaps I may create several ruleflows, one per independant computing?


Subject: RE: [rules-users] Synch Business Object / Working Memory
Date: Fri, 11 Apr 2008 12:11:32 +0100
From: manstis1@ford.com
To: rules-users@lists.jboss.org

I was thinking something more like this:-
 

package com.sample

import com.sample.Test
 
rule 'rule 1 - 1'
    salience 90
    when
        a : Test(
         computed == 'false',
            c < 15,
            d >= 75)       
    then
     System.out.println('setting e to 0');
        a.setE(0);
        update(a);
end

 

rule 'rule 1 - 2'
    salience 10
    when
        a : Test(
            computed == 'false',
            c < 15,
            d >= 75)       
    then
     System.out.println('setting e to 1');
        a.setE(1);
end

Note rule 'rule 1 - 2' deliberately uses the same patterns as rule 'rule 1 - 1'.

 
package com.sample;
 
public class Test {
   
    private boolean computed =false;
    private int c=0;
    private int d=80;
    private int e;
 
    public String getComputed(){
       if(computed)
          return 'true';
       else
          return 'false';
    }
 
    public int getC() {
        return c;
    }
 
    public int getD() {
        return d;
    }
 
    public void setE(int e){
        this.e = e;
        computed = true;
    }
 
}
Rule 'rule 1 - 1' is the only rule to run (and runs once); the second activatino being cancelled due to the update to 'computed'. Here's the audit view:-
 
<object-stream>
  <list>
    <org.drools.audit.event.ActivationLogEvent>
      <activationId>rule 1 - 1 [1]</activationId>
      <rule>rule 1 - 1</rule>
      <declarations>a=com.sample.Test@67126712(1)</declarations>
      <type>4</type>
    </org.drools.audit.event.ActivationLogEvent>
    <org.drools.audit.event.ActivationLogEvent>
      <activationId>rule 1 - 2 [1]</activationId>
      <rule>rule 1 - 2</rule>
      <declarations>a=com.sample.Test@67126712(1)</declarations>
      <type>4</type>
    </org.drools.audit.event.ActivationLogEvent>
    <org.drools.audit.event.ObjectLogEvent>
      <factId>1</factId>
      <objectToString>com.sample.Test@67126712</objectToString>
      <type>1</type>
    </org.drools.audit.event.ObjectLogEvent>
    <org.drools.audit.event.ActivationLogEvent>
      <activationId>rule 1 - 1 [1]</activationId>
      <rule>rule 1 - 1</rule>
      <declarations>a=com.sample.Test@67126712(1)</declarations>
      <type>6</type>
    </org.drools.audit.event.ActivationLogEvent>
    <org.drools.audit.event.ActivationLogEvent>
      <activationId>rule 1 - 2 [1]</activationId>
      <rule>rule 1 - 2</rule>
      <declarations>a=com.sample.Test@67126712(1)</declarations>
      <type>5</type>
    </org.drools.audit.event.ActivationLogEvent>
    <org.drools.audit.event.ObjectLogEvent>
      <factId>1</factId>
      <objectToString>com.sample.Test@67126712</objectToString>
      <type>2</type>
    </org.drools.audit.event.ObjectLogEvent>
    <org.drools.audit.event.ActivationLogEvent>
      <activationId>rule 1 - 1 [1]</activationId>
      <rule>rule 1 - 1</rule>
      <declarations>a=com.sample.Test@67126712(1)</declarations>
      <type>7</type>
    </org.drools.audit.event.ActivationLogEvent>
  </list>
</object-stream>
 


From: rules-users-bounces@lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Jonathan Guéhenneux
Sent: 11 April 2008 11:33
To: Rules Users List
Subject: RE: [rules-users] Synch Business Object / Working Memory

Ok, I think I understood well. I modified my business code, now I call if

(wm != null)
            wm.update(wm.getFactHandle(this), this);

each time a properties is modified.

But it is worse. Rules that sould be activated only once actually loop, even if I add the no-loop clause.

I understand why they loop, assuming update = (rectact + insert), but I dont get a solution to my problem. I just want to notify an object changement in order to read again the properties, but I dont want to restart the ruleflow.

Sorry, but I find hard to say it in english because even in french, it's not very clear ;)

Subject: RE: [rules-users] Synch Business Object / Working Memory
Date: Fri, 11 Apr 2008 10:39:41 +0100
From: manstis1@ford.com
To: rules-users@lists.jboss.org

In essence, yes. Have a look at 'update' in the manual (and a read on Shadow Facts will probably be useful too).


From: rules-users-bounces@lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Jonathan Guéhenneux
Sent: 11 April 2008 10:24
To: Rules Users List
Subject: RE: [rules-users] Synch Business Object / Working Memory

yes, i made a mistake. its a.setE(...) and not c.setE(...).

I don't call update. If I dont call update, properties of an object are just read one time for all rules?



Subject: RE: [rules-users] Synch Business Object / Working Memory
Date: Fri, 11 Apr 2008 09:47:43 +0100
From: manstis1@ford.com
To: rules-users@lists.jboss.org

I guess the example is a simplification as 'c' (in RHS) has not been bound to a fact.
 
Anyway, that aside, do you call 'update' to ensure WM knows of changes to facts otherwise properties need to be 'time-constant' which in your example they are not.


From: rules-users-bounces@lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Jonathan Guéhenneux
Sent: 11 April 2008 09:34
To: Rules Users List
Subject: [rules-users] Synch Business Object / Working Memory

Hi,

I have two rules :

rule 'rule 1 - 1'
   
    salience 90
    ruleflow-group 'rfg1'
    when
        a : A(
            eComputed == 'false',
            c < 15,
            d >= 75)       
    then
        c.setE(0);
end



rule 'rule 1 - 2'

    salience 10
    ruleflow-group 'rfg1'
    when
        a : A(
            eComputed == 'false',
            c >= 15,
            d >= 75)       
    then
        c.setE(1);
end



and part of the corresponding business code :

public class A {

    ...

    public String getEComputed(){
       if(eComputed)
          return 'true';
       else
          return 'false';
    }

    ...

    public void setE(int e){
        this.e = e;
        eComputed = true;
    }

    ...

}



so, I expected that if the first rule is activated, the second won't be. But according to my tests, the two rule can be fired on the same object A.
While debugging, I noticed the getEComputed method was only called once. I suppose that I should write this :


rule 'rule 1 - 1'
   
    salience 90
    ruleflow-group 'rfg1'
    when
        a : A(
            eComputed == 'false',
            c < 15,
            d >= 75)       
    then
        c.setE(0);
        c.setEComputed('true);
end



rule 'rule 1 - 2'

    salience 10
    ruleflow-group 'rfg1'
    when
        a : A(
            eComputed == 'false',
            c >= 15,
            d >= 75)       
    then
        c.setE(1);
        c.setEComputed('true);
end

But I would prefer another solution. Thanks for help.


Plus de 15 millions de français utilisent Windows Live Messenger ! Téléchargez Messenger, c'est gratuit !


Plus de 15 millions de français utilisent Windows Live Messenger ! Téléchargez Messenger, c'est gratuit !


Tous vos amis discutent sur Messenger, et vous ? Téléchargez Messenger, c'est gratuit !


Tous vos amis discutent sur Messenger, et vous ? Téléchargez Messenger, c'est gratuit !


Discutez gratuitement avec vos amis en vidéo ! Téléchargez Messenger, c'est gratuit !


Tous vos amis discutent sur Messenger, et vous ? Téléchargez Messenger, c'est gratuit !