# Vacation Days

This example is another challenge taken from dmcommunity.org, namely Vacation Days Calculation. In this challenge, we need to calculate vacation days for employees, based on their age and years of service. The description is as follows:

Vacation Days

The number of vacation days depends on age and years of service.

Every employee receives at least 22 days. Additional days are provided by the following criteria:

1. Only employees younger than 18 or at least 60 years, or employees with at least 30 years of service will receive 5 extra days.

2. 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.

3. 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 5 extra days.

To solve this challenge, there’s two main ways:

1. Convert all these rules to one big `C+` table, and count the number of days for each employee.

2. Convert each rule into its own table and relation, and then count the days at the end for each rule satisfied.

Both have been implemented in our available cDMN.xlsx , but only the second one will be explained here. By first checking which rules are satisfied and then calculating the days, we gain readability and traceability in our implementation.

We start modeling the example by building the glossary. This is quite simple: we only need to add a type to represent employees. For the example, we create three dummy employees: Huey, Dewey and Louie.

Type
Name Type Values
Employee String Huey, Dewey, Louie

After creating the types, we can move on to the next sub-glossary. We need a way to map each employee on their information: since every employee can only have exactly one age, amount of service years and amount of vacation days, we opt for functions.

Function
Name Type
age of Employee Int
service years of Employee Int
vacation days of Employee Int

Thirdly, we need a way to express which rules are satisfied for which employee. For this purpose, we introduce a relation for each rule.

Relation
Name
Employee is eligible for r1
Employee is eligible for r2
Employee is eligible for r3

Now that our glossary is complete, we can start creating decision and constraint tables. The first tables we should make, are the ones for the extra vacation days. There’s three such rules, and thus, three such tables.

Rule 1

Only employees younger than 18 or at least 60 years, or employees with at least 30 years of service will receive 5 extra days.

The easiest way to model this rule (and the following ones) is by using a `U` table. The rows of the table can be translated to the following:

1. Every employee younger than 18 years is eligible.

2. Every employee over the age of 60 is eligible.

3. Every employee between 18 or 60 with at least 30 years of service is eligible.

Rule 1
U Employee age of Employee service years of Employee Employee is eligible for r1
1 - < 18 - Yes
2 - >= 60 - Yes
3 - [18, 60) >= 30 Yes

Rule 2

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.

We opt for another `U` table here. It is similar to the previous table: it uses the same input columns, but a different output column. The rows can be translated to the following:

1. Everyone with more than 30 service years is eligible for rule 2.

2. Everyone older than 60, with less than 30 years of service are also eligible.

Rule 2
U Employee age of Employee service years of Employee Employee is eligible for r2
1 - - >= 30 Yes
2 - >= 60 < 30 Yes

Rule

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 5 extra days.

Again, the `U` table suits our needs perfectly. We ignore the last sentence of the rule, as we can implement this later. The rows in the following table can be translated as such:

1. Everyone younger than 45 with at least 15 but at maximum 30 service years is eligible.

2. Everyone older than 45 is also eligible.

Rule 3
U Employee age of Employee service years of Employee Employee is eligible for r3
1 - < 45 [15, 30) Yes
2 - > 45 - Yes

Now all that we need to do is add all the days of every applicable rule together, and count them in a `C+` table. This table evaluates every row, and sums together the outputs of the satisfied rows. Here we express in row 4 that the 2 days of rule 3 are only counted if the employee is not eligible for rule 1.

Vacation days of Employee
C+ Employee Employee is eligible for r1 Employee is eligible for r2 Employee is eligible for r3 vacation days of Employee
1 - - - - 22
2 - Yes - - 5
3 - - Yes - 3
4 - No - Yes 2

To now check the amount of vacation days our employees get, we can insert a data table containing their information, and run the solver.

Employee Info
D Employee age of Employee service years of Employee
1 Huey 17 1
2 Dewey 70 31
3 Louie 35 16
4 Donald 46 10

This gives us the following solution:

```Model 1
==========
vacation_days_of_Employee := {Huey->30, Dewey->30, Louie->27, Donald->27}.
age_of_Employee := {Huey->17, Dewey->70, Louie->35, Donald->46}.
service_years_of_Employee := {Huey->1, Dewey->31, Louie->16, Donald->10}.

Elapsed Time:
0.853
```