Пример #1
0
 def delete_edge(self, u, v=None):
     if v is None: (u, v) = u  # no v given, assume u is an edge tuple
     Graph.delete_edge(self, u, v)
     # this will always break a tree into two trees
     # put nodes connected to v in a new component
     vnodes = component.node_connected_component(self, v)
     for n in vnodes:
         self.comp[n] = self.nc
     self.nc += 1
Пример #2
0
 def delete_edge(self, u, v=None): 
     if v is None: (u,v)=u   # no v given, assume u is an edge tuple
     Graph.delete_edge(self,u,v)
     # this will always break a tree into two trees
     # put nodes connected to v in a new component
     vnodes=component.node_connected_component(self,v)
     for n in vnodes:
         self.comp[n]=self.nc
     self.nc+=1
Пример #3
0
 def delete_node(self, n):
     # get neighbors first since this will remove all edges to them
     neighbors = self.neighbors(n)
     Graph.delete_node(self, n)  # delete node and adjacent edges
     del self.comp[n]  # remove node from component dictionary
     if len(neighbors) == 1: return  # n was a leaf node
     for nbr in neighbors:
         # make new components of each nbr and connected graph
         # FIXME this does more work then is necessary
         # since nbrs of n could be in same conected component
         # and then will get renumbered more than once
         vnodes = component.node_connected_component(self, nbr)
         for v in vnodes:
             self.comp[v] = self.nc
         self.nc += 1
Пример #4
0
 def delete_node(self, n):
     # get neighbors first since this will remove all edges to them
     neighbors=self.neighbors(n)
     Graph.delete_node(self,n) # delete node and adjacent edges
     del self.comp[n]     # remove node from component dictionary
     if len(neighbors)==1: return # n was a leaf node
     for nbr in neighbors:
         # make new components of each nbr and connected graph
         # FIXME this does more work then is necessary
         # since nbrs of n could be in same conected component
         # and then will get renumbered more than once
         vnodes=component.node_connected_component(self,nbr)
         for v in vnodes:
             self.comp[v]=self.nc
         self.nc+=1
Пример #5
0
 def add_edge(self, u, v=None):
     if v is None: (u, v) = u  # no v given, assume u is an edge tuple
     if self.has_edge(u, v): return  # no parallel edges
     if u in self:  # u is in forest
         if v in self:  # v is in forest
             if self.comp[u] == self.comp[v]:  # same tree?
                 raise NetworkXError, \
                       "adding edge %s-%s not allowed in forest"%(u,v)
             else:  # join two trees
                 Graph.add_edge(self, u, v)
                 ucomp = self.comp[u]
                 # set component number of v tree to u tree
                 for n in component.node_connected_component(self, v):
                     self.comp[n] = ucomp
         else:  # add u-v to tree in component with u
             Graph.add_edge(self, u, v)
             self.comp[v] = self.comp[u]
     else:  # make new tree with only u-v
         Graph.add_edge(self, u, v)
         self.comp[u] = self.nc
         self.comp[v] = self.nc
         self.nc += 1
Пример #6
0
 def add_edge(self, u, v=None):  
     if v is None: (u,v)=u  # no v given, assume u is an edge tuple
     if self.has_edge(u,v):  return # no parallel edges
     if u in self:  # u is in forest
         if v in self: # v is in forest
             if self.comp[u]==self.comp[v]: # same tree?
                 raise NetworkXError, \
                       "adding edge %s-%s not allowed in forest"%(u,v)
             else:  # join two trees 
                 Graph.add_edge(self,u,v)
                 ucomp=self.comp[u]
                 # set component number of v tree to u tree
                 for n in component.node_connected_component(self,v):
                     self.comp[n]=ucomp
         else: # add u-v to tree in component with u
             Graph.add_edge(self,u,v)
             self.comp[v]=self.comp[u]
     else: # make new tree with only u-v
         Graph.add_edge(self,u,v)
         self.comp[u]=self.nc
         self.comp[v]=self.nc
         self.nc+=1