# Team optimization with constraints

I am trying to solve the following problem of working teams rearrangement. I have 100 teams, each with a different fixed number of members. For each team I have a set of value that represent the number of people with a specific role needed to complete the team (e.g.: Team 1 needs 5 people with Role 1 and 8 with Role 2).

|    Team    |   Role  1  |   Role  2 |  Role  3 |  members  |
|------------|------------|-----------|----------|-----------|
|      1     |      5     |     8     |     0    |    13     |
|      2     |      0     |     5     |     6    |    11     |
|      3     |      6     |     0     |     6    |    12     |
...


I also have 1500 workers, and for each worker I know its current team, its role and his skill levels

|  Worker id |    Role    |   Skill 1  |  Skill 2  |  Skill 3 |
|------------|------------|------------|-----------|----------|
|      1     |      1     |      7     |     7     |     5    |
|      2     |      2     |      4     |     8     |     0    |
|      3     |      2     |      6     |     8     |     3    |
|      4     |      3     |      6     |     0     |     6    |
|      5     |      3     |      9     |     0     |     0    |
...


What I would like to obtain is the optimal teams composition that minimize the average skill level difference between the teams, with the additional constraint of moving only workers with the same role between teams. I am calculating the average skill level as the average of all the skills of all of the team's workers. I need a little help to translate these constraints in a mathematical form, specifically the one about the "same role", so that I could use something like constraint programming (MiniZinc or such) to get the solution. Thanks in advance.

• How do you define the skill level difference between two teams? How do you "average" these skill level differences? – hardmath Jun 4 '18 at 14:25
• The difference in absolute value could be ABS( avg_team_1 - avg_team_2), where avg_team_1 is calculated summing all the skills level for the workers in team 1 and dividing by the number of skills in that team (so if I have 2 workers with 3 skills I sum all their skills and divide the result by 6). Same for avg_team_2. Instead of calculatiing differences in average between all teams I guess I could sum all the teams'averages and have that total maximized. (maybe it is easier) – m.piras Jun 5 '18 at 10:27
• Can workers change roles during a move? If yes, are skill values the same regardless of role (so all workers are equally useful in all roles)? If workers cannot change roles, what do you mean by "the additional constraint of moving only workers with the same role between teams"? – prubin Jun 5 '18 at 18:42
• They cannot change roles if they move. For example, if I have two developers and a PM in a team, i can switch the PM only with a PM from another team and the developers with other developers. – m.piras Jun 6 '18 at 9:40