Preparing decision table
There are several ways to model a Decision Table. No matter what method to be used the end result will be a IIterable<ITable>. Then this can be used to execute the table. For this article we pick simple airline policy and we will model it in different ways.
Airline Passenger Discount Policy
An airline offers only flights to India and Asia. Under special conditions, a discount is offered on the normal airfare:
- Passengers older than 18 with destinations in India are offered a discount of 20%, as long as the departure is not on a Monday or Friday.
- For destinations outside of India, passengers are offered a discount of 25%, if the departure is not on a Monday or Friday.
- Passengers who stay at least 6 days at their destination receive an additional discount of 10%.
- Passengers older than 2 but younger than 18 years are offered a discount of 40% for all destinations.
- Children 2 and under travel for free.
If all the conditions and actions from scenario are extracted you can summarize it as follow:
- Destination (India, Asia)
- Passenger Age (<= 2, > 2 && < 18, > 18
- Depart on Monday or Friday (Yes, No)
- Stay 6 days or more (Yes, No)
- Travel Free
- 0% discount
- 10% discount
- 20% discount
- 40% discount
Number of rules: 2 values * 3 values * 2 values * 2 values = 24 rules
Now we dump the result in a simple table to visualize all the conditions combination.
|Stay >= 6 Days?||Y||N||Y||N||Y||N||Y||N||Y||N||Y||N||Y||N||Y||N||Y||N||Y||N||Y||N||Y||N|
For rules 1 to 4, and 13 to 16, you've got an interesting set of actions: some of these columns state a 10% discount for staying 6+ days, but all of these columns also state that these passengers travel for free. Since a passenger traveling for free can't receive an additional discount, we can combine all 8 rules into rule #1, below.
You can reduce rules 10 and 22 (passengers over 18 departing on a Monday/Friday who are staying less than 6 days, regardless of destination, get no discount at all) although this may be hard to see until after you reduce the table at least once.
We can also reduce rules 5/7 (passengers traveling to India, between 3 and 18 years of age, staying 6+ days, doesn't matter what day they leave) and 6/8 (same as previous, except staying less than 6 days).
You can reduce rules 10 and 22 (passengers over 18 departing on a Monday/Friday who are 6 days or more, regardless of destination, get no discount at all) although this may be hard to see until after you reduce the table at least once.
Similarly, you can reduce rules 9 and 21 (passengers over 18 departing on a Monday/Friday who are staying less than 6 days, regardless of destination, get a 10% discount).
|Stay >= 6 Days?||--||Y||N||N||Y||Y||N||Y||N||Y||N||Y||N|
Preparing Decision Table
Now we can define the aging groups like the following definition:
- Group1 : <=2
- Group2 : 3-18
- Group3 : >18
And it is simpler when we prepare a model that the decision requires. It would encapsulate all conditions:
- Destination: The destination of travel
- AgeGroup: The aging group as we defined
- IsWeekDay: The condition for "Depart Mon/Fri?"
- StaryMoreThan6: The condition for "Stay >= 6 Days?"
And last, we turning the table to a vertical table that conditions/actions sit on columns we can have decision table like this:
We do not need the Rule name (the first column)
And finally the table looks like this:
This table now is the source for the modeling. In fact this exact table can be executed by your application with a bit more additional rows.
- Introduction to decision table
- Preparing decision table
- Modeling decision table
- Decision Model and Notation - decision table
- Check overlaps
- Decision Table final logic
- Multilingual decision table
- Decision Table 101