Skip to content

Max consecutive working days

supix edited this page Apr 30, 2017 · 2 revisions

In the real world, employees don't work every day, as the previous examples would suggest. In the following example employees do not work continuously, but we force a rest after reaching a maximum number of consecutive working days. For example we can force 2 mandatory rest days after reaching 5 consecutive working days. In this case we cannot aspire to cover the scheme using as many employees as the shifts: we need more employees. More precisely, introducing the above rest contraint, employee efficiency reduces from 1 to 5/7=0,714 (5 working days over 7 total days). Therefore, we need at least (14 / 5 * 7) = 19,6 (then 20) employees to give the algorithm a chance to perfectly fill the scheme. In this example we will use just 18 employees, thus tolerating the presence of empty slots. The problem is configured as follows.

var problem = ProblemBuilder.Configure()
  .WithDays(30)
  .WithSlots(14)
  .WithItems(18)
  .AssigningLength(2).ToSlots().From(10).To(13)
  .WithMaxConsecutiveWorkingDaysEqualTo(5)
  .RestAfterMaxWorkingDaysReached(2)
  .Build();

The solving environment is configured exactly as in the previous examples.

The solution is something similar to the following.

Fitness: 0,945681869983673
Evaluated solutions: 104100
 12,  -, 12,  -, 13,  -,  8,  6, 10,  -,  5,  7,  6,  8,  2,  -,  -, 11,  -,  2, 13,  -,  7,  3,  1,  2,  3,  -,  -, 12
  9,  6,  4, 11,  -,  1,  0,  3, 11,  -,  1,  5,  9, 10,  -,  0,  1,  2,  3, 10,  -,  -,  3, 11,  -,  4,  0, 13,  -,  6
  8,  7,  5, 13,  -, 11,  -,  9,  0, 12,  -, 12,  -,  6,  5,  8, 12,  -, 10,  -, 11,  -,  6,  0,  2,  -, 11,  -, 13,  -
 13,  -,  6,  7,  1, 13,  -,  7,  9, 13,  -,  6,  2, 11,  -, 12,  -,  3,  0, 12,  -,  9,  5, 13,  -,  9,  1, 10,  -,  9
  4,  1, 10,  -,  7,  7,  7,  8, 12,  -,  -,  0,  7,  5,  8, 13,  -,  -,  8,  0,  3,  6, 12,  -,  -,  7,  9,  2, 11,  -
  5, 10,  -,  8,  4,  0,  5, 12,  -,  -,  3,  1, 11,  -, 13,  -,  5,  0, 11,  -,  8, 13,  -,  1,  7, 12,  -,  3,  5, 13
  6,  2,  9,  6,  9,  -,  -,  0,  7,  0, 13,  -,  5, 12,  -,  5,  8, 12,  -,  8,  0,  8, 10,  -,  8,  1, 10,  -, 10,  -
  -,  4,  3,  1,  6,  5,  -,  -,  2,  9,  7,  4, 10,  -,  -,  1,  4,  8,  4,  1,  -,  -,  8,  5,  5, 13,  -,  7,  4, 11
  7, 12,  -,  4, 11,  -, 12,  -,  1,  2,  6, 10,  -,  4,  1, 11,  -,  9,  5, 13,  -, 12,  -,  9,  3,  5, 13,  -,  0,  3
  0,  5,  7, 12,  -,  4, 10,  -, 13,  -,  0, 13,  -,  3,  7,  4, 10,  -,  2,  3, 10,  -,  9, 10,  -,  8,  8,  6,  3,  1
  2,  9,  8,  9,  0,  -,  -,  4,  5,  5, 12,  -,  1, 13,  -,  2,  2,  1, 12,  -,  7, 10,  -,  2,  9,  6,  6, 11,  -,  -
 10,  -, 11,  -,  5, 10,  -,  5,  4, 10,  -,  2, 13,  -,  0,  9,  6, 13,  -,  5,  4, 11,  -,  7, 10,  -,  2,  8,  8,  0
  3, 11,  -,  5,  2,  8, 13,  -,  8,  1,  4,  -,  3,  2, 11,  -, 13,  -,  1,  6,  6,  7,  0,  -,  -,  3,  5,  1,  1,  4
 11,  -,  0,  3, 10,  -,  4,  2,  3, 11,  -,  9,  8,  7, 12,  -,  3, 10,  -,  7,  1,  0, 13,  -,  6, 11,  -,  5,  7,  2
  -,  8, 13,  -,  8,  3,  6, 13,  -,  4,  9,  3,  4,  0,  -,  -,  7,  5,  6,  9,  2,  -,  -,  4,  4, 10,  -,  9,  6, 10
  -,  0,  2, 10,  -,  9,  1, 10,  -,  6,  2, 11,  -,  9,  6,  7,  9,  7,  -,  -,  5,  2,  2, 12,  -,  0,  7,  4, 12,  -
  1, 13,  -,  2,  3, 12,  -, 11,  -,  8,  8,  8, 12,  -,  9, 10,  -,  6, 13,  -,  9,  5,  1,  6, 13,  -,  -,  0,  9,  8
  -,  3,  1,  0, 12,  -,  9,  1,  6,  3, 10,  -,  -,  1, 10,  -,  0,  4,  7, 11,  -,  3,  4,  8, 12,  -,  4, 12,  -,  5

In this solution, not all slots are covered every single day, because of lack of enough employees. For example, the 10-th day the slot 7 is not covered by anyone: there is a missing employee in the afternoon's team. Anyway, slots are fairly distributed among employees, as in the previous examples.

All of the following examples will retain the policy on rest days introduced in this page.