Wording as a general optimization problem
It will be useful to formalize restrictions and parameters. Suppose that for 1 <= i <= 8 we have numbers n_i of size i. Now let's impose a strict restriction, which in a particular room S, every two students a, b \ in S, we have the following:
|Grade(a) - Grade(b)| <= 2 (1)
Now we are interested in optimizing the “diversity” function, which intuitively introduces the idea that we want the rooms to be as mixed as possible. Therefore, we can present this goal as:
max over all arrangements {{ Sum over all rooms S of DiversityScore(S) }} where we have DiversityScore(S) =
Wording as a graph problem
This is the most common setting, but obviously max on all devices is not feasible. Now we pose this as a graph problem with tight restrictions. We designate all students as a vertex in column G. Connect two vertices if the students satisfy restriction (1). Now a click on this graph represents a group of students who can be placed in one room. Now go on eagerly. Select the largest click of size 4, which has the largest measure of diversity. Then place them in the room and continue until all the rooms are full. This click search method may also include gender restrictions, which are useful, but not that click search is a difficult NP task.
Now, before trying to come up with something that can be faster, let's think about how to relax the tight constraint (1). We can massage our graph shape by including the edges of the weight in the image. Thus, if a strict restriction is met, we denote the weight of the edge from i to j as 1. If two students i and j deviate in age more than 2, this means that the weight of the edge is 1 / (age difference) ^ 2 or something like that. Then the click estimate should be the product of crossing with clicks with a certain amount of points. However, it becomes clear that now the problem lies in the full schedule, which is only a general optimization, which we hoped to avoid, so we need to impose some strict restrictions to reduce the connectivity of our schedule.
Basic Sort Approximation Algorithm
Sort all students by their age, so we have a sorted array in which all students from [i] are the same age, and all students in [i] are older than all students in [j] for all j <i. Now consider each pair i, j from which there exists O (n ^ 2), where we also have that | Age [i] - Age [j] | <= 2. Find the largest group of students of different nationalities and place them in the room together. We sequentially iterate over pairs of indexes O (n ^ 2), which satisfy a strict restriction and take all students with a difference in nationality (which we can find by preprocessing and hashing on pairs of indexes). By doing this carefully (for example, looking at the indices i j that are scattered before they are close to each other), further improving the runtime. It seems like it should be polytime, but I think there are some subtleties that need to be addressed first before saying this.