Recently my mother came to me with a problem that I found pretty interesting. She manages a childcare center and it turns out that as surprising as it might sounds, it happens that the children need to take a nap once a day. To do so, the staff members need to assign a bed to each child, nothing to fancy up to there. Now come the tricky part. In France there are basically two kinds of childcare center the crèche that accept children on a permanent basis and halte-garderie that is designed for parents that do not work full time (or at least not a 9 to 5 job) and need someone to look after their children only a couple of times a week. My mother works in a halte-garderie, so they basically have less beds available than the total number of children they are going to receive during a week. The point is that they want the children to take their naps in the same bed each time they are at the childcare center (so that they can more easily take their cues).

As the same bed is likely to be used by several children during the week, the question to answer is: in which bed should a child sleep when he is spending the day in the childcare center?

There are some additional constraints :

1/ Some children have to sleep in contiguous beds (for example when they have twins they do not want to split them)

2/ Some children must not sleep in contiguous beds (for example because they cannot stop talking when they are close one to the other, and they would therefore be annoying for all the other children wanting to sleep)

3/ Each child is under the responsibility of one staff member. In order to avoid the staff members spending their time to run from one side of the room to the other, all children assigned to one staff member have to sleep in beds that are close together.

As in some cases, it may be impossible to find an assignment in which each child can keep the same bed all week long, we consider that the objective function is to minimize the number of bed changes.

As the problem faced in the childcare run by my mother is fairly small (about 30 children and 12 beds) I thought it could be interesting to try out an exact approach. Here is the model I came out with :

First let me introduce some notations:

is a binary variable indicating if child i spends at least one nap in bed j

is a binary variable indicating if child i spends the nap of the day k in bed j

is the set of children that are incompatible with child i

is the set of children that must be in a bed near child i

is the set of staff member

is the set of the children

is the set of the beds

is the set of the days of the week

is the set of days child c is present at the childcare center

is the set of children that are the responsibility of staff s

is the distance between beds and . The distance between two beds is 1 if the beds are neighboring beds, 2 if there is 1 bed between them, 3 if there are 2 beds between them…

We try to minimize the objective function

under the following set of constraints

(1)

(2)

(3)

(4)

(5)

(6)

(7)

The model is structured in the following way : Constraints (1) state that each time a child is here, he must be assigned to a bed. Constraints (2) forbid that more than one child sleep in the same bed the same day. Constraints (3) guarantee that a bed can only be used on a given day by a kid if the variable stating that the bed is used at least once in the week take value 1. Constraints (4) state that when he is not there a child is not assigned to any bed. Constraints (5) and (6) guarantee that incompatibility and proximity constraints are respected. Constraints (7) ensure that the children that are the responsibility of the same staff member are sleeping close together.

For those of you that are interested, the code of the model (in python, using the PuLP library for the mathematical modeling and GLPK to solve the MIP) as well as a toy instance are available on bitbucket (https://bitbucket.org/renaud_masson/bed-assignment). The solving time for this small instance using GLPK as a solver is a couple seconds while it previously took several hours to manually design the assignment of the children to the beds for “real-life” instances of similar size.

Feel free to post any comments or proposition for model enhancement 😉