[rules-users] Getting different results from decision tables based on number of facts - all other fact information staying the same.

groovenarula gnarula1 at la-z-boy.com
Thu Feb 10 12:11:38 EST 2011


Background : 

I have an object model is as follows :

	Units  1 ---------------> 0..N Options

where a unit (basically an item in stock),  can have 0 … N Options. 

Items themselves have 2 primary fields - an item type (called group - a 3
digit number that represents the category the item belongs to) and a minor
item number (called style - another 3 digit number that represents the
styling of the item). 

Options represent additional enhancements that can be added to the base
units. Very similar to options that can be purchased when buying a new car -
wider wheels/tires, navigation system, leather seats etc. 

Now the use case is to provide the business with easy to use decision tables
that will enable them to Price items based on the base unit and the options
added to the base unit. The way pricing works is that each options has a
standard price. However there are times when options associated with a
specific group and style are priced differently. 

	e.g. Option 'F103' would alway be priced at 100 bucks, however when added
to a unit with group '010' and style '315' it should be priced at 120.

I've created the following approach to meet the pricing rules above: 

rule "Set F103 Option price based on Group/Style"
	salience 50
	when
		$unit : Unit ( 	group == "010", style == "315" )
		$option : Option (unit == $unit )
		          Option (optionPrice == null, code == "F103" )
	then
		
	    $option.setOptionPrice(120.00);
	    retract ( $option );
end

rule "Set F103 Option base price"
	salience 5
	when 
		$option : Option ( optionPrice == null, code == "F103" )
	then
	    	$option.setOptionPrice(100.00);
		retract ( $option );
end

Question : Is there a better way to implement the rules stated above ?

The DRL works as expected when I insert one or multiple items in working
memory. The appropriate rules fire and when Group / Style = 010 / 315, the
price for the option is set to 120, but when Group and Style is anything
else, the option does get priced at 100.00.

However, when I try to implement the same rule using decision tables, I get
different results. To implement the above, I created 2 rule tables :

1. The first rule table establishes the pricing of options that are not
specific to a group / style as follows:

CONDITION                                                  PRIORITY    
ACTION
$option : Option 
code == "$param", optionPrice == null               5            
$option.setOptionPrice($param); retract($option)

2. A second rule table that adds the unit constraints as follows (with
PRIORITY 50):

CONDITION              CONDITION              CONDITION
$unit : Unit                                              $option : Option
group == "$param"  style == "$param"     unit == $unit, code == "$param",
optionPrice == null

ACTION
$option.setOptionPrice($param); retract ( $option);

There in lies my dilemma. 

When I send one unit with Group Style 010 315 and option F103, it prices the
option properly @ 120.00. 

When I send in a unit with a different style (same group = 010), it also
prices the option properly at 100.  

When I when I send 2 units together - one with group and style 010 315 and
another having the same group but a different style (515 for example), it
prices the option for both units @ 120 :

   010 315 option price = 120.00 (correct result)
   010 515 option price = 120.00 (wrong result)

But if the second unit on the 2 units has a different group (011 for
example), I get the right option prices :
 010 315 option price = 120.00 (correct result)
 011 315 option price = 100.00 (correct result)

For what ever reason, it does not fire the generic pricing option even
though the second unit's G/S does not match 010 315.

Can anyone please shed some light on what I'm doing wrong here ?

Any help will be appreciated.

Thanks in advance.
Gurvinder

-- 
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Getting-different-results-from-decision-tables-based-on-number-of-facts-all-other-fact-information-s-tp2467364p2467364.html
Sent from the Drools - User mailing list archive at Nabble.com.




More information about the rules-users mailing list