#NEWLINE# def linear_assignment( X ) : #NEWLINE# #INDENT# 'Solve the linear assignment problem using the Hungarian algorithm.\n\n    The problem is also known as maximum weight matching in bipartite graphs.\n    The method is also known as the Munkres or Kuhn-Munkres algorithm.\n\n    Parameters\n    ----------\n    X : array\n        The cost matrix of the bipartite graph\n\n    Returns\n    -------\n    indices : array,\n        The pairs of (row, col) indices in the original array giving\n        the original ordering.\n\n    References\n    ----------\n\n    1. http://www.public.iastate.edu/~ddoty/HungarianAlgorithm.html\n\n    2. Harold W. Kuhn. The Hungarian Method for the assignment problem.\n       *Naval Research Logistics Quarterly*, 2:83-97, 1955.\n\n    3. Harold W. Kuhn. Variants of the Hungarian method for assignment\n       problems. *Naval Research Logistics Quarterly*, 3: 253-258, 1956.\n\n    4. Munkres, J. Algorithms for the Assignment and Transportation Problems.\n       *Journal of the Society of Industrial and Applied Mathematics*,\n       5(1):32-38, March, 1957.\n\n    5. https://en.wikipedia.org/wiki/Hungarian_algorithm\n    ' #NEWLINE# indices = _hungarian ( X ) . tolist ( ) #NEWLINE# indices . sort ( ) #NEWLINE# indices = np . array ( indices , dtype = int ) #NEWLINE# indices . shape = ( ( - 1 ) , 2 ) #NEWLINE# return indices