My Problem
I am quite new to optimisation, so any advice is appreciated. I am currently trying to solve a problem as follows:
Given a pool of people, we want to create n teams such to find the optimal solution based on all players' preferences
As a test, I have been assuming there are 6 players, each of which selects a 1st and a 2nd preference for who they would like in their team. For now, I am looking to create 2 teams of 3 players.
How I have attempted it
I want to solve this using an open-source solver in Python, so I am currently trying the 'glpk' solver via Pyomo, however I am stuck. I created a matrix of preferences, whereby each row represents a given player's top 2 preferences (here, 2 means 1st pick) as follows:
preferenceMatrix = [0 1 0 0 2 0] # Player 1 would like players 5 (1st pick) and 2 (2nd pick)
[2 0 1 0 0 0] # Player 2 would like players 1 (1st pick) and 3 (2nd pick)
[0 0 0 0 2 1] # Player 3 would like players 5 (1st pick) and 6 (2nd pick)
[0 1 2 0 0 0] # Player 4 would like players 3 (1st pick) and 2 (2nd pick)
[0 0 0 1 2 0] # Player 5 would like players 5 (1st pick) and 4 (2nd pick)
[2 0 0 1 0 0] # Player 6 would like players 1 (1st pick) and 4 (2nd pick)
Next, I multiply the preference matrix by a binary matrix (subject to a constraint of 2 players per row and column), and then maximise the sum over the entire matrix. An example of what the binary matrix could look like is:
binaryMatrix = [0 1 1 0 0 0]
[1 0 1 0 0 0]
[1 1 0 0 0 0]
[0 0 0 0 1 1]
[0 0 0 1 0 1]
[0 0 0 1 1 0]
This would form 2 teams: Team 1) players 1,2,3, and Team 2) players 4,5,6 and the objective function (summing over rows) would be 1+3+0+0+1+1 = 6.
My questions
1) If I continue with this approach, then how could I constrain it to create exactly 2 teams? I originally posted this exact issue here
2) As I am finding it hard to approach the problem using glpk, is there a more appropriate open-source solver I could use instead?
3) Or, could I approach this entirely differently (e.g. using networkx where I specify that the problem should create 2 equal-sized connected groups)?