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

def networkx::base::DiGraph::add_edge (   self,
  u,
  v = None 
) [inherited]

Add a single directed edge (u,v) to the digraph.

>> G.add_edge(u,v)
and
>>> G.add_edge( (u,v) )
are equivalent forms of adding a single edge between nodes u and v.
The nodes u and v will be automatically added if not already in
the graph.  They must be a hashable (except None) Python object.

For example, the following examples all add the edge (1,2) to
the digraph G.

>>> G=DiGraph()
>>> G.add_edge( 1, 2 )          # explicit two node form
>>> G.add_edge( (1,2) )         # single edge as tuple of two nodes
>>> G.add_edges_from( [(1,2)] ) # list of edges form

Reimplemented from networkx::base::Graph.

Reimplemented in networkx::tree::DirectedTree.

Definition at line 1169 of file base.py.

01169                                  :  
        """Add a single directed edge (u,v) to the digraph.

        >> G.add_edge(u,v)
        and
        >>> G.add_edge( (u,v) )
        are equivalent forms of adding a single edge between nodes u and v.
        The nodes u and v will be automatically added if not already in
        the graph.  They must be a hashable (except None) Python object.

        For example, the following examples all add the edge (1,2) to
        the digraph G.

        >>> G=DiGraph()
        >>> G.add_edge( 1, 2 )          # explicit two node form
        >>> G.add_edge( (1,2) )         # single edge as tuple of two nodes
        >>> G.add_edges_from( [(1,2)] ) # list of edges form

        """
        if v is None:
            (u,v)=u  # no v given, assume u is an edge tuple
        # add nodes            
        if u not in self.succ:
            self.succ[u]={}
        if u not in self.pred:
            self.pred[u]={}
        if v not in self.succ:
            self.succ[v]={}
        if v not in self.pred:
            self.pred[v]={}

        # don't create self loops, fail silently, nodes are still added
        if u==v: 
            return  
        self.succ[u][v]=None
        self.pred[v][u]=None


Generated by  Doxygen 1.6.0   Back to index