Пример #1
0
def test_mz_small_problem():
    with open('tests/data/sc_6_1') as f:
        problem = parse_problem(f.read())

        solution = minimum_set_cover_mz(problem)

        assert Cover(2, [problem.sets[i] for i in [4, 5]]) == solution
Пример #2
0
def test_cover_really_covers_universe(problem):
    cover = minimum_set_cover_mz(problem)

    assert (
        items_covered_by(cover)
        ==
        problem.universe
    )
Пример #3
0
def test_mz_larger_problem():
    with open('tests/data/sc_1000_11') as f:
        problem = parse_problem(f.read())

        solution = minimum_set_cover_mz(problem)

        assert Cover(146, [
            problem.sets[i] for i in [
                0, 1, 2, 4, 5, 6, 7, 10, 11, 12, 13, 16, 19, 20, 21, 23, 24,
                25, 26, 28, 33, 35, 43, 46, 47, 50, 53, 59, 60, 61, 63, 70, 77,
                83, 102, 104
            ]
        ]) == solution
Пример #4
0
def test_cover_is_maximal(problem):
    cover = minimum_set_cover_mz(problem)

    assert all(
        items_covered_by(cover, minus=s) != problem.universe
        for s in cover.sets)
Пример #5
0
def test_cover_cost_matches_sum_of_chosen_set_costs(problem):
    cover = minimum_set_cover_mz(problem)

    assert cover.cost == sum(s.cost for s in cover.sets)
Пример #6
0
def test_cover_consists_of_sets_we_started_with(problem):
    cover = minimum_set_cover_mz(problem)

    assert all(s in problem.sets for s in cover.sets)