============================
Generators - Degree Sequence
============================



>>> from networkx import *
>>> from networkx.generators.degree_seq import *
>>> from networkx.isomorph import graph_could_be_isomorphic
>>> is_isomorphic=graph_could_be_isomorphic # use fast but weak isomorphism checker

configuration_model
-------------------

empty graph has empty degree sequence
>>> deg_seq=[]
>>> G=configuration_model(deg_seq)
>>> G.degree()
[]

>>> deg_seq=[5,3,3,3,3,2,2,2,1,1,1]
>>> G=configuration_model(deg_seq,seed=12345678)
>>> sorted(G.degree())
[1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 5]
>>> G.degree(range(1,len(deg_seq)+1))
[5, 1, 3, 3, 1, 2, 2, 2, 1, 1, 1]


test that fixed seed delivers the same graph

>>> deg_seq=[3,3,3,3,3,3,3,3,3,3,3,3]
>>> G1=configuration_model(deg_seq,seed=1000)
>>> G2=configuration_model(deg_seq,seed=1000)
>>> is_isomorphic(G1,G2)
True
>>> G1=configuration_model(deg_seq,seed=10)
>>> G2=configuration_model(deg_seq,seed=10)
>>> is_isomorphic(G1,G2)
True


>>> z=[5,3,3,3,3,2,2,2,1,1,1]
>>> is_valid_degree_sequence(z)
True

>>> G=havel_hakimi_graph(z)
>>> G=configuration_model(z)
>>> z=[1000,3,3,3,3,2,2,2,1,1,1]
>>> is_valid_degree_sequence(z)
False

Havel-Hakimi Construction
-------------------------

>>> G=havel_hakimi_graph(z)
Traceback (most recent call last):
...
NetworkXError: Invalid degree sequence

>>> z=["A",3,3,3,3,2,2,2,1,1,1]
>>> havel_hakimi_graph(z)
Traceback (most recent call last):
...
NetworkXError: Invalid degree sequence

>>> z=[5,4,3,3,3,2,2,2]
>>> G=havel_hakimi_graph(z)
>>> G=configuration_model(z)
>>> z=[6,5,4,4,2,1,1,1]
>>> is_valid_degree_sequence(z)
False
>>> G=havel_hakimi_graph(z)
Traceback (most recent call last):
...
NetworkXError: Invalid degree sequence

>>> z=[10,3,3,3,3,2,2,2,2,2,2]
>>> is_valid_degree_sequence(z)
True
>>> G=havel_hakimi_graph(z)

Degree Sequence Tree
--------------------

>>> z=[1, 1, 1, 1, 1, 2, 2, 2, 3, 4]
>>> is_valid_degree_sequence(z)
True
>>> G=degree_sequence_tree(z)
>>> len(G.nodes())==len(z)
True
>>> len(G.edges())==sum(z)/2
True

>>> z=[1, 1, 1, 1, 1, 1, 2, 2, 2, 3, 4]
>>> is_valid_degree_sequence(z)
False
>>> G=degree_sequence_tree(z)
Traceback (most recent call last):
...
NetworkXError: Degree sequence not a tree


Degree Sequences
----------------

>>> from networkx.utils import *
>>> seq=create_degree_sequence(10,uniform_sequence)
>>> len(seq)
10
>>> seq=create_degree_sequence(10,powerlaw_sequence)
>>> len(seq)
10


