hungarian

class libra_py.hungarian.TestHungarian(methodName='runTest')[source]
test_maximize()[source]

Tests the reordering algorithm

test_minimize()[source]

Tests the reordering algorithm

libra_py.hungarian.maximize(_X, verbosity=0)[source]

Minimize the negative of the original matrix

We also need to shift the negative matrix up rigidly, so all its elements are > 0.0

libra_py.hungarian.step1(X)[source]

For each row of the matrix, find the smallest element and subtract it from every element in its row. Go to Step 2.

libra_py.hungarian.step2(X, M, Rcov, Ccov)[source]

Find a zero (Z) in the resulting matrix. If there is no starred zero in its row or column, star Z. Repeat for each element in the matrix. Go to Step 3.

libra_py.hungarian.step3(M, Ccov)[source]

Cover each column containing a starred zero. If K columns are covered, the starred zeros describe a complete set of unique assignments. In this case, Go to DONE, otherwise, Go to Step 4.

libra_py.hungarian.step4(X, M, Rcov, Ccov)[source]

Find a noncovered zero and prime it. If there is no starred zero in the row containing this primed zero, Go to Step 5. Otherwise, cover this row and uncover the column containing the starred zero. Continue in this manner until there are no uncovered zeros left. Save the smallest uncovered value and Go to Step 6.

libra_py.hungarian.step5(M, path_row_0, path_col_0, Rcov, Ccov)[source]

Construct a series of alternating primed and starred zeros as follows. Let Z0 represent the uncovered primed zero found in Step 4. Let Z1 denote the starred zero in the column of Z0 (if any). Let Z2 denote the primed zero in the row of Z1 (there will always be one). Continue until the series terminates at a primed zero that has no starred zero in its column. Unstar each starred zero of the series, star each primed zero of the series, erase all primes and uncover every line in the matrix. Return to Step 3.

libra_py.hungarian.step6(X, Rcov, Ccov)[source]

Add the value found in Step 4 to every element of each covered row, and subtract it from every element of each uncovered column. Return to Step 4 without altering any stars, primes, or covered lines.