def __init__(self, data=None, **kwds): DiGraph.__init__(self, **kwds) if data is not None: try: # build a rooted tree D = DiGraph() for (child, parent) in data.par.iteritems(): D.add_edge(parent, child) except AttributeError: D = DiGraph(data) except: # else nothing we can do raise NetworkXError, "Data %s is not a rooted tree:" % data if D.order() == D.size() + 1: self.pred = D.pred.copy() self.succ = D.succ.copy() self.adj = self.succ del D else: # not a tree raise NetworkXError, "Data %s is not a rooted tree:" % data
def __init__(self,data=None,**kwds): DiGraph.__init__(self,**kwds) if data is not None: try: # build a rooted tree D=DiGraph() for (child,parent) in data.par.iteritems(): D.add_edge(parent,child) except AttributeError: D=DiGraph(data) except: # else nothing we can do raise NetworkXError, "Data %s is not a rooted tree:"%data if D.order()==D.size()+1: self.pred=D.pred.copy() self.succ=D.succ.copy() self.adj=self.succ del D else: # not a tree raise NetworkXError, "Data %s is not a rooted tree:"%data