We saw one way of representing those rules as a compact decision table. Here is another way…
This approach is based on first grouping together into age bands and then by length of service. This layout is probably easier to read than the first approach.
Days_leave MV 22 AGE >= ? - 18 18 18 45 45 45 60 ELSE AGE < ? 18 45 45 45 60 60 60 - - SERVICE >= 15 - N Y - N Y - - - SERVICE >= 30 - N N Y N N Y - - Days_leave +5 X . . X . . X X . Days_leave +2 . . X . X X . . . Days_leave +3 . . . X . . X X .
Solution 2 Explained
|Initial ActionA||Days_leave MV 22|
|Conditions||AGE >= ?||–||18||18||18||45||45||45||60||ELSE|
|AGE < ?||18||45||45||45||60||60||60||–||–|
|SERVICE >= 15||–||N||Y||–||N||Y||–||–||–|
|SERVICE >= 30||–||N||N||Y||N||N||Y||–||–|
|Actions||Days_leave + 5||XB||.||.||XB||.||.||XB||XB||.|
|Days_leave + 2||.||.||XD||.||XD||XD||.||.||.|
|Days_leave + 3||.||.||.||XC||.||.||XC||XC||.|
A Every employee receives at least 22 days.
- The initial action assigns 22 days.
- Rule 2 does not add any extra days.
B Only employees younger than 18 or at least 60 years, or employees with at least 30 years of service will receive 5 extra days.
- Rule 1 adds 5 days for under 18s.
- Rule 8 adds 5 days for over 60s.
- Rules 4 & 7 adds 5 days for others with over 30 years service.
C Employees with at least 30 years of service and also employees of age 60 or more, receive 3 extra days, on top of possible additional days already given.
- Rules 4 & 7 add an extra 3 days for those with over 30 years service.
- Rule 8 adds an extra 3 days for those over 60 years old.
D If an employee has at least 15 but less than 30 years of service, 2 extra days are given. These 2 days are also provided for employees of age 45 or more. These 2 extra days can not be combined with the extra 5 days.
- Rules 3 & 6 add 2 days for those with 15-30 years service.
- Rule 5 adds 2 days for 45-60s with less than 15 years service.
- The ELSE rule covers any rules not stated.
It is unlikely that rule 4 will be satisfied as the age of the employee would have to be 14 or less when they joined.
The decision table above works so long as the input data is valid. There probably should be checks on age and service. For example, age could be 20 and service 30 which although invalid would satisfy rule 4.
- Checks for minimum and maximum ages
- Check that an age of a person is greater than their years of service — or take the minimum age from their real age and check that the result is more than their years of service.
Of course if you know your data is valid then there should be no problem but unfortunately data can become corrupted.
The following decision table, written in RapidGen’s decision table language RPL, includes the condition to check that the years of service cannot be more than they should be for the person’s age.
*DETAB Calculate_Days_leave I Days_leave MV 22 [Everybody gets 22 days Minimum_age MV 15 [Set minimum age Service_age MV AGE [Set Service age to be age Service_age - Minimum_age [less the minimum age for comparison C SERVICE <= Service_age Y Y Y Y Y Y Y Y ELSE AGE >= ? - 18 18 18 45 45 45 60 - AGE < ? 18 45 45 45 60 60 60 - - SERVICE >= 15 - N Y Y N Y Y - - SERVICE >= 30 - N N Y N N Y - - A Days_leave += 5 X . . X . . X X . [+5 extra days Days_leave += 2 . . X . X X . . . [+2 extra days Days_leave += 3 . . . X . . X X . [+3 extra days DISPLAY ‘Error’ . . . . . . . . X [show error
Executing Decision Table Logic
These screenshots show the original decision tables being run without the additional data checks.
This screenshot shows a decision table being run from a command prompt. The user is prompted to input:
- Name = Jim
- Age = 44
- Service = 14
The output repeats the input values and the calculated days leave = 22. It also shows which rule was used (Rule E)
A command prompt like this can be useful when testing, but typically input and output are both data files. RPL offers great flexibility for reading and writing in many formats.
In this screenshot instead of a command window the decision table logic has been embedded in a C or C++ program.
- age = 59
- service = 30
The result is calculated as 30 days leave and used rule 3 (R3).