Home | Trees | Indices | Help |
---|
|
object --+ | graph.Graph --+ | digraph.DiGraph --+ | XDiGraph
Digraphs with (optional) self-loops, (optional) multiple edges, arbitrary (hashable) objects as nodes, and arbitrary objects associated with edges.
An XDiGraph edge is uniquely specified by a 3-tuple e=(n1,n2,x), where n1 and n2 are (hashable) objects (nodes) and x is an arbitrary (and not necessarily unique) object associated with that edge.
See the documentation of XGraph for the use of the optional parameters selfloops (defaults is False) and multiedges (default is False).
XDiGraph inherits from DiGraph, with all purely node-specific methods identical to those of DiGraph. XDiGraph edges are identical to XGraph edges, except that they are directed rather than undirected. XDiGraph replaces the following DiGraph methods:
XDiGraph also adds the following methods to those of DiGraph:
While XDiGraph does not inherit from XGraph, we compare them here. XDigraph adds the following methods to those of XGraph:
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
Inherited from Inherited from Inherited from |
|
|||
Inherited from |
|
Initialize XDiGraph. Optional arguments:: name: digraph name (default="No Name") selfloops: if True then selfloops are allowed (default=False) multiedges: if True then multiple edges are allowed (default=False)
|
Add a single directed edge to the digraph. Can be called as G.add_edge(n1,n2,x) or as G.add_edge(e), where e=(n1,n2,x). If called as G.add_edge(n1,n2) or G.add_edge(e), with e=(n1,n2), then this is interpreted as adding the edge (n1,n2,None) to be compatible with the Graph and DiGraph classes. n1,n2 are node objects, and are added to the Graph if not already present. Nodes must be hashable Python objects (except None). x is an arbitrary (not necessarily hashable) object associated with this edge. It can be used to associate one or more, labels, data records, weights or any arbirary objects to edges. The default is the Python None. For example, if the graph G was created with >>> G=XDiGraph()
then G.add_edge(1,2,"blue") will add the directed edge (1,2,"blue"). If G.multiedges=False, then a subsequent G.add_edge(1,2,"red") will change the above edge (1,2,"blue") into the edge (1,2,"red"). On the other hand, if G.multiedges=True, then two successive calls to G.add_edge(1,2,"red") will result in 2 edges of the form (1,2,"red") that can not be distinguished from one another. If self.selfloops=False, then any attempt to create a self-loop with add_edge(n1,n1,x) will have no effect on the digraph and will not elicit a warning. Objects imbedded in the edges from n1 to n2 (if any), can be retrieved using get_edge(n1,n2), or calling edges(n1) or edge_iter(n1) to return all edges attached to n1.
|
|
Return True if digraph contains directed edge (n1,n2,x). Can be called as G.has_edge(n1,n2,x) or as G.has_edge(e), where e=(n1,n2,x). If x is unspecified, i.e. if called with an edge of the form e=(n1,n2), then return True if there exists ANY edge from n1 to n2 (equivalent to has_successor(n1,n2)).
|
Return True if node n1 has a successor n2. Return True if there exists ANY edge (n1,n2,x) for some x. |
Return True if node n1 has a predecessor n2. Return True if there exists ANY edge (n2,n1,x) for some x. |
Return the objects associated with each edge from node u to node v. If multiedges=False, a single object is returned. If multiedges=True, a list of objects is returned. If no edge exists, None is returned.
|
Delete all edges between nodes n1 and n2. When there is only a single edge allowed between nodes (multiedges=False), this just calls delete_edge(n1,n2), otherwise (multiedges=True) all edges between n1 and n2 are deleted. |
Delete the directed edge (n1,n2,x) from the graph. Can be called either as >>> G.delete_edge(n1,n2,x) or as >>> G.delete_edge(e) where e=(n1,n2,x). 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)
|
Delete edges in ebunch from the graph. ebunch: Container of edges. Each edge must be a 3-tuple (n1,n2,x) or a 2-tuple (n1,n2). The container must be iterable or an iterator, and is iterated over once. Edges that are not in the graph are ignored.
|
Return iterator that iterates once over each edge pointing out of nodes in nbunch, or over all edges in digraph if no nodes are specified. See edges() for definition of nbunch. Nodes in nbunch that are not in the graph will be (quietly) ignored.
|
Return iterator that iterates once over each edge pointing in to nodes in nbunch, or over all edges in digraph if no nodes are specified. See edges() for definition of nbunch. Nodes in nbunch that are not in the graph will be (quietly) ignored.
|
Return an iterator of nodes pointing out of node n. Returns the same data as out_edges(n) but in a different format.
|
Return an iterator of nodes pointing in to node n. Returns the same data as in_edges(n) but in a different format.
|
Return iterator that iterates once over each edge pointing out of nodes in nbunch, or over all edges in digraph if no nodes are specified. See edges() for definition of nbunch. Nodes in nbunch that are not in the graph will be (quietly) ignored.
|
Return an iterator of nodes pointing out of node n. Returns the same data as out_edges(n) but in a different format.
|
|
|
|
Return iterator for 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 more details.
|
Return iterator for 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 more details.
|
Return iterator that returns in_degree(n)+out_degree(n) or (n,in_degree(n)+out_degree(n)) for all n in nbunch. If nbunch is ommitted, then iterate over all nodes. Can be called in three ways: G.degree_iter(n): return iterator the degree of node n G.degree_iter(nbunch): return a list of values, one for each n in nbunch (nbunch is any iterable container of nodes.) G.degree_iter(): same as nbunch = all nodes in graph. If with_labels=True, iterator will return an (n,in_degree(n)+out_degree(n)) tuple of node and degree. Any nodes in nbunch but not in the graph will be (quietly) ignored.
|
Henceforth allow addition of self-loops (edges from a node to itself). This doesn't change the graph structure, only what you can do to it. |
Henceforth allow addition of multiedges (more than one edge between two nodes). Warning: This causes all edge data to be converted to lists. |
|
Return the subgraph induced on nodes in nbunch. nbunch: can be a single node or any iterable container of of nodes. (It can be an iterable or an iterator, e.g. a list, set, graph, file, numeric array, etc.) Setting inplace=True will return induced subgraph in original graph by deleting nodes not in nbunch. It overrides any setting of create_using. WARNING: specifying inplace=True makes it easy to destroy the graph. Unless otherwise specified, return a new graph of the same type as self. Use (optional) create_using=R to return the resulting subgraph in R. R can be an existing graph-like object (to be emptied) or R can be a call to a graph object, e.g. create_using=DiGraph(). See documentation for empty_graph() Note: use subgraph(G) rather than G.subgraph() to access the more general subgraph() function from the operators module.
|
Return a (shallow) copy of the digraph. Return a new XDiGraph with same name and same attributes for selfloop and multiededges. Each node and each edge in original graph are added to the copy.
|
Return the underlying graph of G. The underlying graph is its undirected representation: each directed edge is replaced with an undirected edge. If multiedges=True, then an XDiGraph with only two directed edges (1,2,"red") and (2,1,"blue") will be converted into an XGraph with two undirected edges (1,2,"red") and (1,2,"blue"). Two directed edges (1,2,"red") and (2,1,"red") will result in in two undirected edges (1,2,"red") and (1,2,"red"). If multiedges=False, then two directed edges (1,2,"red") and (2,1,"blue") can only result in one undirected edge, and there is no guarantee which one it is.
|
|
Return the number of edges between nodes u and v. If u and v are not specified return the number of edges in the entire graph. The edge argument e=(u,v) can be specified as G.number_of_edges(u,v) or G.number_of_edges(e)
|
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0beta1 on Sun Aug 17 12:04:47 2008 | http://epydoc.sourceforge.net |