Skip to content

Slot closures

supix edited this page Apr 30, 2017 · 4 revisions

Slot closure configuration rule allows to close one or more slots in one or more days.

Closing all shifts altogether

During the timeline of a workshift you can decide to close the shifts altogether, for example in case of a public holiday. This constraint can be expressed as follows.

var problem = ProblemBuilder.Configure()
  ...
  .Closing.AllSlots().InDay(4)
  .Build();

The solution stemming from this computation resembles the one below.

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

The fifth day (index equal to 4) is completely empty.

Modulating demand for a shift

In some cases, demand for shift coverage changes during the week. For example, you might want 5 afternoons everyday but on Saturday and on Sunday. In these 2 days of week, it's enough to have only 3 afternoons to be covered. Let's assume that the 30 days start with a Monday. Thus, the Saturdays and the Sundays on the timeline have the following indexes: 5, 6, 12, 13, 19, 20, 26, 27. In these days we have to close 2 afternoon slots, e.g. 8 and 9. As always, indexes are 0-based.

Closing rules can be chained together. Then, the problem is configured as follows.

var problem = ProblemBuilder.Configure()
  ...
  .Closing.Slots().From(8).To(9)
    .InDays().From(5).To(6)
  .Closing.Slots().From(8).To(9)
    .InDays().From(12).To(13)
  .Closing.Slots().From(8).To(9)
    .InDays().From(19).To(20)
  .Closing.Slots().From(8).To(9)
    .InDays().From(26).To(27)
  .Build();

This configuration brings to a solution like this.

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

In this scheme, slots 8 and 9 are not covered on Saturdays and Sundays (identified by the column indexes written above), as requested.

Clone this wiki locally