1
$\begingroup$

Suppose there are three categories of people. Type X, Type Y, Type Z. In each type, there are two objects of subtype Type 'a' and type 'b'.

For example.

X: a1 , a2 , b1 , b2

Y: a3 , a4 , b3 , b4

Z: a5 , a6 , b5 , b6

Each object of type 'a' should be assigned with an object of type 'b'. But it is desirable not necessary to assign a type 'a' with type 'b' from different classes (X, Y, Z).

In this example, the optimal solution would be: a1 with b5 , a2 with b6 , a3 with b1 , a4 with b2 , a5 with b3 , a6 with b4 .

Non -optimal solution would be :

a1 with b5 , a2 with b6 , a5 with b1 , a6 with b2 , a3 with b3 , a4 with b4 .

(Non -optimal because a3 and a4 are assigned with b's of same type Y)

If we generalize, there can be n- number of Types (X,Y,Z, .....and so on) with different number of a's and b's in each (but total number of a's = total number of b's).

How to find an optimal solution?

$\endgroup$
3
  • $\begingroup$ How do you measure "optimality"? Is it the number of matches between two objects of a different type? Do you require that all objects be matched? Can you state the task a bit more precisely? $\endgroup$
    – D.W.
    Commented Mar 26, 2021 at 19:46
  • $\begingroup$ @D.W. yes, optimality is the number of matches between two objects of a different type. $\endgroup$ Commented Mar 26, 2021 at 21:23
  • $\begingroup$ and yes, all objects have to be matched. $\endgroup$ Commented Mar 26, 2021 at 21:23

1 Answer 1

1
$\begingroup$

This problem reduces to finding a maximum matching in a bipartite graph, which can be done easily by e.g. the Ford-Fulkerson algorithm. You construct the graph as follows:

Take all elements of type $a$ on one side and all elements of type $b$ on the other. Then, for any two elements $a_i,b_j$, draw an edge between them if they do not belong to the same category.

If there is a matching in the set with only, say, $k$ pairs belonging to the same category, then we can find a matching in our graph on $m-k$ edges, where $m$ is the number of a's (or b's).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.