Ejemplo n.º 1
0
 def delete_edge(self, u, v=None): 
     if v is None: (u,v)=u
     if self.degree(u)==1 or self.degree(v)==1:
         DiGraph.delete_edge(self,u,v)
     else:
         raise NetworkXError(
               "deleting interior edge %s-%s not allowed in tree"%(u,v))
     if self.degree(u)==0: DiGraph.delete_node(self,u)
     if self.degree(v)==0: DiGraph.delete_node(self,v)
Ejemplo n.º 2
0
 def delete_edge(self, u, v=None):
     if v is None: (u, v) = u
     if self.degree(u) == 1 or self.degree(v) == 1:
         DiGraph.delete_edge(self, u, v)
     else:
         raise NetworkXError(
             "deleting interior edge %s-%s not allowed in tree" % (u, v))
     if self.degree(u) == 0: DiGraph.delete_node(self, u)
     if self.degree(v) == 0: DiGraph.delete_node(self, v)
Ejemplo n.º 3
0
 def delete_node(self, n):
     try:
         if len(self.succ[n])+len(self.pred[n])==1: # allowed for leaf node
             DiGraph.delete_node(self,n) # deletes adjacent edge too
         else:
             raise NetworkXError( \
           "deleting interior node %s not allowed in tree"%(n))
     except KeyError: # NetworkXError if n not in self
         raise NetworkXError, "node %s not in graph"%n
Ejemplo n.º 4
0
 def delete_node(self, n):
     try:
         if len(self.succ[n]) + len(
                 self.pred[n]) == 1:  # allowed for leaf node
             DiGraph.delete_node(self, n)  # deletes adjacent edge too
         else:
             raise NetworkXError( \
           "deleting interior node %s not allowed in tree"%(n))
     except KeyError:  # NetworkXError if n not in self
         raise NetworkXError, "node %s not in graph" % n