You should be using the update($p) to notify the change of the Product to the engine and no-loop to prevent looping in this case. And doing that, everything seems to work correctly (in both cases)?

I will take a look at why your initial results were different, basically the $price variable in the LHS of your rule gets assigned a value the last time the Product object was inserted or updated. It seems to be using a more recent value if used in combination with ruleflow though.

What do you mean by "But I have the same result without my ruleflow."? Your ruleflow makes sure that your global rule will always be executed before your local rule. It is possible that, if you remove your ruleflow, the behaviour is the same (as in some situations the global rule might still get executed before the local rule). However, if you would for example increase the salience of your local rule, it will always be executed first without ruleflow, but always second in case your ruleflow is used. Similarly, the ruleflow would prevent the global rule from triggering again if the local rule would update the Product again.

Kris

----- Original Message ----- From: "DELBART Vincent" <[EMAIL PROTECTED]>
To: "Rules Users List" <[email protected]>
Sent: Monday, September 10, 2007 4:50 PM
Subject: RE: [rules-users] Ruleflow and persistence


I have really those results in the first set (I put a project in the forum)

If I put an update I loop...

With a no-loop it seems work... But I have the same result without my ruleflow.

vdelbart

-----Message d'origine-----
De : [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] De la part de Kris Verlaenen
Envoyé : lundi 10 septembre 2007 16:37
À : Rules Users List
Objet : Re: [rules-users] Ruleflow and persistence

The expected behavior is actually the second one, did you really get those results when executing the first set? The reason is that you should notify the engine if you change a product (so it can re-evaluate). Otherwise, it will never know that the product has changed price and will still use the old price. So you should add a update($p) statement after changing your product if you want the engine to take that change into account.

Kris


----- Original Message ----- From: "vdelbart" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Monday, September 10, 2007 4:17 PM
Subject: [rules-users] Ruleflow and persistence



Hello,

I have a problem with this ruleflow :

http://www.nabble.com/file/p12593732/ruleflow.jpg

This two rules package doesn't work in the same way :

First package :

#created on: 29 août 2007
package reductionExample1

import model.*

rule "global rule"
ruleflow-group "WorldReduction"
#include attributes such as "salience" here...
when
$p:Product(year == 2006)
then
#actions
System.out.println("Global rule");
System.out.println("$p.getPrice() : " + $p.getPrice());
$p.setPrice($p.getPrice()*1.1);
end
rule "local rule"
ruleflow-group "StateReduction"
#include attributes such as "salience" here...
when
$p:Product(year < 2007, $price: price)
then
#actions
System.out.println("Local rule");
System.out.println("$price : " + $price);
System.out.println("$p.getPrice() : " + $p.getPrice());
$p.setPrice($price * 1.2);
end

I have :
Before : Product(name=Adidas, year=2006, price=100.0)
Global rule
$p.getPrice() : 100.0
Local rule
$price : 110.00000000000001
$p.getPrice() : 110.00000000000001
After : Product(name=Adidas, year=2006, price=132.0)


Second package :

#created on: 29 août 2007
package reductionExample1

import model.*

rule "global rule"
ruleflow-group "WorldReduction"
#include attributes such as "salience" here...
when
$p:Product(year == 2006, $priceGlobal: price)
then
#actions
System.out.println("Global rule");
System.out.println("$price : " + $priceGlobal);
System.out.println("$p.getPrice() : " + $p.getPrice());
$p.setPrice($p.getPrice()*1.1);
end
rule "local rule"
ruleflow-group "StateReduction"
#include attributes such as "salience" here...
when
$p:Product(year < 2007, $price: price)
then
#actions
System.out.println("Local rule");
System.out.println("$price : " + $price);
System.out.println("$p.getPrice() : " + $p.getPrice());
$p.setPrice($price * 1.2);
end

I have :

Before : Product(name=Adidas, year=2006, price=100.0)
Global rule
$price : 100.0
$p.getPrice() : 100.0
Local rule
$price : 100.0
$p.getPrice() : 110.00000000000001
After : Product(name=Adidas, year=2006, price=120.0)


What is the normal execution (for me the first way) and why is different ?

thanks,

vdelbart

--
View this message in context:
http://www.nabble.com/Ruleflow-and-persistence-tf4415033.html#a12593732
Sent from the drools - user mailing list archive at Nabble.com.


_______________________________________________
rules-users mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/rules-users

_______________________________________________
rules-users mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/rules-users

_______________________________________________
rules-users mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/rules-users

_______________________________________________
rules-users mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/rules-users

Reply via email to