2

I have employees and matrix with ranks how are they working with each other with the results from 0 to 10. I have to select groups with two people and give them work. The problem is I don't know how should I choose groups that sum up group works will be the highest.

   A  B  C  D
A  -  3  10 3
B  3  -  0  3
C  10 0  -  3 
D  3  3  3  -

For the given example, it would be <A,C>,<B,D> _ 10 + 3 = 13

ashchk
  • 161
  • 13
  • 1) What have you tried? 2) Do you always have a total of 4 people to be split into 2 groups of 2 people, or do you have different values for the number of groups and the number of people per group? – Stef Sep 07 '20 at 13:38
  • I have an N number of employees and I would like to combine them in a group of two people each one. – Gevorg Harutyunyan Sep 07 '20 at 13:40
  • I would like to choose those groups in which the company will work in a better way – Gevorg Harutyunyan Sep 07 '20 at 13:41
  • If the number of groups and people per group are very small, you can just bruteforce the problem: list all possible combinations, calculate the score for each combination, and keep the combination with highest score. In the case of 2 groups of 2 people, there are only 3 different combinations up to symmetries, and only 24 combinations if you blindly enumerates all the groups as `(AB)(CD), (AB)(DC), (AC)(BD), (AC)(DB), (AD)(BC), ...`. Those are extremely small numbers! – Stef Sep 07 '20 at 13:41
  • How big is the number `N`? – Stef Sep 07 '20 at 13:42
  • Yes but I assume that company size could be more than 10000 – Gevorg Harutyunyan Sep 07 '20 at 13:42
  • Please add those details (groups of 2 people, total of N people, N could be more than 10000) to the question. – Stef Sep 07 '20 at 14:28

3 Answers3

2

This is maximum weight matching in a non-bipartite graph. The classical polynomial-time algorithm is the Blossom algorithm due to Jack Edmonds. Integer programming will also work in a pinch.

David Eisenstat
  • 64,237
  • 7
  • 60
  • 120
1

You are trying to solve the Maximum Weight Matching problem.

Wikipedia links to a paper and a C++ implementation by Vladimir Kolmogorov: http://pub.ist.ac.at/~vnk/papers/BLOSSOM5.html

Stef
  • 13,242
  • 2
  • 17
  • 28
1

@David and @Stef thanks for your help. I solved the problem using Kolmogorov's algorithm.
I used algorithm implementation from the JGraphT library. In case if someone is interested here is the link to the project. https://github.com/CGevorg/Employee_Matcher