def is_claw_free(G):
    """Returns True if *G* is claw-free, and False otherwise.

    A graph is *claw-free* if it contains no induce subgraph isomorphic to the
    star on four vertices.

    Parameters
    ----------
    G : NetworkX graph
        An undirected graph.

    Returns
    -------
    boolean
        True if *G* is claw-free, and False otherwise.

    Examples
    --------
    >>> G = gp.complete_graph(4)
    >>> gp.is_claw_free(G)
    True
    >>> G = gp.star_graph(4)
    >> gp.is_claw_free(G)
    False
    """
    # define a claw graph, also known as the complete bipartite graph K_1,3
    claw = gp.star_graph(3)

    # enumerate over all possible combinations of 4 vertices contained in G
    for S in set(itertools.combinations(G.nodes(), 4)):
        H = G.subgraph(list(S))
        if gp.is_isomorphic(H, claw):
            return False
    # if the above loop completes, the graph is claw-free
    return True
Example #2
0
def test_adjacent_vertices_of_star_is_not_independent_set():
    G = gp.star_graph(3)
    assert gp.is_independent_set(G, [0, 1]) is False
    assert gp.is_independent_set(G, [0, 2]) is False
Example #3
0
 def test_connected_zero_forcing_number_of_monster_is_4(self):
     G = gp.star_graph(3)
     G.add_edge(3, 4)
     G.add_edge(3, 5)
     assert gp.connected_zero_forcing_number(G) == 4
Example #4
0
 def test_leaf_is_max_degree_minus_one_forcing_set_for_star(self):
     for i in range(3, 13):
         G = gp.star_graph(i)
         D = gp.max_degree(G)
         assert gp.is_k_forcing_set(G, [1], D - 1) == True
Example #5
0
 def test_non_integral_value_for_k_raises_TypeError_in_is_k_forcing(self):
     with pytest.raises(TypeError):
         G = gp.star_graph(2)
         gp.is_k_forcing_vertex(G, 1, [1], 1.5)
Example #6
0
 def test_center_of_star_is_not_zero_forcing_active_set(self):
     G = gp.star_graph(2)
     assert gp.is_zero_forcing_active_set(G, [0]) == False
Example #7
0
 def test_center_of_S3_is_not_2_forcing_vertex(self):
     G = gp.star_graph(3)
     assert gp.is_k_forcing_vertex(G, 0, [0], 2) == False
Example #8
0
 def test_no_vertex_is_zero_forcing_vertex_for_empty_set(self):
     G = gp.star_graph(2)
     assert gp.is_zero_forcing_vertex(G, 0, set()) == False
     assert gp.is_zero_forcing_vertex(G, 1, set()) == False
     assert gp.is_zero_forcing_vertex(G, 2, set()) == False
Example #9
0
 def test_zero_value_for_k_raises_ValueError(self):
     with pytest.raises(ValueError):
         G = gp.star_graph(2)
         gp.sub_k_domination_number(G, 0)
Example #10
0
def test_matching_number_of_star_is_1():
    for i in range(1, 11):
        G = gp.star_graph(i)
        assert gp.matching_number(G, method="bf") == 1
        assert gp.matching_number(G, method="ilp") == 1
Example #11
0
def test_min_maximal_matching_number_of_star_is_1():
    for i in range(1, 11):
        G = gp.star_graph(i)
        assert gp.min_maximal_matching_number(G) == 1
Example #12
0
def test_independence_number_of_star_is_order_minus_1():
    for i in range(1, 10):
        G = gp.star_graph(i)
        assert gp.independence_number(G, method="bf") == G.order() - 1
        assert gp.independence_number(G, method="ilp") == G.order() - 1
Example #13
0
def test_center_and_two_leaves_of_star_is_not_2_independent_set():
    G = gp.star_graph(3)
    assert gp.is_independent_set(G, [0, 1, 2]) is False
Example #14
0
def test_set_of_leaves_of_star_is_2_independent_set():
    for i in range(2, 10):
        G = gp.star_graph(i)
        ind_set = set(j for j in range(1, i + 1))
        assert gp.is_k_independent_set(G, ind_set, 2) is True
Example #15
0
 def test_leaf_is_zero_forcing_vertex_for_star(self):
     G = gp.star_graph(2)
     assert gp.is_zero_forcing_vertex(G, 1, [1]) == True
Example #16
0
 def test_integral_float_for_k_works(self):
     G = gp.star_graph(2)
     assert gp.sub_k_domination_number(G, 1.0) == 1
Example #17
0
 def test_center_is_not_zero_forcing_vertex_for_star(self):
     G = gp.star_graph(2)
     assert gp.is_zero_forcing_vertex(G, 0, [0]) == False
Example #18
0
 def test_non_integral_value_for_k_raises_TypeError(self):
     with pytest.raises(TypeError):
         G = gp.star_graph(2)
         gp.sub_k_domination_number(G, 1.5)
Example #19
0
 def test_center_of_S3_is_3_forcing_vertex(self):
     G = gp.star_graph(3)
     assert gp.is_k_forcing_vertex(G, 0, [0], 3) == True
Example #20
0
 def test_annihilation_number_of_star_is_order_minus_1(self):
     for i in range(2, 11):
         G = gp.star_graph(i)
         assert gp.annihilation_number(G) == G.order() - 1
Example #21
0
 def test_leaf_of_star_is_zero_forcing_active_set(self):
     G = gp.star_graph(2)
     assert gp.is_zero_forcing_active_set(G, [1]) == True
Example #22
0
 def test_0_value_for_k_raises_ValueError_in_is_k_forcing(self):
     with pytest.raises(ValueError):
         G = gp.star_graph(2)
         gp.is_k_forcing_vertex(G, 1, [1], 0)
Example #23
0
 def test_empy_set_is_not_zero_forcing_active_set(self):
     G = gp.star_graph(2)
     assert gp.is_zero_forcing_active_set(G, set()) == False
Example #24
0
 def test_non_int_value_for_k_raises_error_in_connected_k_forcing_num(self):
     with pytest.raises(TypeError):
         G = gp.star_graph(2)
         gp.connected_k_forcing_number(G, 1.5)
Example #25
0
 def test_leaf_is_not_zero_forcing_set_of_S3(self):
     G = gp.star_graph(3)
     assert gp.is_zero_forcing_set(G, [1]) == False
Example #26
0
 def test_0_value_for_k_raises_error_in_connected_k_forcing_num(self):
     with pytest.raises(ValueError):
         G = gp.star_graph(2)
         gp.connected_k_forcing_number(G, 0)
Example #27
0
 def test_zero_forcing_number_of_star_is_order_minus_2(self):
     for i in range(2, 12):
         G = gp.star_graph(i)
         assert gp.zero_forcing_number(G) == G.order() - 2
Example #28
0
 def test_integral_float_for_k_works(self):
     G = gp.star_graph(2)
     assert gp.is_k_forcing_vertex(G, 1, [1], 1.0) == True
Example #29
0
 def test_non_int_value_for_k_raises_error_in_is_connected_k_forcing(self):
     with pytest.raises(TypeError):
         G = gp.star_graph(2)
         gp.is_connected_k_forcing_set(G, [0], 1.5)
 def test_center_node_is_power_dominating_set_of_star(self):
     for i in range(1, 11):
         G = gp.star_graph(i)
         assert gp.is_power_dominating_set(G, [0]) == True