Search code examples
python-3.xgraphnetworkxnetworkit

Methods for generating complex network


I have a small graph network and I've been looking for methods that can make use of the structural properties of the small network to generate a complex network. I'd like to use a method that preserves properties such as degree distribution, clustering, etc..

Fortunately, I came across this [article] (https://link.springer.com/article/10.1007/s41109-017-0054-z) that discusses the generation of a replica of the original network followed by network scaling.

For example, I have generated an edge-weighted Networkx graph like the following: ( a random graph is created for illustration),

import random
import networkx as nx
import matplotlib.pyplot as plt
G = nx.gnm_random_graph(20, 30, seed=1)

for (u, v) in G.edges():
    G.edges[u, v]['weight'] = random.randint(0, 10)

nx.draw(G, with_labels=True)
plt.show()
print(G.edges(data=True))

This graph has 20 nodes. I'd like to know how to scale such Networks by a scale factor x varying from 5 to 10. Examples will be really helpful.

Also, in the documentation (https://github.com/networkit/networkit/blob/Dev/notebooks/User-Guide.ipynb) it is mentioned that the supported graph data format is METIS adjacency format. I would like to know if the networkx graph has to be converted to metis graph. Is there an option of directly using the Networkx graph in Networkit?


Solution

  • You can use the nxadapter module in NetworKit to convert graphs from networkx to NetworKit and vice versa. In your code this would work as follows:

    import networkit as nk
    import random
    import networkx as nx
    import matplotlib.pyplot as plt
    G = nx.gnm_random_graph(20, 30, seed=1)
    
    for (u, v) in G.edges():
        G.edges[u, v]['weight'] = random.randint(0, 10)
    
    nx.draw(G, with_labels=True)
    plt.show()
    print(G.edges(data=True))
    
    # Networkx graph to NetworKit graph
    G_nk = nk.nxadapter.nx2nk(G, weightAttr='weight')
    

    To generate complex networks you can also consider to use a graph generator, here you can find some examples.