Пример #1
0
def torrents_and_ferraro_graph():
    # Graph from https://arxiv.org/pdf/1503.04476v1 p.26
    G = nx.convert_node_labels_to_integers(nx.grid_graph([5, 5]),
                                           label_attribute="labels")
    rlabels = nx.get_node_attributes(G, "labels")
    labels = {v: k for k, v in rlabels.items()}

    for nodes in [(labels[(0, 4)], labels[(1, 4)]),
                  (labels[(3, 4)], labels[(4, 4)])]:
        new_node = G.order() + 1
        # Petersen graph is triconnected
        P = nx.petersen_graph()
        G = nx.disjoint_union(G, P)
        # Add two edges between the grid and P
        G.add_edge(new_node + 1, nodes[0])
        G.add_edge(new_node, nodes[1])
        # K5 is 4-connected
        K = nx.complete_graph(5)
        G = nx.disjoint_union(G, K)
        # Add three edges between P and K5
        G.add_edge(new_node + 2, new_node + 11)
        G.add_edge(new_node + 3, new_node + 12)
        G.add_edge(new_node + 4, new_node + 13)
        # Add another K5 sharing a node
        G = nx.disjoint_union(G, K)
        nbrs = G[new_node + 10]
        G.remove_node(new_node + 10)
        for nbr in nbrs:
            G.add_edge(new_node + 17, nbr)
        # This edge makes the graph biconnected; it's
        # needed because K5s share only one node.
        G.add_edge(new_node + 16, new_node + 8)

    for nodes in [(labels[(0, 0)], labels[(1, 0)]),
                  (labels[(3, 0)], labels[(4, 0)])]:
        new_node = G.order() + 1
        # Petersen graph is triconnected
        P = nx.petersen_graph()
        G = nx.disjoint_union(G, P)
        # Add two edges between the grid and P
        G.add_edge(new_node + 1, nodes[0])
        G.add_edge(new_node, nodes[1])
        # K5 is 4-connected
        K = nx.complete_graph(5)
        G = nx.disjoint_union(G, K)
        # Add three edges between P and K5
        G.add_edge(new_node + 2, new_node + 11)
        G.add_edge(new_node + 3, new_node + 12)
        G.add_edge(new_node + 4, new_node + 13)
        # Add another K5 sharing two nodes
        G = nx.disjoint_union(G, K)
        nbrs = G[new_node + 10]
        G.remove_node(new_node + 10)
        for nbr in nbrs:
            G.add_edge(new_node + 17, nbr)
        nbrs2 = G[new_node + 9]
        G.remove_node(new_node + 9)
        for nbr in nbrs2:
            G.add_edge(new_node + 18, nbr)
    return G
Пример #2
0
def main():
    
    ### Undirected graph ###
    
    # Initialize model using the Petersen graph
    model=gmm.gmm(nx.petersen_graph())
    old_graph=model.get_base()
    model.set_termination(node_ceiling)
    model.set_rule(rand_add)
    
    # Run simualation with tau=4 and Poisson density for motifs
    gmm.algorithms.simulate(model,4)   

    # View results
    new_graph=model.get_base()
    print(nx.info(new_graph))
    
    # Draw graphs
    old_pos=nx.spring_layout(old_graph)
    new_pos=nx.spring_layout(new_graph,iterations=2000)
    fig1=plt.figure(figsize=(15,7))
    fig1.add_subplot(121)
    #fig1.text(0.1,0.9,"Base Graph")
    nx.draw(old_graph,pos=old_pos,node_size=25,with_labels=False)
    fig1.add_subplot(122)
    #fig1.text(0.1,0.45,"Simulation Results")
    nx.draw(new_graph,pos=new_pos,node_size=20,with_labels=False)
    fig1.savefig("undirected_model.png")
    
    ### Directed graph ###
    
    # Initialize model using random directed Barabasi-Albert model
    directed_base=nx.barabasi_albert_graph(25,2).to_directed()
    directed_model=gmm.gmm(directed_base)
    directed_model.set_termination(node_ceiling)
    directed_model.set_rule(rand_add)
    
    # Run simualation with tau=4 and Poisson density for motifs
    gmm.algorithms.simulate(directed_model,4)
    
    # View results
    new_directed=directed_model.get_base()
    print(nx.info(new_directed))
    
    # Draw directed graphs
    old_dir_pos=new_pos=nx.spring_layout(directed_base)
    new_dir_pos=new_pos=nx.spring_layout(new_directed,iterations=2000)
    fig2=plt.figure(figsize=(7,10))
    fig2.add_subplot(211)
    fig2.text(0.1,0.9,"Base Directed Graph")
    nx.draw(directed_base,pos=old_dir_pos,node_size=25,with_labels=False)
    fig2.add_subplot(212)
    fig2.text(0.1,0.45, "Simualtion Results")
    nx.draw(new_directed,pos=new_dir_pos,node_size=20,with_labels=False)
    fig2.savefig("directed_model.png")
    
    # Export files
    nx.write_graphml(model.get_base(), "base_model.graphml")
    nx.write_graphml(directed_model.get_base(), "directed_model.graphml")
    nx.write_graphml(nx.petersen_graph(), "petersen_graph.graphml")
Пример #3
0
def torrents_and_ferraro_graph():
    G = nx.convert_node_labels_to_integers(nx.grid_graph([5, 5]),
                                           label_attribute='labels')
    rlabels = nx.get_node_attributes(G, 'labels')
    labels = {v: k for k, v in rlabels.items()}

    for nodes in [(labels[(0, 4)], labels[(1, 4)]),
                  (labels[(3, 4)], labels[(4, 4)])]:
        new_node = G.order() + 1
        # Petersen graph is triconnected
        P = nx.petersen_graph()
        G = nx.disjoint_union(G, P)
        # Add two edges between the grid and P
        G.add_edge(new_node + 1, nodes[0])
        G.add_edge(new_node, nodes[1])
        # K5 is 4-connected
        K = nx.complete_graph(5)
        G = nx.disjoint_union(G, K)
        # Add three edges between P and K5
        G.add_edge(new_node + 2, new_node + 11)
        G.add_edge(new_node + 3, new_node + 12)
        G.add_edge(new_node + 4, new_node + 13)
        # Add another K5 sharing a node
        G = nx.disjoint_union(G, K)
        nbrs = G[new_node + 10]
        G.remove_node(new_node + 10)
        for nbr in nbrs:
            G.add_edge(new_node + 17, nbr)
        # Commenting this makes the graph not biconnected !!
        # This stupid mistake make one reviewer very angry :P
        G.add_edge(new_node + 16, new_node + 8)

    for nodes in [(labels[(0, 0)], labels[(1, 0)]),
                  (labels[(3, 0)], labels[(4, 0)])]:
        new_node = G.order() + 1
        # Petersen graph is triconnected
        P = nx.petersen_graph()
        G = nx.disjoint_union(G, P)
        # Add two edges between the grid and P
        G.add_edge(new_node + 1, nodes[0])
        G.add_edge(new_node, nodes[1])
        # K5 is 4-connected
        K = nx.complete_graph(5)
        G = nx.disjoint_union(G, K)
        # Add three edges between P and K5
        G.add_edge(new_node + 2, new_node + 11)
        G.add_edge(new_node + 3, new_node + 12)
        G.add_edge(new_node + 4, new_node + 13)
        # Add another K5 sharing two nodes
        G = nx.disjoint_union(G, K)
        nbrs = G[new_node + 10]
        G.remove_node(new_node + 10)
        for nbr in nbrs:
            G.add_edge(new_node + 17, nbr)
        nbrs2 = G[new_node + 9]
        G.remove_node(new_node + 9)
        for nbr in nbrs2:
            G.add_edge(new_node + 18, nbr)
    return G
def torrents_and_ferraro_graph():
    G = nx.convert_node_labels_to_integers(nx.grid_graph([5, 5]),
                                           label_attribute='labels')
    rlabels = nx.get_node_attributes(G, 'labels')
    labels = {v: k for k, v in rlabels.items()}

    for nodes in [(labels[(0, 4)], labels[(1, 4)]),
                  (labels[(3, 4)], labels[(4, 4)])]:
        new_node = G.order() + 1
        # Petersen graph is triconnected
        P = nx.petersen_graph()
        G = nx.disjoint_union(G, P)
        # Add two edges between the grid and P
        G.add_edge(new_node + 1, nodes[0])
        G.add_edge(new_node, nodes[1])
        # K5 is 4-connected
        K = nx.complete_graph(5)
        G = nx.disjoint_union(G, K)
        # Add three edges between P and K5
        G.add_edge(new_node + 2, new_node + 11)
        G.add_edge(new_node + 3, new_node + 12)
        G.add_edge(new_node + 4, new_node + 13)
        # Add another K5 sharing a node
        G = nx.disjoint_union(G, K)
        nbrs = G[new_node + 10]
        G.remove_node(new_node + 10)
        for nbr in nbrs:
            G.add_edge(new_node + 17, nbr)
        # Commenting this makes the graph not biconnected !!
        # This stupid mistake make one reviewer very angry :P
        G.add_edge(new_node + 16, new_node + 8)

    for nodes in [(labels[(0, 0)], labels[(1, 0)]),
                  (labels[(3, 0)], labels[(4, 0)])]:
        new_node = G.order() + 1
        # Petersen graph is triconnected
        P = nx.petersen_graph()
        G = nx.disjoint_union(G, P)
        # Add two edges between the grid and P
        G.add_edge(new_node + 1, nodes[0])
        G.add_edge(new_node, nodes[1])
        # K5 is 4-connected
        K = nx.complete_graph(5)
        G = nx.disjoint_union(G, K)
        # Add three edges between P and K5
        G.add_edge(new_node + 2, new_node + 11)
        G.add_edge(new_node + 3, new_node + 12)
        G.add_edge(new_node + 4, new_node + 13)
        # Add another K5 sharing two nodes
        G = nx.disjoint_union(G, K)
        nbrs = G[new_node + 10]
        G.remove_node(new_node + 10)
        for nbr in nbrs:
            G.add_edge(new_node + 17, nbr)
        nbrs2 = G[new_node + 9]
        G.remove_node(new_node + 9)
        for nbr in nbrs2:
            G.add_edge(new_node + 18, nbr)
    return G
 def test160_petersengraph(self):
     """ Petersen graph. """
     g = nx.petersen_graph()
     mate1 = mv.max_cardinality_matching( g )
     mate2 = nx.max_weight_matching( g, True )
     td.showGraph(g, mate1, "test160_petersengraph")
     self.assertEqual( len(mate1), len(mate2) )
Пример #6
0
def fun2():
    gNx = nx.petersen_graph()
    gDgl = dgl.DGLGraph(gNx)

    plt.subplot(121)
    nx.draw(gNx, with_labels=True)
    plt.subplot(122)
    nx.draw(gDgl.to_networkx(), with_labels=True)
    plt.show()

    g2 = dgl.DGLGraph()
    g2.add_nodes(8)

    for i in range(1, 4):
        g2.add_edge(i, 0)

    src = list(range(5, 8))
    dst = [0] * 3
    g2.add_edges(src, dst)

    draw(g2)
    # nx.draw(g2.to_networkx(), with_labels=True)
    # plt.show()

    g2.clear()
    g2.add_nodes(10)
    src = torch.tensor(list(range(1, 10)))
    g2.add_edges(src, 0)

    draw(g2)
Пример #7
0
def get_instance(r):
    g = nx.petersen_graph()
    pos = tutte_embedding(g).rpos()
    pos = {k: np.array(map(mul, v, [r, r])) for k, v in pos.items()}
    for u, v in g.edges():
        g[u][v]['weight'] = np.linalg.norm(pos[u] - pos[v])
    return g, pos
Пример #8
0
 def __init__(self, colors):
     self._graph = nx.petersen_graph()
     self._colors = colors
     self._color_map = {
         node: random.choice(self._colors)
         for node in self._graph.nodes
     }
def test_petersen():
    G = nx.petersen_graph()
    for flow_func in flow_funcs:
        assert_equal(3, nx.node_connectivity(G, flow_func=flow_func),
                     msg=msg.format(flow_func.__name__))
        assert_equal(3, nx.edge_connectivity(G, flow_func=flow_func),
                     msg=msg.format(flow_func.__name__))
Пример #10
0
    def test_empty_graph(self):
        G = nx.empty_graph()
        assert nx.number_of_nodes(G) == 0
        G = nx.empty_graph(42)
        assert nx.number_of_nodes(G) == 42
        assert nx.number_of_edges(G) == 0

        G = nx.empty_graph("abc")
        assert len(G) == 3
        assert G.size() == 0

        # create empty digraph
        G = nx.empty_graph(42, create_using=nx.DiGraph(name="duh"))
        assert nx.number_of_nodes(G) == 42
        assert nx.number_of_edges(G) == 0
        assert isinstance(G, nx.DiGraph)

        # create empty multigraph
        G = nx.empty_graph(42, create_using=nx.MultiGraph(name="duh"))
        assert nx.number_of_nodes(G) == 42
        assert nx.number_of_edges(G) == 0
        assert isinstance(G, nx.MultiGraph)

        # create empty graph from another
        pete = nx.petersen_graph()
        G = nx.empty_graph(42, create_using=pete)
        assert nx.number_of_nodes(G) == 42
        assert nx.number_of_edges(G) == 0
        assert isinstance(G, nx.Graph)
Пример #11
0
def graph_example_1():
    G = nx.convert_node_labels_to_integers(nx.grid_graph([5, 5]),
                                           label_attribute='labels')
    rlabels = nx.get_node_attributes(G, 'labels')
    labels = {v: k for k, v in rlabels.items()}

    for nodes in [(labels[(0, 0)], labels[(1, 0)]),
                  (labels[(0, 4)], labels[(1, 4)]),
                  (labels[(3, 0)], labels[(4, 0)]),
                  (labels[(3, 4)], labels[(4, 4)])]:
        new_node = G.order() + 1
        # Petersen graph is triconnected
        P = nx.petersen_graph()
        G = nx.disjoint_union(G, P)
        # Add two edges between the grid and P
        G.add_edge(new_node + 1, nodes[0])
        G.add_edge(new_node, nodes[1])
        # K5 is 4-connected
        K = nx.complete_graph(5)
        G = nx.disjoint_union(G, K)
        # Add three edges between P and K5
        G.add_edge(new_node + 2, new_node + 11)
        G.add_edge(new_node + 3, new_node + 12)
        G.add_edge(new_node + 4, new_node + 13)
        # Add another K5 sharing a node
        G = nx.disjoint_union(G, K)
        nbrs = G[new_node + 10]
        G.remove_node(new_node + 10)
        for nbr in nbrs:
            G.add_edge(new_node + 17, nbr)
        G.add_edge(new_node + 16, new_node + 5)

    G.name = 'Example graph for connectivity'
    return G
Пример #12
0
def test_petersen():
    G = nx.petersen_graph()
    for flow_func in flow_funcs:
        assert_equal(3, nx.node_connectivity(G, flow_func=flow_func),
                     msg=msg.format(flow_func.__name__))
        assert_equal(3, nx.edge_connectivity(G, flow_func=flow_func),
                     msg=msg.format(flow_func.__name__))
Пример #13
0
 def test_similar_output_to_naive_peterson(self):
     G = nx.petersen_graph()
     G2 = graphpca.reduce_graph_efficiently(G, 2)
     G2n = graphpca.reduce_graph_naively(G, 2)
     self.assertTrue(
         np.allclose(G2, G2n, rtol=1e-04, atol=1e-06),
         'Regular result:\n{}\nNaive result:\n{}\n'.format(G2, G2n))
Пример #14
0
def graph_example_1():
    G = nx.convert_node_labels_to_integers(nx.grid_graph([5, 5]),
                                           label_attribute='labels')
    rlabels = nx.get_node_attributes(G, 'labels')
    labels = {v: k for k, v in rlabels.items()}

    for nodes in [(labels[(0, 0)], labels[(1, 0)]),
                  (labels[(0, 4)], labels[(1, 4)]),
                  (labels[(3, 0)], labels[(4, 0)]),
                  (labels[(3, 4)], labels[(4, 4)])]:
        new_node = G.order() + 1
        # Petersen graph is triconnected
        P = nx.petersen_graph()
        G = nx.disjoint_union(G, P)
        # Add two edges between the grid and P
        G.add_edge(new_node + 1, nodes[0])
        G.add_edge(new_node, nodes[1])
        # K5 is 4-connected
        K = nx.complete_graph(5)
        G = nx.disjoint_union(G, K)
        # Add three edges between P and K5
        G.add_edge(new_node + 2, new_node + 11)
        G.add_edge(new_node + 3, new_node + 12)
        G.add_edge(new_node + 4, new_node + 13)
        # Add another K5 sharing a node
        G = nx.disjoint_union(G, K)
        nbrs = G[new_node + 10]
        G.remove_node(new_node + 10)
        for nbr in nbrs:
            G.add_edge(new_node + 17, nbr)
        G.add_edge(new_node + 16, new_node + 5)

    G.name = 'Example graph for connectivity'
    return G
Пример #15
0
def get_instance(r, k=3):
    g = nx.petersen_graph()
    pos = tutte_embedding(g).rpos()
    pos = {k: np.array(map(mul, v, [r, r])) for k, v in pos.items()}
    for u, v in g.edges():
        g[u][v]['weight'] = np.linalg.norm(pos[u] - pos[v])
    gen = gen_pair_and_demand(nx.number_of_nodes(g))
    return g, pos, [gen.next() for i in xrange(k)]
Пример #16
0
def dgl_graph_from_networkx():
    g_nx = nx.petersen_graph()
    g_dgl = dgl.DGLGraph(g_nx)
    plt.subplot(121)
    nx.draw(g_nx, with_labels=True)
    plt.subplot(122)
    nx.draw(g_dgl.to_networkx(), with_labels=True)
    plt.show()
Пример #17
0
def check(G):
    if len(G.nodes()) == 10:
        return nx.is_isomorphic(nx.petersen_graph(), G)
    elif nx.diameter(G) == 2:
        ds = list(nx.degree(G).values())
        if max(ds) == min(ds) or max(ds) == min(ds) + 1:
            return True
    return False
Пример #18
0
    def generate_graph():
        G = nx.petersen_graph()
        for src, dest in nx.edges(G):
            nx.set_edge_attributes(G,
                                   values={(src, dest): random.randint(1, 30)},
                                   name='weight')

        matrix = nx.to_numpy_array(G).astype(int).tolist()
        return WeightedGraph(matrix)
 def test_petersen(self):
     expected = False
     g = nx.petersen_graph()
     for o in enumerate_dfs_ordering_naively(g):
         @spec_order(o)
         def func(g):
             return is_planar(g)
         actual = func(g)
         self.assertEqual(expected, actual)
Пример #20
0
def build_graph():
    G1 = nx.petersen_graph()
    G2 = dgl.DGLGraph(G1)

    plt.subplot(121)
    nx.draw(G1, with_labels=True)
    plt.subplot(122)
    nx.draw(G2.to_networkx(), with_labels=True)
    plt.show()
Пример #21
0
def main():
    '''
    Not a tight bound;
    '''
    G = nx.petersen_graph()
    print("Petersen Graph CHI upper bound:")
    print(estimate_graph_color(G))
    G100 = nx.complete_graph(100)
    print("K_100 CHI upper bound:")
    print(estimate_graph_color(G100))
Пример #22
0
 def test_there_is_homomorphism_from_peterson_to_all_graphs_upto__vertices(
         self):
     peterson = nx.petersen_graph()
     for i in range(2, 6):
         with open("g" + str(i) + ".g6", "r") as f:
             data = f.read()
             i = 0
             for line in data.split("\n"):
                 if line != "":
                     fh.handle_one_g6_string(peterson, line)
Пример #23
0
def plot1():
    G = nx.petersen_graph()
    plt.subplot(121)
    nx.draw(G, with_labels=True, font_weight='bold')
    plt.subplot(122)
    nx.draw_shell(G,
                  nlist=[range(5, 10), range(5)],
                  with_labels=True,
                  font_weight='bold')
    plt.show()
Пример #24
0
 def setUp(self):
     """Some graphs and vertex-sets used in testing."""
     self.E3 = networkx.empty_graph(3)
     self.E4 = networkx.empty_graph(4)
     self.K3 = networkx.complete_graph(3)
     self.K4 = networkx.complete_graph(4)
     self.petersen = networkx.petersen_graph()
     self.S3 = [0, 1, 2]
     self.S4 = [0, 1, 2, 3]
     self.PT = [2, 4, 5, 6]
     self.PF = [0, 3, 4, 5, 9]
Пример #25
0
    def get_graph():
        g = nx.petersen_graph()
        g = dgl.DGLGraph(g)

        nn, ne = g.number_of_nodes(), g.number_of_edges()

        nf, ef = torch.randn(nn, nf_dim), torch.randn(ne, ef_dim)
        u = torch.randn(1, u_dim)
        g.ndata['h'] = nf
        g.edata['h'] = ef
        return g, u
Пример #26
0
def classic_small_graphs():
    petersen = nx.petersen_graph()
    tutte = nx.tutte_graph()
    maze = nx.sedgewick_maze_graph()
    tet = nx.tetrahedral_graph()

    g_list = [petersen, tutte, maze, tet]
    for n, g in enumerate(g_list):
        plt.subplot(221+n)
        nx.draw(g, with_labels=True, font_weight='bold')
    plt.show()
Пример #27
0
def practice():
    Peterson = nx.petersen_graph()
    tutte = nx.tutte_graph()
    maze = nx.sedgewick_maze_graph()
    tet = nx.tetrahedral_graph()
    G = nx.random_tree(20)

    nx.draw(G, pos=nx.spring_layout(G), with_labels=True)
    #nx.draw_shell(G, nlist=[range(5, 10), range(5)], with_labels=True, font_weight='bold')

    plt.show()
Пример #28
0
 def test_there_is_homomorphism_from_peterson_to_different_graphs(self):
     peterson = nx.petersen_graph()
     complete3 = nx.complete_graph(3)
     complete4 = nx.complete_graph(4)
     cycle4 = nx.cycle_graph(4)
     part = fh.find_a_homomorphism(peterson, complete3)
     self.assertTrue(len(part) >= 1)
     part = fh.find_a_homomorphism(peterson, complete4)
     self.assertTrue(len(part) >= 1)
     part = fh.find_a_homomorphism(peterson, cycle4)
     self.assertTrue(len(part) == 0)
Пример #29
0
def test_petersen_disjoint_paths():
    G = nx.petersen_graph()
    for flow_func in flow_funcs:
        kwargs = dict(flow_func=flow_func)
        # edge disjoint paths
        edge_dpaths = list(nx.edge_disjoint_paths(G, 0, 6, **kwargs))
        assert_true(are_edge_disjoint_paths(G, edge_dpaths), msg=msg.format(flow_func.__name__))
        assert_equal(3, len(edge_dpaths), msg=msg.format(flow_func.__name__))
        # node disjoint paths
        node_dpaths = list(nx.node_disjoint_paths(G, 0, 6, **kwargs))
        assert_true(are_node_disjoint_paths(G, node_dpaths), msg=msg.format(flow_func.__name__))
        assert_equal(3, len(node_dpaths), msg=msg.format(flow_func.__name__))
Пример #30
0
 def test_dimension(self):
     """ Check first embedding coordinates not changed by adding more
     dimensions"""
     G = nx.DiGraph()
     for edge in nx.petersen_graph().edges():
         if edge[0] < edge[1]:
             G.add_edge(edge[0], edge[1])
     X_2, nodes = dag.minkowski_embed(G, 2)
     X_5, nodes = dag.minkowski_embed(G, 5)
     for i in range(10):
         for j in range(2):
             assert_equal(X_2[i,j], X_5[i,j])
Пример #31
0
 def test_dimension(self):
     """ Check first embedding coordinates not changed by adding more
     dimensions"""
     G = nx.DiGraph()
     for edge in nx.petersen_graph().edges():
         if edge[0] < edge[1]:
             G.add_edge(edge[0], edge[1])
     X_2, nodes = dag.minkowski_embed(G, 2)
     X_5, nodes = dag.minkowski_embed(G, 5)
     for i in range(10):
         for j in range(2):
             assert_equal(X_2[i, j], X_5[i, j])
 def test_is_distance_regular(self):
     assert_true(nx.is_distance_regular(nx.icosahedral_graph()))
     assert_true(nx.is_distance_regular(nx.petersen_graph()))
     assert_true(nx.is_distance_regular(nx.cubical_graph()))
     assert_true(nx.is_distance_regular(nx.complete_bipartite_graph(3, 3)))
     assert_true(nx.is_distance_regular(nx.tetrahedral_graph()))
     assert_true(nx.is_distance_regular(nx.dodecahedral_graph()))
     assert_true(nx.is_distance_regular(nx.pappus_graph()))
     assert_true(nx.is_distance_regular(nx.heawood_graph()))
     assert_true(nx.is_distance_regular(nx.cycle_graph(3)))
     # no distance regular
     assert_false(nx.is_distance_regular(nx.path_graph(4)))
Пример #33
0
def __test():
    return tutte_poly(nx.petersen_graph()) == [[0, 36, 84, 75, 35, 9, 1],
                                               [36, 168, 171, 65, 10],
                                               [120, 240, 105, 15],
                                               [180, 170, 30],
                                               [170, 70],
                                               [114, 12],
                                               [56],
                                               [21],
                                               [6],
                                               [1]
                                               ]
Пример #34
0
 def test_is_distance_regular(self):
     assert_true(nx.is_distance_regular(nx.icosahedral_graph()))
     assert_true(nx.is_distance_regular(nx.petersen_graph()))
     assert_true(nx.is_distance_regular(nx.cubical_graph()))
     assert_true(nx.is_distance_regular(nx.complete_bipartite_graph(3,3)))
     assert_true(nx.is_distance_regular(nx.tetrahedral_graph()))
     assert_true(nx.is_distance_regular(nx.dodecahedral_graph()))
     assert_true(nx.is_distance_regular(nx.pappus_graph()))
     assert_true(nx.is_distance_regular(nx.heawood_graph()))
     assert_true(nx.is_distance_regular(nx.cycle_graph(3)))
     # no distance regular
     assert_false(nx.is_distance_regular(nx.path_graph(4)))
Пример #35
0
def __test():
    return tutte_poly(nx.petersen_graph()) == [[0, 36, 84, 75, 35, 9, 1],
                                               [36, 168, 171, 65, 10],
                                               [120, 240, 105, 15],
                                               [180, 170, 30],
                                               [170, 70],
                                               [114, 12],
                                               [56],
                                               [21],
                                               [6],
                                               [1]
                                               ]
Пример #36
0
    def test_is_eulerian(self):
        assert nx.is_eulerian(nx.complete_graph(5))
        assert nx.is_eulerian(nx.complete_graph(7))
        assert nx.is_eulerian(nx.hypercube_graph(4))
        assert nx.is_eulerian(nx.hypercube_graph(6))

        assert not nx.is_eulerian(nx.complete_graph(4))
        assert not nx.is_eulerian(nx.complete_graph(6))
        assert not nx.is_eulerian(nx.hypercube_graph(3))
        assert not nx.is_eulerian(nx.hypercube_graph(5))

        assert not nx.is_eulerian(nx.petersen_graph())
        assert not nx.is_eulerian(nx.path_graph(4))
Пример #37
0
    def tri_cubic(self):
        G = nx.petersen_graph()
        edges_petersen = list(G.edges())
        G = nx.DiGraph()
        for a, b in edges_petersen:
            G.add_edge(a, b, R=random.randint(1,10))

        random_edge = random.choice(list(G.edges()))
        pos = {0: [-9, 2], 2: [9, 2], 1: [0, 8], 4: [-5, -10], 3: [5, -10],  # outer
               5: [-4, 0], 8: [3, -6], 9: [-3, -6], 6: [0, 3], 7: [4, 0]
               }

        return G, (random_edge[0], random_edge[1], random.randint(10, 50)), pos
Пример #38
0
def test_tensor_product_classic_result():
    K2 = nx.complete_graph(2)
    G = nx.petersen_graph()
    G = tensor_product(G,K2)
    assert_true(nx.is_isomorphic(G,nx.desargues_graph()))

    G = nx.cycle_graph(5)
    G = tensor_product(G,K2)
    assert_true(nx.is_isomorphic(G,nx.cycle_graph(10)))

    G = nx.tetrahedral_graph()
    G = tensor_product(G,K2)
    assert_true(nx.is_isomorphic(G,nx.cubical_graph()))
Пример #39
0
    def test_is_eulerian(self):
        assert_true(is_eulerian(nx.complete_graph(5)))
        assert_true(is_eulerian(nx.complete_graph(7)))
        assert_true(is_eulerian(nx.hypercube_graph(4)))
        assert_true(is_eulerian(nx.hypercube_graph(6)))

        assert_false(is_eulerian(nx.complete_graph(4)))
        assert_false(is_eulerian(nx.complete_graph(6)))
        assert_false(is_eulerian(nx.hypercube_graph(3)))
        assert_false(is_eulerian(nx.hypercube_graph(5)))

        assert_false(is_eulerian(nx.petersen_graph()))
        assert_false(is_eulerian(nx.path_graph(4)))
Пример #40
0
def test_tensor_product_classic_result():
    K2 = nx.complete_graph(2)
    G = nx.petersen_graph()
    G = nx.tensor_product(G, K2)
    assert_true(nx.is_isomorphic(G, nx.desargues_graph()))

    G = nx.cycle_graph(5)
    G = nx.tensor_product(G, K2)
    assert_true(nx.is_isomorphic(G, nx.cycle_graph(10)))

    G = nx.tetrahedral_graph()
    G = nx.tensor_product(G, K2)
    assert_true(nx.is_isomorphic(G, nx.cubical_graph()))
Пример #41
0
def test_petersen_cutset():
    G = nx.petersen_graph()
    # edge cuts
    edge_cut = nx.minimum_edge_cut(G)
    assert_equal(3, len(edge_cut))
    H = G.copy()
    H.remove_edges_from(edge_cut)
    assert_false(nx.is_connected(H))
    # node cuts
    node_cut = nx.minimum_node_cut(G)
    assert_equal(3,len(node_cut))
    H = G.copy()
    H.remove_nodes_from(node_cut)
    assert_false(nx.is_connected(H))
Пример #42
0
def test_petersen_cutset():
    G = nx.petersen_graph()
    for flow_func in flow_funcs:
        kwargs = dict(flow_func=flow_func)
        # edge cuts
        edge_cut = nx.minimum_edge_cut(G, **kwargs)
        assert_equal(3, len(edge_cut), msg=msg.format(flow_func.__name__))
        H = G.copy()
        H.remove_edges_from(edge_cut)
        assert_false(nx.is_connected(H), msg=msg.format(flow_func.__name__))
        # node cuts
        node_cut = nx.minimum_node_cut(G, **kwargs)
        assert_equal(3, len(node_cut), msg=msg.format(flow_func.__name__))
        H = G.copy()
        H.remove_nodes_from(node_cut)
        assert_false(nx.is_connected(H), msg=msg.format(flow_func.__name__))
Пример #43
0
    def test_petersen(self):
        """Check boundaries in the petersen graph

        cheeger(G,k)=min(|bdy(S)|/|S| for |S|=k, 0<k<=|V(G)|/2)
        """
        from itertools import combinations
        P=nx.petersen_graph()
        def cheeger(G,k):
            return min( float(len(nx.node_boundary(G,nn)))/k
                        for nn in combinations(G,k) )

        assert_almost_equals(cheeger(P,1),3.00,places=2)
        assert_almost_equals(cheeger(P,2),2.00,places=2)
        assert_almost_equals(cheeger(P,3),1.67,places=2)
        assert_almost_equals(cheeger(P,4),1.00,places=2)
        assert_almost_equals(cheeger(P,5),0.80,places=2)
Пример #44
0
    def test_petersen(self):
        """Check boundaries in the petersen nxgraph

        cheeger(G,k)=min(|bdy(S)|/|S| for |S|=k, 0<k<=|V(G)|/2)
        """
        from random import sample
        P=nx.petersen_graph()
        def cheeger(G,k):
            return min([float(len(nx.node_boundary(G,sample(G.nodes(),k))))/k 
                        for n in range(100)])

        assert_almost_equals(cheeger(P,1),3.00,places=2)
        assert_almost_equals(cheeger(P,2),2.00,places=2)
        assert_almost_equals(cheeger(P,3),1.67,places=2)
        assert_almost_equals(cheeger(P,4),1.00,places=2)
        assert_almost_equals(cheeger(P,5),0.80,places=2)
Пример #45
0
def petersenGraph():
    print "petersenGraph()"
    # Sigui G = (Vg,Eg) el graf original
    # Vèrtex inicial d'exploració: v
    # Sigui H = (Vh,Eh) el graf resultant d'aplicar DFS
    # El graf H està buit  
    G=nx.petersen_graph()
    print "number of edges: ",G.number_of_edges()
    print "number of nodes: ",G.number_of_nodes() 
    print "edges: ",G.edges()
    print "nodes: ",G.nodes()
    print "neighbors: ",G.neighbors()      
    H = nx.dfs_tree(G,0)
    Eh = {}
    Vh ={}
    visitats = {}
    explora(v)
    print "number of edges: ",H.number_of_edges()
    print "number of nodes: ",H.number_of_nodes() 
    print "edges: ",H.edges()
    print "nodes: ",H.nodes()
    print "neighbors: ",H.neighbors()   
    H = nx.dfs_tree(G,5)
    print "number of edges: ",H.number_of_edges()
    print "number of nodes: ",H.number_of_nodes() 
    print "edges: ",H.edges()
    print "nodes: ",H.nodes()
    print "neighbors: ",H.neighbors() 
    G.add_edge(1000,1001)
    print "number of edges: ",G.number_of_edges()
    print "number of nodes: ",G.number_of_nodes() 
    print "edges: ",G.edges()
    print "nodes: ",G.nodes()
    print "neighbors: ",G.neighbors()    
    H = nx.dfs_tree(G,0)
    print "number of edges: ",H.number_of_edges()
    print "number of nodes: ",H.number_of_nodes() 
    print "edges: ",H.edges()
    print "nodes: ",H.nodes()
    print "neighbors: ",H.neighbors() 
    H = nx.dfs_tree(G,1000)
    print "number of edges: ",H.number_of_edges()
    print "number of nodes: ",H.number_of_nodes() 
    print "edges: ",H.edges()
    print "nodes: ",H.nodes()
    print "neighbors: ",H.neighbors()    
Пример #46
0
    def test_num_orbits(self):

        # build a simple example graph
        g = nx.petersen_graph()
        sym = stats.BalancedTreeAutomorphismStatistics(self.sc)
        dg = sym._format_graph_as_nauty(g)
        nauty_format = sym._get_raw_nauty_output(dg)
        log.info("%s", nauty_format)

        o = re.compile('(\d+) orbit;')
        m = o.search(nauty_format)
        if m:
            num_orbits = m.group(1)
            #log.debug("num_orbits match: %s", num_orbits)

            log.info("orbits in petersen graph: %s", num_orbits)
            self.assertEqual(1, int(num_orbits))
        else:
            self.assertTrue(False)
Пример #47
0
 def test_similar_output_to_naive_peterson(self):
     G = nx.petersen_graph()
     G2 = graphpca.reduce_graph_efficiently(G, 2)
     G2n = graphpca.reduce_graph_naively(G, 2)
     self.assertTrue(np.allclose(G2, G2n, rtol=1e-04, atol=1e-06),
                     'Regular result:\n{}\nNaive result:\n{}\n'.format(G2, G2n))
Пример #48
0
 def test_petersen_graph(self):
     """Tests that the Petersen graph is strongly regular."""
     G = nx.petersen_graph()
     assert_true(is_strongly_regular(G))
Пример #49
0
def petersen_graph():
    return EquibelGraph(nx.petersen_graph())
Пример #50
0
# グラフジェネレーターとグラフオペレータ

# 典型的なグラフ操作
# subgraph(G, nbunch)      - induce subgraph of G on nodes in nbunch
# union(G1,G2)             - graph union
# disjoint_union(G1,G2)    - graph union assuming all nodes are different
# cartesian_product(G1,G2) - return Cartesian product graph
# compose(G1,G2)           - combine graphs identifying nodes common to both
# complement(G)            - graph complement
# create_empty_copy(G)     - return an empty copy of the same graph class
# convert_to_undirected(G) - return an undirected representation of G
# convert_to_directed(G)   - return a directed representation of G


petersen=nx.petersen_graph() # ピーターセングラフ 10個の頂点と15個の辺からなる無向グラフ。グラフ理論の様々な問題の例、あるいは反例としてよく使われる。
tutte=nx.tutte_graph() # Tutte グラフ
maze=nx.sedgewick_maze_graph() 
tet=nx.tetrahedral_graph() # テトラへドラル

K_5=nx.complete_graph(5) # 完全グラフ
K_3_5=nx.complete_bipartite_graph(3,5) #完全二部グラフ 2部グラフのうち特に第1の集合に属するそれぞれの頂点から第2の集合に属する全ての頂点に辺が伸びているもの
barbell=nx.barbell_graph(10,10) # 
lollipop=nx.lollipop_graph(10,20) # 

er=nx.erdos_renyi_graph(100,0.15)
ws=nx.watts_strogatz_graph(30,3,0.1)
ba=nx.barabasi_albert_graph(100,5)
red=nx.random_lobster(100,0.9,0.9)

nx.write_gml(red,"path.to.file")
Пример #51
0
def torrents_and_ferraro_graph():
    # Graph from http://arxiv.org/pdf/1503.04476v1 p.26
    G = nx.convert_node_labels_to_integers(
        nx.grid_graph([5, 5]),
        label_attribute='labels',
    )
    rlabels = nx.get_node_attributes(G, 'labels')
    labels = {v: k for k, v in rlabels.items()}

    for nodes in [(labels[(0,4)], labels[(1,4)]),
                  (labels[(3,4)], labels[(4,4)])]:
        new_node = G.order() + 1
        # Petersen graph is triconnected
        P = nx.petersen_graph()
        G = nx.disjoint_union(G, P)
        # Add two edges between the grid and P
        G.add_edge(new_node+1, nodes[0])
        G.add_edge(new_node, nodes[1])
        # K5 is 4-connected
        K = nx.complete_graph(5)
        G = nx.disjoint_union(G, K)
        # Add three edges between P and K5
        G.add_edge(new_node+2, new_node+11)
        G.add_edge(new_node+3, new_node+12)
        G.add_edge(new_node+4, new_node+13)
        # Add another K5 sharing a node
        G = nx.disjoint_union(G, K)
        nbrs = G[new_node+10]
        G.remove_node(new_node+10)
        for nbr in nbrs:
            G.add_edge(new_node+17, nbr)
        # This edge makes the graph biconnected; it's
        # needed because K5s share only one node.
        G.add_edge(new_node+16, new_node+8)

    for nodes in [(labels[(0, 0)], labels[(1, 0)]),
                  (labels[(3, 0)], labels[(4, 0)])]:
        new_node = G.order() + 1
        # Petersen graph is triconnected
        P = nx.petersen_graph()
        G = nx.disjoint_union(G, P)
        # Add two edges between the grid and P
        G.add_edge(new_node+1, nodes[0])
        G.add_edge(new_node, nodes[1])
        # K5 is 4-connected
        K = nx.complete_graph(5)
        G = nx.disjoint_union(G, K)
        # Add three edges between P and K5
        G.add_edge(new_node+2, new_node+11)
        G.add_edge(new_node+3, new_node+12)
        G.add_edge(new_node+4, new_node+13)
        # Add another K5 sharing two nodes
        G = nx.disjoint_union(G,K)
        nbrs = G[new_node+10]
        G.remove_node(new_node+10)
        for nbr in nbrs:
            G.add_edge(new_node+17, nbr)
        nbrs2 = G[new_node+9]
        G.remove_node(new_node+9)
        for nbr in nbrs2:
            G.add_edge(new_node+18, nbr)

    G.name = 'Example graph for connectivity'
    return G
    au = ''.join(map(str, A[__upper_matrix_index]))

    # Convert the binary string to an int
    int_index = int(au, 2)

    return int_index

if __name__ == "__main__":
    import logging

    # Start the logger
    logging.root.setLevel(logging.INFO)
    logging.info("Testing the Petersen graph for all the invariants")

    logging.info("Creating the graph.")
    g = nx.petersen_graph()

    logging.info("Converting to adj. format")
    adj = convert_nx_to_adj(g)

    N = 10
    args = {"N": N}

    logging.info("Converting to numpy format")
    A = convert_to_numpy(adj, **args)

    logging.info("Converting to networkx format")
    gx = networkx_representation(adj, **args)

    logging.info("Converting to graph-tool format")
    gt = graph_tool_representation(adj, **args)
Пример #53
0
def test_petersen():
    # Actual coefficient is 0
    G = nx.petersen_graph()
    assert_equal(average_clustering(G, trials=int(len(G) / 2)),
                 nx.average_clustering(G))
Пример #54
0
def test_petersen():
    G = nx.petersen_graph()
    assert_equal(3, nx.node_connectivity(G))
    assert_equal(3, nx.edge_connectivity(G))
Пример #55
0
import networkx as nx
import matplotlib.pylab as plt
from plot_multigraph import plot_multigraph

graphs = [
  ("bull", nx.bull_graph()),
  ("chvatal", nx.chvatal_graph()),
  ("cubical", nx.cubical_graph()),
  ("desargues", nx.desargues_graph()),
  ("diamond", nx.diamond_graph()),
  ("dodecahedral", nx.dodecahedral_graph()),
  ("frucht", nx.frucht_graph()),
  ("heawood", nx.heawood_graph()),
  ("house", nx.house_graph()),
  ("house_x", nx.house_x_graph()),
  ("icosahedral", nx.icosahedral_graph()),
  ("krackhardt_kite", nx.krackhardt_kite_graph()),
  ("moebius_kantor", nx.moebius_kantor_graph()),
  ("octahedral", nx.octahedral_graph()),
  ("pappus", nx.pappus_graph()),
  ("petersen", nx.petersen_graph()),
  ("sedgewick_maze", nx.sedgewick_maze_graph()),
  ("tetrahedral", nx.tetrahedral_graph()),
  ("truncated_cube", nx.truncated_cube_graph()),
  ("truncated_tetrahedron", nx.truncated_tetrahedron_graph()),
]

plot_multigraph(graphs, 4, 5, node_size=50)
plt.savefig('graphs/small.png')

Пример #56
0
def drawSample():
    G = nx.petersen_graph()
    nx.draw(G)
    plt.show()
Пример #57
0
 def test_petersen_graph(self):
     """Test Petersen graph tree decomposition result"""
     G = nx.petersen_graph()
     _, decomp = treewidth_min_degree(G)
     is_tree_decomp(G, decomp)
Пример #58
0
def test_petersen():
    G = nx.petersen_graph()
    assert_equal(3, approx.node_connectivity(G))
    assert_equal(3, approx.node_connectivity(G, 0, 5))
Пример #59
0
import networkx

G = networkx.petersen_graph()