Search code examples
algorithmoptimizationgraphbipartite

optimization of bipartite graph


There are two sets one containing list of classes and other contains list of teachers.Each teacher has a set of classes.We have to assign a teacher for a particular class such a way that number of classes engaged by teachers should be maximum.Is this problem is related to any optimization algorithm?I couldn't find any similar algorithms.Please help me to get the logic.

Thanks in advane


Solution

  • This is a maximal matching problem that is solveable efficiently in bipartite graphs using maximal flow algorithms.

    The reduction to the maximal flow is simple:

    • Let your original graph be (V,U,E) [where V,U are the edges - one for 'classes' and one for 'teachers' - the direction is teacher->class].
    • Create a new graph G', with additional two vertices: s,t.
    • Connect s to all teachers, and connect all classes to t.
    • Give capacity of 1 for each edge in the new graph.
    • Run maximal flow algorithm, that returns integer result (since the capacities are integers, it can be done).
    • (profit)