예제 #1
0
파일: tree.py 프로젝트: thiagoki/Tdevel
 def __init__(self, data=None, **kwds):
     Graph.__init__(self, **kwds)
     if data is not None:
         try:  # build a graph
             G = Graph()
             G = convert.from_whatever(data, create_using=G)
         except:
             raise NetworkXError, "Data %s is not a tree" % data
         # check if it is a tree.
         if G.order()==G.size()+1 and \
                component.number_connected_components(G)==1:
             self.adj = G.adj.copy()
             del G
         else:
             raise NetworkXError, "Data %s is not a tree" % data
예제 #2
0
파일: digraph.py 프로젝트: thiagoki/Tdevel
 def to_undirected(self):
     """Return an undirected representation of the digraph.
 
     A new graph is returned with the same name and nodes and
     with edge (u,v,data) if either (u,v,data) or (v,u,data) 
     is in the digraph.  If both edges exist in digraph and
     their edge data is different, only one edge is created
     with an arbitrary choice of which edge data to use.  
     You must check and correct for this manually if desired.
     
     """
     H = Graph()
     H.name = self.name
     H.add_nodes_from(self)
     H.add_edges_from([(v, u, d)
                       for (u, v, d) in self.edges_iter(data=True)])
     return H