Exemple #1
0
def test_bipartition_tree_returns_within_epsilon_of_target_pop(graph_with_pop):
    ideal_pop = sum(graph_with_pop.nodes[node]["pop"] for node in graph_with_pop) / 2
    epsilon = 0.25
    result = bipartition_tree(graph_with_pop, "pop", ideal_pop, epsilon, 10)

    part_pop = sum(graph_with_pop.nodes[node]["pop"] for node in result)
    assert abs(part_pop - ideal_pop) / ideal_pop < epsilon
Exemple #2
0
def test_bipartition_tree_returns_a_tree(graph_with_pop):
    ideal_pop = sum(graph_with_pop.nodes[node]["pop"]
                    for node in graph_with_pop) / 2
    tree = networkx.Graph([(0, 1), (1, 2), (1, 4), (3, 4), (4, 5), (3, 6),
                           (6, 7), (6, 8)])
    for node in tree:
        tree.nodes[node]["pop"] = graph_with_pop.nodes[node]["pop"]

    result = bipartition_tree(graph_with_pop, "pop", ideal_pop, 0.25, 10, tree,
                              lambda x: 4)

    assert networkx.is_tree(tree.subgraph(result))
    assert networkx.is_tree(
        tree.subgraph({node
                       for node in tree if node not in result}))
Exemple #3
0
def test_bipartition_tree_returns_a_subset_of_nodes(graph_with_pop):
    ideal_pop = sum(graph_with_pop.nodes[node]["pop"]
                    for node in graph_with_pop) / 2
    result = bipartition_tree(graph_with_pop, "pop", ideal_pop, 0.25, 10)
    assert isinstance(result, set)
    assert all(node in graph_with_pop.nodes for node in result)