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

    A graph is *bull-free* if it contains no induced subgraph isomorphic to the
    bull graph, where the bull graph is the complete graph on 3 vertices with
    two pendants added to two of its vertices.

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

    Returns
    -------
    boolean
        True if *G* is bull-free, false otherwise.

    Examples
    --------
    >>> G = gp.complete_graph(4)
    >>> gp.is_bull_free(G)
    True
    """
    # define a bull graph, also known as the graph obtained from the complete graph K_3 by addiing two pendants
    bull = gp.Graph([(0, 1), (0, 2), (1, 2), (1, 3), (2, 4)])

    # enumerate over all possible combinations of 5 vertices contained in G
    for S in set(itertools.combinations(G.nodes(), 5)):
        H = G.subgraph(list(S))
        if gp.is_isomorphic(H, bull):
            return False
    # if the above loop completes, the graph is bull-free
    return True
 def setup_class(self):
     G = gp.Graph()
     G.add_edge(0, 1)
     G.add_edge(0, 2)
     G.add_edge(1, 2)
     G.add_edge(0, 3)
     G.add_edge(3, 4)
     G.add_edge(3, 5)
     self.G = G
Exemple #3
0
 def setup_class(self):
     # The test graph for these functions is the simple graph obtained from
     # the disjoint union of K_3 and P_3 by joining one vertex of K_3 with
     # the degree two vertex of P_3.
     G = gp.Graph()
     G.add_edge(0, 1)
     G.add_edge(0, 2)
     G.add_edge(1, 2)
     G.add_edge(0, 3)
     G.add_edge(3, 4)
     G.add_edge(3, 5)
     self.G = G
Exemple #4
0
def test_min_conn_dominating_for_disconnected_graph_is_0():
    G = gp.Graph()
    G.add_edge(1, 2)
    G.add_edge(3, 4)
    assert gp.connected_domination_number(G) == 0