Logo Search packages:      
Sourcecode: python-networkx version File versions  Download package

def networkx::xbase::XGraph::delete_edge (   self,
  n1,
  n2 = None,
  x = None 
)

Delete the edge (n1,n2,x) from the graph.

Can be called either as

>>> G.delete_edge(n1,n2,x)
or
>>> G.delete_edge(e)

where e=(n1,n2,x).

The default edge data is x=None

If called with an edge e=(n1,n2), or as G.delete_edge(n1,n2)
then the edge (n1,n2,None) will be deleted.

If the edge does not exist, do nothing.

To delete *all* edges between n1 and n2 use
>>> G.delete_multiedges(n1,n2)

Definition at line 507 of file xbase.py.

00507                                               : 
        """Delete the edge (n1,n2,x) from the graph.

        Can be called either as

        >>> G.delete_edge(n1,n2,x)
        or
        >>> G.delete_edge(e)

        where e=(n1,n2,x).

        The default edge data is x=None

        If called with an edge e=(n1,n2), or as G.delete_edge(n1,n2)
        then the edge (n1,n2,None) will be deleted.

        If the edge does not exist, do nothing.

        To delete *all* edges between n1 and n2 use
        >>> G.delete_multiedges(n1,n2)
        
        """
        if n2 is None:      # was called as delete_edge(e)
            if len(n1)==3:  # case e=(n1,n2,x)
                n1,n2,x=n1
            else:           # assume e=(n1,n2), x unspecified, set to None
                n1,n2=n1    # x=None

        if self.multiedges:
            if (self.adj.has_key(n1)
                and self.adj[n1].has_key(n2)
                and x in self.adj[n1][n2]):  # if (n1,n2,x) is an edge;
                self.adj[n1][n2].remove(x)  # remove the edge item from list
                if n1!=n2:                   # and if not self loop
                    self.adj[n2][n1].remove(x)  # remove n2->n1 entry
                if len(self.adj[n1][n2])==0: # if last edge between n1 and n2
                    del self.adj[n1][n2]      # was deleted, remove all trace
                    if n1!=n2:                # and if not self loop
                        del self.adj[n2][n1]  # remove n2->n1 entry
        else:  # delete single edge       
            if self.has_neighbor(n1,n2):
                del self.adj[n1][n2]
                if n1!=n2:
                    del self.adj[n2][n1]
        return


Generated by  Doxygen 1.6.0   Back to index