Return a directed_random graph with the given degree sequences.
The configuration model generates a random directed pseudograph (graph with parallel edges and self loops) by randomly assigning edges to match the given degree sequences.
Parameters: | in_degree_sequence : list of integers
out_degree_sequence : list of integers
create_using : graph, optional (default MultiDiGraph)
seed : hashable object, optional
|
---|---|
Returns: | G : MultiDiGraph
|
Raises: | NetworkXError :
|
See also
Notes
Algorithm as described by Newman [R52].
A non-graphical degree sequence (not realizable by some simple graph) is allowed since this function returns graphs with self loops and parallel edges. An exception is raised if the degree sequences does not have the same sum.
This configuration model construction process can lead to duplicate edges and loops. You can remove the self-loops and parallel edges (see below) which will likely result in a graph that doesn’t have the exact degree sequence specified. This “finite-size effect” decreases as the size of the graph increases.
References
[R52] | (1, 2) Newman, M. E. J. and Strogatz, S. H. and Watts, D. J. Random graphs with arbitrary degree distributions and their applications Phys. Rev. E, 64, 026118 (2001) |
Examples
>>> D=nx.DiGraph([(0,1),(1,2),(2,3)]) # directed path graph
>>> din=D.in_degree().values()
>>> dout=D.out_degree().values()
>>> din.append(1)
>>> dout[0]=2
>>> D=nx.directed_configuration_model(din,dout)
To remove parallel edges:
>>> D=nx.DiGraph(D)
To remove self loops:
>>> D.remove_edges_from(D.selfloop_edges())