Edgelist
========
>>> from networkx import *
>>> import os,tempfile


ASCII Edge List
--------------------
set up some test networks

>>> G=Graph(name="test")
>>> e=[('a','b'),('b','c'),('c','d'),('d','e'),('e','f'),('a','f')]
>>> G.add_edges_from(e)
>>> G.add_node('g')
>>> DG=DiGraph(G)
>>> XG=MultiGraph()
>>> XG.add_weighted_edges_from([(1,2,5),(1,2,5),(1,2,1),(3,3,42)])
>>> XDG=MultiDiGraph(XG)


>>> (fd,fname)=tempfile.mkstemp()

strings

>>> write_edgelist(G,fname); 
>>> H=read_edgelist(fname)
>>> H2=read_edgelist(fname)
>>> H is not H2  # they should be different graphs
True
>>> G.remove_node('g') # isolated nodes are not written in edgelist
>>> sorted(H.nodes())==sorted(G.nodes())
True
>>> sorted(H.edges())==sorted(G.edges())
True

digraph

>>> write_edgelist(DG,fname)  
>>> H=read_edgelist(fname,create_using=DiGraph());
>>> H2=read_edgelist(fname,create_using=DiGraph());
>>> H is not H2  # they should be different graphs
True
>>> DG.remove_node('g') # isolated nodes are not written in edgelist
>>> sorted(H.nodes())==sorted(DG.nodes())
True
>>> sorted(H.edges())==sorted(DG.edges())
True


integers

>>> Gint=convert_node_labels_to_integers(G)
>>> write_edgelist(Gint,fname)  
>>> H=read_edgelist(fname,nodetype=int)
>>> H2=read_edgelist(fname,nodetype=int)
>>> H is not H2  # they should be different graphs
True
>>> sorted(H.nodes())==sorted(Gint.nodes())
True
>>> sorted(H.edges())==sorted(Gint.edges())
True
>>> os.close(fd)
>>> os.unlink(fname)

MultiGraph

>>> (fd,fname)=tempfile.mkstemp()
>>> write_edgelist(XG,fname)  
>>> H=read_edgelist(fname,nodetype=int,create_using=MultiGraph())
>>> H2=read_edgelist(fname,nodetype=int,create_using=MultiGraph())
>>> H is not H2  # they should be different graphs
True
>>> sorted(H.nodes())==sorted(XG.nodes())
True
>>> sorted(H.edges(data=True))==sorted(XG.edges(data=True))
True

MultiDiGraph

>>> (fd,fname)=tempfile.mkstemp()
>>> write_edgelist(XDG,fname)  
>>> H=read_edgelist(fname,nodetype=int,create_using=MultiDiGraph())
>>> H2=read_edgelist(fname,nodetype=int,create_using=MultiDiGraph())
>>> H is not H2  # they should be different graphs
True
>>> sorted(H.nodes())==sorted(XDG.nodes())
True
>>> sorted(H.edges(data=True))==sorted(XDG.edges(data=True))
True

>>> os.close(fd)
>>> os.unlink(fname)

