A directed graph that allows multiple (parallel) edges with arbitrary data on the edges.
Subclass of DiGraph which is a subclass of Graph.
An empty multidigraph is created with
>>> G=nx.MultiDiGraph()
Examples
Create an empty graph structure (a “null graph”) with no nodes and no edges
>>> G=nx.MultiDiGraph()
You can add nodes in the same way as the simple Graph class >>> G.add_nodes_from(xrange(100,110))
You can add edges with data/labels/objects as for the Graph class, but here the same two nodes can have more than one edge between them.
>>> G.add_edges_from([(1,2,0.776),(1,3,0.535)])
For graph coloring problems, one could use >>> G.add_edges_from([(1,2,”blue”),(1,3,”red”)])
A MultiDiGraph edge is uniquely specified by a 3-tuple e=(u,v,x), where u and v are (hashable) objects (nodes) and x is an arbitrary (and not necessarily unique) object associated with that edge.
The graph is directed and multiple edges between the same nodes are allowed.
MultiDiGraph inherits from DiGraph, with all purely node-specific methods identical to those of DiGraph. MultiDiGraph edges are identical to MultiGraph edges, except that they are directed rather than undirected.
MultiDiGraph replaces the following DiGraph methods:
While MultiDiGraph does not inherit from MultiGraph, we compare them here. MultiDigraph adds the following methods to those of MultiGraph:
MultiDiGraph.add_node (n) | Add a single node n. |
MultiDiGraph.add_nodes_from (nbunch) | Add nodes from nbunch. |
MultiDiGraph.remove_node (n) | Remove node n. |
MultiDiGraph.remove_nodes_from (nbunch) | Remove nodes specified in nbunch. |
MultiDiGraph.add_edge (u, v[, data]) | Add a single directed edge to the digraph. |
MultiDiGraph.add_edges_from (ebunch[, data]) | Add all the edges in ebunch. |
MultiDiGraph.remove_edge (u, v[, data]) | Remove edge between (u,v). |
MultiDiGraph.remove_edges_from (ebunch) | Remove all edges specified in ebunch. |
MultiDiGraph.add_star (nlist[, data]) | Add a star. |
MultiDiGraph.add_path (nlist[, data]) | Add a path. |
MultiDiGraph.add_cycle (nlist[, data]) | Add a cycle. |
MultiDiGraph.clear () | Remove all nodes and edges. |
MultiDiGraph.nodes () | Return a list of the nodes. |
MultiDiGraph.nodes_iter () | Return an iterator for the nodes. |
MultiDiGraph.__iter__ () | Iterate over the nodes. Use “for n in G”. |
MultiDiGraph.edges ([nbunch, data]) | Return a list of edges. |
MultiDiGraph.edges_iter ([nbunch, data]) | Return an iterator over the edges. |
MultiDiGraph.get_edge (u, v[, no_edge]) | Return a list of edge data for all edges between u and v. |
MultiDiGraph.neighbors (n) | Return a list of the nodes connected to the node n. |
MultiDiGraph.neighbors_iter (n) | Return an iterator over all neighbors of node n. |
MultiDiGraph.__getitem__ (n) | Return the neighbors of node n. Use “G[n]”. |
MultiDiGraph.successors (n) | Return a list of the nodes connected to the node n. |
MultiDiGraph.successors_iter (n) | Return an iterator over all neighbors of node n. |
MultiDiGraph.predecessors (n) | Return a list of predecessor nodes of n. |
MultiDiGraph.predecessors_iter (n) | Return an iterator over predecessor nodes of n. |
MultiDiGraph.adjacency_list () | Return an adjacency list as a Python list of lists |
MultiDiGraph.adjacency_iter () | Return an iterator of (node, adjacency dict) tuples for all nodes. |
MultiDiGraph.nbunch_iter ([nbunch]) | Return an iterator of nodes contained in nbunch that are also in the graph. |
MultiDiGraph.has_node (n) | Return True if graph has node n. |
MultiDiGraph.__contains__ (n) | Return True if n is a node, False otherwise. Use “n in G”. |
MultiDiGraph.has_edge (u, v) | Return True if graph contains the edge (u,v), False otherwise. |
MultiDiGraph.has_neighbor (u, v) | Return True if node u has neighbor v. |
MultiDiGraph.nodes_with_selfloops () | Return a list of nodes with self loops. |
MultiDiGraph.selfloop_edges () | Return a list of selfloop edges with data (3-tuples). |
MultiDiGraph.order () | Return the number of nodes. |
MultiDiGraph.number_of_nodes () | Return the number of nodes. |
MultiDiGraph.__len__ () | Return the number of nodes. Use “len(G)”. |
MultiDiGraph.size ([weighted]) | Return the number of edges. |
MultiDiGraph.number_of_edges ([u, v]) | Return the number of edges between two nodes. |
MultiDiGraph.number_of_selfloops () | Return the number of selfloop edges counting multiple edges. |
MultiDiGraph.degree ([nbunch, with_labels, ...]) | Return the degree of a node or nodes. |
MultiDiGraph.degree_iter ([nbunch, weighted]) | Return an iterator for (node, degree). |
MultiDiGraph.copy () | Return a copy of the graph. |
MultiDiGraph.to_undirected () | Return an undirected representation of the digraph. |
MultiDiGraph.subgraph (nbunch[, copy]) | Return the subgraph induced on nodes in nbunch. |
MultiDiGraph.reverse ([copy]) | Return the reverse of the graph |