- #1
Frank Einstein
- 170
- 1
- TL;DR Summary
- I wan to group some people based on a compatibility score. Each group has a maximum size. I must maximize the compatibility within each group
I have a matrix of dimension 56*56, each row and column represent the compatibility of one person with the rest of the people.
A sample matrix could be
Represented in python as
I want to group the people in groups of two or three people and I want to maximize the total compatibility within each group since I want them to do some teamwork.
One solution could be [Alejandro-Juan], [Ana-Ruben], [Beatriz-Luz] and [Maria-Jose]. The punctuation would be the sum of the element of the matrix corresponding to each pair. If I had chosen [Alejandro-Juan-Ana], [Ruben-Beatriz-Luz], [Maria-Jose], I would sum the scores of Alejandro-Juan, Alejandro-Ana, Juan-Ana and so on.
I have already asked this question in Stack Overflow, but the code doesn't find clusters for the real data. In reality, I must group people in groups of 8-10 people.
I have tough on using a genetic algorithm, where chromosomes are the groups of people, as an example,
However, I am clueless about how to do the crossing and the mutation.
Can someone please help me obtain a solution to this problem?
Any answer is appreciated.
Best regards and thanks for reading.
A sample matrix could be
Compatibility sample:
Alejandro Ana Beatriz Jose Juan Luz Maria Ruben
Alejandro 0.0 0.0 1000.0 0.0 1037.0 1014.0 100.0 0.0
Ana 0.0 0.0 15.0 0.0 100.0 0.0 16.0 1100.0
Beatriz 1000.0 15.0 0.0 100.0 1000.0 1100.0 15.0 0.0
Jose 0.0 0.0 100.0 0.0 0.0 100.0 1000.0 14.0
Juan 1037.0 100.0 1000.0 0.0 0.0 1014.0 0.0 100.0
Luz 1014.0 0.0 1100.0 100.0 1014.0 0.0 0.0 0.0
Maria 100.0 16.0 15.0 1000.0 0.0 0.0 0.0 0.0
Ruben 0.0 1100.0 0.0 14.0 100.0 0.0 0.0 0.0
Represented in python as
Data as dataframe:
data = {
'Alejandro': [0.0, 0.0, 1000.0, 0.0, 1037.0, 1014.0, 100.0, 0.0],
'Ana': [0.0, 0.0, 15.0, 0.0, 100.0, 0.0, 16.0, 1100.0],
'Beatriz': [1000.0, 15.0, 0.0, 100.0, 1000.0, 1100.0, 15.0, 0.0],
'Jose': [0.0, 0.0, 100.0, 0.0, 0.0, 100.0, 1000.0, 14.0],
'Juan': [1037.0, 100.0, 1000.0, 0.0, 0.0, 1014.0, 0.0, 100.0],
'Luz': [1014.0, 0.0, 1100.0, 100.0, 1014.0, 0.0, 0.0, 0.0],
'Maria': [100.0, 16.0, 15.0, 1000.0, 0.0, 0.0, 0.0, 0.0],
'Ruben': [0.0, 1100.0, 0.0, 14.0, 100.0, 0.0, 0.0, 0.0]
}
df = pd.DataFrame(
data,
index=['Alejandro', 'Ana', 'Beatriz', 'Jose', 'Juan', 'Luz', 'Maria', 'Ruben']
)
I want to group the people in groups of two or three people and I want to maximize the total compatibility within each group since I want them to do some teamwork.
One solution could be [Alejandro-Juan], [Ana-Ruben], [Beatriz-Luz] and [Maria-Jose]. The punctuation would be the sum of the element of the matrix corresponding to each pair. If I had chosen [Alejandro-Juan-Ana], [Ruben-Beatriz-Luz], [Maria-Jose], I would sum the scores of Alejandro-Juan, Alejandro-Ana, Juan-Ana and so on.
I have already asked this question in Stack Overflow, but the code doesn't find clusters for the real data. In reality, I must group people in groups of 8-10 people.
I have tough on using a genetic algorithm, where chromosomes are the groups of people, as an example,
Alejandro | Juan | Ana | Ruben | Beatriz | Luz | Maria | Jose |
1 | 1 | 1 | 2 | 2 | 2 | 3 | 3 |
1 | 2 | 3 | 1 | 2 | 3 | 1 | 2 |
However, I am clueless about how to do the crossing and the mutation.
Can someone please help me obtain a solution to this problem?
Any answer is appreciated.
Best regards and thanks for reading.