[rules-users] Evaluate rules for multiple facts of the same type within a StateuflSession

FrankVhh frank.vanhoenshoven at agserv.eu
Wed Feb 13 08:11:22 EST 2013


Hmm, it is very uncommon that I am solely addressed in a post where both me
and the great Wolfgang Laune replied to. It is quite obvious that I have the
lesser mind in this area. Anyway...

There is a variety of ways to deal with it and it all depends on your use
case.

Salience is not the best way to go because it is difficult to manage and
maintain in the ling run. Suppose that you would have 50 reductions and
suppose that you would have to apply the reduction with the highest
percentage (I am guessing that is the case in your example). IN this
scenario, if you would add a 51th discount, that should be second in the
prioritization order, you would have to adapt all saliences of the other
rules to make it fit. This is not what you want.

Also if you rely on saliences only, you might be impacted by other rules in
other logical rule groups that also rely on salience only.

If you must use salience and the amount of the reduction is the
prioritization key, you could use the discount amount as the salience value.
If there is any other kind of rule sequence, make sure it is done nice and
tidy. Only rely on salience within the groups, not accross.

An other approach is that you decouple the validity checking of the
reduction from applying the reduction.

rule
agenda-group "discount eligibility"
when
...
then
insert new Discount(code?, amount?, shoppingCart)

rule
agenda-group "apply discounts"
when
$cart: ShoppingCart()
not DiscountApplied(cart == $cart)
$myDisc: Discount()
not Discount(amount > $myDisc.amount)
then
cart.setDiscount($myDisc.getAmount());
insert(new DiscountApplied());
end

This implies that setDiscount knows how to process the discount. 

You might need different extensions of Discount to fulfill all your needs.

Regards,
Frank


pdario wrote
> @FrankVhh
> 
> It looks ok to have a "no other reductions are applied" as a blocker, I
> find cumbersome to repeat all the conditions of other rules negated.
> 
> Anyway, I'll try to summarize my situation:
> 
> rule "20% discount"
> salience 0
> effective 1st Feb -> 28th Feb
> activaction-group "online discounts"
> when
>   paying with credicard
>   cart contains special product A
> then
>   cart.setDiscount(20)
> 
> rule "15% discount"
> salience -10
> effective 1st Feb -> 28th Feb
> activaction-group "online discounts"
> when
>   paying with credicard
>   cart contains special product B
> then
>   cart.setDiscount(15)
> 
> rule "10% discount"
> salience -20
> activaction-group "online discounts"
> when
>   paying with credicard
> then
>   cart.setDiscount(10)
> 
> rule "No discount"
> salience -30
> activaction-group "online discounts"
> when
>   paying not with creditcard
> then
>   cart.setDiscount(0)
> 
> I thought activation-group / salience combination was the easiest and more
> natural way to follow business rules.
> 
> How would you suggest to change these?





--
View this message in context: http://drools.46999.n3.nabble.com/Evaluate-rules-for-multiple-facts-of-the-same-type-within-a-StateuflSession-tp4022157p4022275.html
Sent from the Drools: User forum mailing list archive at Nabble.com.


More information about the rules-users mailing list