I need to write a program that sorts people into groups.
To give a little context: The aim of the program is to create an equitable distribution of tasks and people for a school trip. Every day the groups are reshuffled and each group is assigned a task (cleaning, cooking, ...). So far, we have put the groups together randomly by drawing items from a bag. But every year the students complain if they are never in the same group as their friends or if they always have the task "cleaning". So I had the idea to develop a small program that solves this problem by dividing the students into groups where the people and tasks are evenly distributed.
The following specifications are requested:
- We have a total of x people.
- The people will be divided into y groups.
- There are z days. On each day, the groups are mixed so that ideally, after all days, each person has been in a group with every other person at least once. The distribution should be even, i.e. everyone shares a group with every other person about the same number of times.
- There are as many tasks as there are groups. For each day, each group is assigned one of these tasks. After all days, each person should have had each task about the same number of times.
Now about the algorithm. I think a solution to the "Social golfer problem" (www.mdpi.com/2073-8994/13/1/13) might be a way to sort people into groups. But since there is the additional requirement of Tasks (people equally distributed among all groups), I really don't know how to approach this problem. After a bit of googling "Kirkman's Schoolgirl Problem" and "The Running Dinner Problem" were some other keywords that popped up. Maybe that can be helpful?
If someone has a hint or even a full algorithm I would be very happy! Thank you!
Some thoughts:
Though I don't have a solution, here's some (nearly) equivalent problem statements, in case the alternative perspectives are useful. If you can solve any of these, then that solution can be translated into a solution for your original problem.
Each string represents the sequence of tasks that a particular student does through the trip (with position corresponding to day). One solution direction would be to generate all distinct strings where every character occurs either $\left\lfloor \frac{z}{y} \right\rfloor$ or $\left\lceil \frac{z}{y} \right\rceil$ times, then look for an $x$-sized subset that minimizes the gap between the most and least number of overlaps between any two strings, while ensuring least overlap is always non-zero.
If a student is present in cell $(i,j)$, then they are assigned task $j$ on day $i$. For example, starting from $(1,1)$ with value $1$, if you increment position by $y+1$ each day, then you will cycle through all the columns over $y$ days. Though the next increment would cause the student to skip row $y+1$, so a simple constant increment probably won't work.
And because I was in the mood, a more mathematical version of the above.
And some other perspectives I haven't fleshed out,
Distributing Balls: Distribute $xz$ balls, evenly colored by $x$ colors, into a $z \times y$ grid of boxes such that ...
Set of Points: Construct $S \subset [1, x] \times [1, y] \times [1, z]$, with $|S| = xz$, such that ...
Graph Theory: Construct a graph with $zy$ vertices and $x(z-1)$ edges, with $z-1$ edges of a different color/weight forming $x$ paths by color/weight, such that ...