[Solved] Algorithm to group people based on their preference


One way to solve this is to use integer linear programming.
There are many solvers out there for ILP, for example SCIP (http://scip.zib.de/).

You would have binary variable for each assigment, i.e.
xij = 1 if person i was assigned to table j (and 0 is it was not assigned).

Your goal is to maximize total happiness, i.e. sum of weights multiplied by xij

Now you have write some conditions to ensure, that:

  • each person is assigned to exactly one table, i.e. sum of xij for each i is equal to one.
  • all tables have similar number of persons (you can determine possible ranges for number of persons beforehand), i.e. some of xij for each j is in defined range.

3

solved Algorithm to group people based on their preference