pythonpython-3.xnetworkxtopology

networkX create topolohy


how can I create a graph, which contains two rings of k/2 neurons each and both rings should be connected by a bridge.

G = nx.generators.lattice.grid_2d_graph(k, 1, periodic=True)
G = nx.convert_node_labels_to_integers(G) 

does not work. Can someone help me please?


Solution

  • G1 = nx.generators.lattice.grid_2d_graph(k/2, 1, periodic=True)
    G1 = nx.convert_node_labels_to_integers(G1)
    G2 = nx.generators.lattice.grid_2d_graph(k/2, 1, periodic=True)
    G2 = nx.convert_node_labels_to_integers(G2)
    G =  nx.union(G1, G2, rename=('g1-', 'g2-'))
    G.add_edge('g1-0', 'g2-0')