Generators - Bipartite
----------------------

>>> from networkx import *
>>> from networkx.generators.bipartite import *

Configuration Model
-------------------

>>> aseq=[3,3,3,3]
>>> bseq=[2,2,2,2,2] 
>>> G=bipartite_configuration_model(aseq,bseq)
Traceback (most recent call last):
...
NetworkXError: invalid degree sequences, sum(aseq)!=sum(bseq),12,10

>>> aseq=[3,3,3,3]
>>> bseq=[2,2,2,2,2,2] 
>>> G=bipartite_configuration_model(aseq,bseq)
>>> sorted(G.degree())
[2, 2, 2, 2, 2, 2, 3, 3, 3, 3]
 
>>> aseq=[2,2,2,2,2,2] 
>>> bseq=[3,3,3,3]
>>> G=bipartite_configuration_model(aseq,bseq)
>>> sorted(G.degree())
[2, 2, 2, 2, 2, 2, 3, 3, 3, 3]

 
>>> aseq=[2,2,2,1,1,1] 
>>> bseq=[3,3,3]
>>> G=bipartite_configuration_model(aseq,bseq)
>>> sorted(G.degree())
[1, 1, 1, 2, 2, 2, 3, 3, 3]

>>> GU=project(G,range(len(aseq)))
>>> GU.number_of_nodes()
6

>>> GD=project(G,range(len(aseq),len(aseq)+len(bseq)))
>>> GD.number_of_nodes()
3


Havel-Hakimi Graph
------------------

>>> aseq=[3,3,3,3]
>>> bseq=[2,2,2,2,2] 
>>> G=bipartite_havel_hakimi_graph(aseq,bseq)
Traceback (most recent call last):
...
NetworkXError: invalid degree sequences, sum(aseq)!=sum(bseq),12,10

>>> bseq=[2,2,2,2,2,2] 
>>> G=bipartite_havel_hakimi_graph(aseq,bseq)
>>> sorted(G.degree())
[2, 2, 2, 2, 2, 2, 3, 3, 3, 3]
 
 
>>> aseq=[2,2,2,2,2,2] 
>>> bseq=[3,3,3,3]
>>> G=bipartite_havel_hakimi_graph(aseq,bseq)
>>> sorted(G.degree())
[2, 2, 2, 2, 2, 2, 3, 3, 3, 3]



>>> GU=project(G,range(len(aseq)))
>>> GU.number_of_nodes()
6

>>> GD=project(G,range(len(aseq),len(aseq)+len(bseq)))
>>> GD.number_of_nodes()
4



Reverse Havel-Hakimi Graph
--------------------------

>>> aseq=[3,3,3,3]
>>> bseq=[2,2,2,2,2] 
>>> G=bipartite_reverse_havel_hakimi_graph(aseq,bseq)
Traceback (most recent call last):
...
NetworkXError: invalid degree sequences, sum(aseq)!=sum(bseq),12,10

>>> bseq=[2,2,2,2,2,2] 
>>> G=bipartite_reverse_havel_hakimi_graph(aseq,bseq)
>>> sorted(G.degree())
[2, 2, 2, 2, 2, 2, 3, 3, 3, 3]

 
>>> aseq=[2,2,2,2,2,2] 
>>> bseq=[3,3,3,3]
>>> G=bipartite_reverse_havel_hakimi_graph(aseq,bseq)
>>> sorted(G.degree())
[2, 2, 2, 2, 2, 2, 3, 3, 3, 3]

 
>>> aseq=[2,2,2,1,1,1] 
>>> bseq=[3,3,3]
>>> G=bipartite_reverse_havel_hakimi_graph(aseq,bseq)
>>> sorted(G.degree())
[1, 1, 1, 2, 2, 2, 3, 3, 3]


>>> GU=project(G,range(len(aseq)))
>>> GU.number_of_nodes()
6

>>> GD=project(G,range(len(aseq),len(aseq)+len(bseq)))
>>> GD.number_of_nodes()
3



Alternating Havel-Hakimi Graph
------------------------------

>>> aseq=[3,3,3,3]
>>> bseq=[2,2,2,2,2] 
>>> G=bipartite_alternating_havel_hakimi_graph(aseq,bseq)
Traceback (most recent call last):
...
NetworkXError: invalid degree sequences, sum(aseq)!=sum(bseq),12,10

>>> bseq=[2,2,2,2,2,2] 
>>> G=bipartite_alternating_havel_hakimi_graph(aseq,bseq)
>>> sorted(G.degree())
[2, 2, 2, 2, 2, 2, 3, 3, 3, 3]
 
>>> aseq=[2,2,2,2,2,2] 
>>> bseq=[3,3,3,3]
>>> G=bipartite_alternating_havel_hakimi_graph(aseq,bseq)
>>> sorted(G.degree())
[2, 2, 2, 2, 2, 2, 3, 3, 3, 3]

 
>>> aseq=[2,2,2,1,1,1] 
>>> bseq=[3,3,3]
>>> G=bipartite_alternating_havel_hakimi_graph(aseq,bseq)
>>> sorted(G.degree())
[1, 1, 1, 2, 2, 2, 3, 3, 3]


>>> GU=project(G,range(len(aseq)))
>>> GU.number_of_nodes()
6

>>> GD=project(G,range(len(aseq),len(aseq)+len(bseq)))
>>> GD.number_of_nodes()
3


Preferential Attachment
-----------------------

>>> aseq=[3,2,1,1]
>>> G=bipartite_preferential_attachment_graph(aseq,0.5)


Random Regular Bipartite
------------------------
FIXME: test this somehow
G=bipartite_random_regular_graph(2,12)
G.degree()
[4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]
is_bipartite(G)
True

Coloring and bipartite sets
---------------------------
>>> G=complete_bipartite_graph(2,2)
>>> is_bipartite(G)
True
>>> A,B=bipartite_sets(G)
>>> A
[0, 1]
>>> B
[2, 3]
>>> bipartite_color(G)
{0: 1, 1: 1, 2: 0, 3: 0}

>>> G=path_graph(10)
>>> is_bipartite(G)
True
>>> A,B=bipartite_sets(G)
>>> A
[0, 2, 4, 6, 8]
>>> B
[1, 3, 5, 7, 9]

>>> G=cycle_graph(5)
>>> is_bipartite(G)
False

>>> G=cycle_graph(6)
>>> is_bipartite(G)
True

>>> G=Graph({0: {7: None},1: {7: None},2: {6: None},3: {6: None},4:{5: None},5: {4: None, 7: None},6: {2: None, 3: None, 7: None},7:{0: None, 1: None, 5: None, 6: None}})
>>> is_bipartite(G)
True
