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" <delbart.v(a)mipih.fr>
To: <rules-users(a)lists.jboss.org>
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
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users