Preparing decision table
There are several ways to model a Decision Table. No matter what method is used, the end result will be a IIterable<ITable>. This can be used to execute the table.
For the purposes of this article, we picked a simple airline policy. We will model this 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 the scenario are extracted, you can summarize it as follows:
- 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 a combination of all these conditions.
|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, as shown 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 (it 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 staying six 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 six 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 as shown in the following definition:
- Group1 : <=2
- Group2 : 3-18
- Group3 : >18
It is simpler when we prepare a model to help make a decision. It would encapsulate all conditions:
- Destination: The destination of travel
- AgeGroup: The aging group as defined
- IsWeekDay: The condition for "Depart Mon/Fri?"
- StaryMoreThan6: The condition for "Stay >= 6 Days?"
And last, we change the table into a vertical table in which conditions/actions sit in columns. We can then have Decision Table like this:
We do not need the Rule name (the first column)
The final table looks like this:
This table is now the source for modeling. In fact this exact table can be executed by your application with a few 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