def test_remove_covers(matrix_for_tests): """ Test that the remove covers function resets all appropriate vectors to have all entries False and that marked contain only zeros """ munkres = _hungarian.Munkres(matrix_for_tests) munkres.col_saturated += True munkres.row_saturated += True munkres.marked += True munkres.row_marked += True munkres.col_marked += True assert_array_equal(munkres.marked, np.ones((3, 4), dtype=bool)) assert_array_equal(munkres.col_saturated, np.array([True, True, True, True], dtype=bool)) assert_array_equal(munkres.row_saturated, np.array([True, True, True], dtype=bool)) assert_array_equal(munkres.col_marked, np.array([True, True, True, True], dtype=bool)) assert_array_equal(munkres.row_marked, np.array([True, True, True], dtype=bool)) munkres._remove_covers() assert_array_equal(munkres.marked, np.zeros((3, 4), dtype=bool)) assert_array_equal(munkres.col_saturated, np.array([False, False, False, False], dtype=bool)) assert_array_equal(munkres.row_saturated, np.array([False, False, False], dtype=bool)) assert_array_equal(munkres.col_marked, np.array([False, False, False, False], dtype=bool)) assert_array_equal(munkres.row_marked, np.array([False, False, False], dtype=bool))
def test_maximal_matching_matrix_adjustment_minimize_option(matrix_for_tests): """ Test that _maximal_matching method correctly subtracts the smallest element of each row from every element in the same row """ munkres = _hungarian.Munkres(-matrix_for_tests) munkres._maximal_matching() matrix = np.array([[0, 5, 3, 5], [3, 1, 0, 4], [0, 0, 2, 0]], dtype=float) assert_array_equal(munkres.matrix, matrix)
def test_row_col_saturated_maximal_matching_maximize_option(matrix_for_tests): """ Test that the computation of a maximal matching for the 0-induced graph correctly labels the appropriate row and column vertices as saturated """ munkres = _hungarian.Munkres(matrix_for_tests, maximize=True) munkres._maximal_matching() assert_array_equal(munkres.row_saturated, np.array([True, True, True], dtype=bool)) assert_array_equal(munkres.col_saturated, np.array([True, True, True, False], dtype=bool))
def test_munkres_init_matrix_negation_maximize_option(matrix_for_tests): """Test that on initialization, all entries of cost matrix are negated""" munkres = _hungarian.Munkres(matrix_for_tests, maximize=True) matrix = np.array([[-5, 0, -2, 0], [-1, -3, -4, 0], [-2, -2, 0, -2]], dtype=float) assert_array_equal(munkres.matrix, matrix)