Package networkx :: Module base :: Class DiGraph

[frames | no frames]

## Type DiGraph

    object --+
             |
         Graph --+
                 |
                DiGraph

Known Subclasses:
  `XDiGraph`

A graph with directed edges. Subclass of Graph.

DiGraph inherits from Graph, overriding the following methods:

- __init__: replaces self.adj with the dicts self.pred and self.succ
- __getitem__
- add_node
- delete_node
- add_edge
- delete_edge
- add_nodes_from
- delete_nodes_from
- add_edges_from
- delete_edges_from
- edges_iter
- degree_iter
- degree
- copy
- clear
- subgraph
- is_directed
- to_directed
- to_undirected

Digraph adds the following methods to those of Graph:

- successors
- successors_iter
- predecessors
- predecessors_iter
- out_degree
- out_degree_iter
- in_degree
- in_degree_iter

Method Summary
| ``__init__`(self, **kwds)` Initialize Graph.
| ``__getitem__`(self, n)` Return the in- and out-neighbors of node n as a list.
| ``add_edge`(self, u, v)` Add a single directed edge (u,v) to the digraph.
| ``add_edges_from`(self, ebunch)` Add all the edges in ebunch to the graph.
| ``add_node`(self, n)` Add a single node to the digraph.
| ``add_nodes_from`(self, nbunch)` Add multiple nodes to the digraph.
| ``clear`(self)` Remove name and delete all nodes and edges from digraph.
| ``copy`(self)` Return a (shallow) copy of the digraph.
| ``degree`(self, nbunch, with_labels)` Return degree of single node or of nbunch of nodes.
| ``degree_iter`(self, nbunch, with_labels)` Return iterator that return degree(n) or (n,degree(n)) for all n in nbunch.
| ``delete_edge`(self, u, v)` Delete the single directed edge (u,v) from the digraph.
| ``delete_edges_from`(self, ebunch)` Delete the directed edges in ebunch from the digraph.
| ``delete_node`(self, n)` Delete node n from the digraph.
| ``delete_nodes_from`(self, nbunch)` Remove nodes in nbunch from the digraph.
| ``edges_iter`(self, nbunch, with_labels)` Return iterator that iterates once over each edge adjacent to nodes in nbunch, or over all edges in digraph if no nodes are specified.
| `foo(self)`
| ``in_degree`(self, nbunch, with_labels)` Return in-degree of single node or of nbunch of nodes.
| ``in_degree_iter`(self, nbunch, with_labels)` Return iterator that return in_degree(n) or (n,in_degree(n)) for all n in nbunch.
| ``is_directed`(self)` Return True if a directed graph.
| ``neighbors`(self, n, with_labels)` Return a list of all nodes connected to node n.
| ``neighbors_iter`(self, n, with_labels)` Return an iterator over all nodes connected to node n.
| ``out_degree`(self, nbunch, with_labels)` Return out-degree of single node or of nbunch of nodes.
| ``out_degree_iter`(self, nbunch, with_labels)` Return iterator that return out_degree(n) or (n,out_degree(n)) for all n in nbunch.
| ``predecessors`(self, v, with_labels)` Return predecessor nodes of v.
| ``predecessors_iter`(self, v, with_labels)` Return an iterator for predecessor nodes of v.
| ``reverse`(self)` Return a new digraph with the same vertices and edges as G but with the directions of the edges reversed.
| ``successors`(self, v, with_labels)` Return sucessor nodes of v.
| ``successors_iter`(self, v, with_labels)` Return an iterator for successor nodes of v.
| ``to_directed`(self)` Return a directed representation of the digraph.
| ``to_undirected`(self)` Return the undirected representation of the digraph.

Inherited from `Graph`: `__contains__`, `__iter__`, `__len__`, `__str__`, `add_cycle`, `add_path`, `edge_boundary`, `edges`, `has_edge`, `has_neighbor`, `has_node`, `node_boundary`, `nodes`, `nodes_iter`, `number_of_edges`, `number_of_nodes`, `order`, `print_dna`, `size`, `subgraph`
Inherited from `object`: `__delattr__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__repr__`, `__setattr__`

Method Details

### __init__(self, **kwds)
(Constructor)

Initialize Graph.

    >>> G=Graph(name="empty") creates empty graph G with G.name="empty"

  Overrides:
    `networkx.base.Graph.__init__` (inherited documentation)

### __getitem__(self, n)
(Indexing operator)

Return the in- and out-neighbors of node n as a list.

This provides digraph G the natural property that G[n] returns the neighbors of G.

  Overrides:
    `networkx.base.Graph.__getitem__`

### add_edge(self, u, v=None)

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

Can be used in two basic forms: G.add_edge(u,v) or G.add_edge( (u,v) ) are equivalent forms of adding a single edge between nodes u and v. Nodes are nor required to exist before adding an edge; they will be added in silence.

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

  Overrides:
    `networkx.base.Graph.add_edge`

### add_edges_from(self, ebunch)

Add all the edges in ebunch to the graph.

ebunch: Container of 2-tuples (u,v). The container must be iterable or an iterator. It is iterated over once. Adding the same edge twice has no effect and does not raise an exception.

See add_edge for an example.

  Overrides:
    `networkx.base.Graph.add_edges_from`

### add_node(self, n)

Add a single node to the digraph.

n can be any hashable object (it is used as a key in a dictionary). On many platforms this includes mutables such as Graphs e.g., though one should be careful the hash doesn't change during the lifetime of the graph.

    >>> G=DiGraph()
    >>> K3=complete_graph(3)
    >>> G.add_nodes_from(K3)    # add the nodes from K3 to G
    >>> G.nodes()
    [1,2,3]
    >>> G.clear()
    >>> G.add_node(K3)          # add the graph K3 as a node in G.
    >>> number_of_nodes(G)
    1

  Overrides:
    `networkx.base.Graph.add_node`

### add_nodes_from(self, nbunch)

Add multiple nodes to the digraph.

nbunch: A container of nodes that will be iterated through once (thus it can be an iterator or an iterable). A node can be any hashable object (it is used as a key in a dictionary

  Overrides:
    `networkx.base.Graph.add_nodes_from`

### clear(self)

Remove name and delete all nodes and edges from digraph.

  Overrides:
    `networkx.base.Graph.clear`

### copy(self)

Return a (shallow) copy of the digraph.

Identical to dict.copy() of adjacency dicts pred and succ, with name and dna copied as well.

  Overrides:
    `networkx.base.Graph.copy`

### degree(self, nbunch=None, with_labels=False)

Return degree of single node or of nbunch of nodes. If nbunch is omitted or nbunch=None, then return degrees of all nodes.

If nbunch is a single node n, return degree of n. If nbunch is an iterable (non-string) container of nodes, return a list of values, one for each n in nbunch. (omitting nbunch or nbunch=None is interpreted as nbunch = all nodes in graph.)

If with_labels==True, then return a dict that maps each n in nbunch to degree(n).

Any nodes in nbunch that are not in the graph are (quietly) ignored.

  Overrides:
    `networkx.base.Graph.degree`

### degree_iter(self, nbunch=None, with_labels=False)

Return iterator that return degree(n) or (n,degree(n)) for all n in nbunch. If nbunch is ommitted, then iterate over all nodes.

nbunch: a singleton node, a string (which is treated
  as a singleton node), or any iterable (non-string) container of nodes for which len(nbunch) is defined. For example, a list, dict, set, Graph, numeric array, or user-defined iterable object.

If with_labels=True, iterator will return an (n,degree(n)) tuple of node and degree.

Any nodes in nbunch but not in the graph will be (quietly) ignored.

  Overrides:
    `networkx.base.Graph.degree_iter`

### delete_edge(self, u, v=None)

Delete the single directed edge (u,v) from the digraph.

Can be used in two basic forms: G.delete_edge(u,v) or G.delete_edge( (u,v) ) are equivalent forms of deleting a directed edge u->v. If the nodes do not exist; return without complaining.

  Overrides:
    `networkx.base.Graph.delete_edge`

### delete_edges_from(self, ebunch)

Delete the directed edges in ebunch from the digraph.

ebunch: Container of 2-tuples (u,v). The container must be iterable or an iterator. It is iterated over once. Edges that are not in the digraph are ignored.

  Overrides:
    `networkx.base.Graph.delete_edges_from`

### delete_node(self, n)

Delete node n from the digraph. Attempting to delete a non-existent node will raise a NetworkXError.

  Overrides:
    `networkx.base.Graph.delete_node`

### delete_nodes_from(self, nbunch)

Remove nodes in nbunch from the digraph.

nbunch: an iterable or iterator containing valid (hashable) node names.

Attempting to delete a non-existent node will raise an exception. This could mean some nodes in nbunch were deleted and some valid nodes were not!

  Overrides:
    `networkx.base.Graph.delete_nodes_from`

### edges_iter(self, nbunch=None, with_labels=False)

Return iterator that iterates once over each edge adjacent to nodes in nbunch, or over all edges in digraph if no nodes are specified.

See add_node for definition of nbunch.

Those nodes in nbunch that are not in the graph will be (quietly) ignored.

with_labels=True is not supported (in that case you should probably use neighbors())

  Overrides:
    `networkx.base.Graph.edges_iter`

### in_degree(self, nbunch=None, with_labels=False)

Return in-degree of single node or of nbunch of nodes. If nbunch is omitted or nbunch=None, then return in-degrees of all nodes.

### in_degree_iter(self, nbunch=None, with_labels=False)

Return iterator that return in_degree(n) or (n,in_degree(n)) for all n in nbunch. If nbunch is ommitted, then iterate over all nodes.

See degree_iter method for Digraph Class for more details.

### is_directed(self)

Return True if a directed graph.

  Overrides:
    `networkx.base.Graph.is_directed`

### neighbors(self, n, with_labels=False)

Return a list of all nodes connected to node n.

If with_labels=True, return a dict keyed by neighbors.

  Overrides:
    `networkx.base.Graph.neighbors`

### neighbors_iter(self, n, with_labels=False)

Return an iterator over all nodes connected to node n.

If with_labels=True, return an iterator of (neighbor, 1) tuples.

  Overrides:
    `networkx.base.Graph.neighbors_iter`

### out_degree(self, nbunch=None, with_labels=False)

Return out-degree of single node or of nbunch of nodes. If nbunch is omitted or nbunch=None, then return out-degrees of all nodes.

### out_degree_iter(self, nbunch=None, with_labels=False)

Return iterator that return out_degree(n) or (n,out_degree(n)) for all n in nbunch. If nbunch is ommitted, then iterate over all nodes.

See degree_iter method for Digraph Class for more details.

### predecessors(self, v, with_labels=False)

Return predecessor nodes of v.

### predecessors_iter(self, v, with_labels=False)

Return an iterator for predecessor nodes of v.

### reverse(self)

Return a new digraph with the same vertices and edges as G but with the directions of the edges reversed.

### successors(self, v, with_labels=False)

Return sucessor nodes of v.

### successors_iter(self, v, with_labels=False)

Return an iterator for successor nodes of v.

### to_directed(self)

Return a directed representation of the digraph.

This is already directed, so merely return a copy.

  Overrides:
    `networkx.base.Graph.to_directed`

### to_undirected(self)

Return the undirected representation of the digraph.

A new graph is returned (the underlying graph). The edge u-v is in the underlying graph if either u->v or v->u is in the digraph.

  Overrides:
    `networkx.base.Graph.to_undirected`

Generated by Epydoc 2.1 on Sun Aug 21 08:06:58 2005 | http://epydoc.sf.net