Package networkx :: Package generators :: Module classic
[hide private]
[frames] | no frames]

Module classic

source code

Generators for some classic graphs.

The typical graph generator is called as follows:

>>> G=complete_graph(100)

returning the complete graph on n nodes labeled 0,..,99 as a simple graph. Except for empty_graph, all the generators in this module return a Graph class (i.e. a simple, undirected graph).




Date: $Date: 2005-06-17 14:06:03 -0600 (Fri, 17 Jun 2005) $

Author: Aric Hagberg (hagberg@lanl.gov) Pieter Swart (swart@lanl.gov)

Functions [hide private]
 
balanced_tree(r, h)
Return the perfectly balanced r-tree of height h.
source code
 
barbell_graph(m1, m2)
Return the Barbell Graph: two complete graphs connected by a path.
source code
 
complete_graph(n, create_using=None)
Return the Complete graph K_n with n nodes.
source code
 
complete_bipartite_graph(n1, n2)
Return the complete bipartite graph K_{n1_n2}.
source code
 
circular_ladder_graph(n)
Return the circular ladder graph CL_n of length n.
source code
 
cycle_graph(n, create_using=None)
Return the cycle graph C_n over n nodes.
source code
 
dorogovtsev_goltsev_mendes_graph(n)
Return the hierarchically constructed Dorogovtsev-Goltsev-Mendes graph.
source code
 
empty_graph(n=0, create_using=None)
Return the empty graph with n nodes and zero edges.
source code
 
grid_2d_graph(m, n, periodic=False)
Return the 2d grid graph of mxn nodes, each connected to its nearest neighbors.
source code
 
grid_graph(dim, periodic=False)
Return the n-dimensional grid graph.
source code
 
hypercube_graph(n)
Return the n-dimensional hypercube.
source code
 
ladder_graph(n)
Return the Ladder graph of length n.
source code
 
lollipop_graph(m, n)
Return the Lollipop Graph; K_m connected to P_n.
source code
 
null_graph(create_using=None)
Return the Null graph with no nodes or edges.
source code
 
path_graph(n, create_using=None)
Return the Path graph P_n of n nodes linearly connected by n-1 edges.
source code
 
star_graph(n)
one center node, connected to n outer nodes.
source code
 
trivial_graph()
Return the Trivial graph with one node (with integer label 0) and no edges.
source code
 
wheel_graph(n)
to each node of the (n-1)-node cycle graph.
source code
 
_test_suite() source code
Variables [hide private]
  __credits__ = ''
  __revision__ = '$Revision: 1056 $'
Function Details [hide private]

balanced_tree(r, h)

source code 

Return the perfectly balanced r-tree of height h.

For r>=2, h>=1, this is the rooted tree where all leaves are at distance h from the root. The root has degree r and all other internal nodes have degree r+1.

number_of_nodes = 1+r+r**2+...+r**h = (r**(h+1)-1)/(r-1), number_of_edges = number_of_nodes - 1.

Node labels are the integers 0 (the root) up to number_of_nodes - 1.

barbell_graph(m1, m2)

source code 

Return the Barbell Graph: two complete graphs connected by a path.

For m1 > 1 and m2 >= 0.

Two identical complete graphs K_{m1} form the left and right bells, and are connected by a path P_{m2}.

The 2*m1+m2 nodes are numbered
0,...,m1-1 for the left barbell, m1,...,m1+m2-1 for the path, and m1+m2,...,2*m1+m2-1 for the right barbell.

The 3 subgraphs are joined via the edges (m1-1,m1) and (m1+m2-1,m1+m2). If m2=0, this is merely two complete graphs joined together.

This graph is an extremal example in David Aldous and Jim Fill's etext on Random Walks on Graphs.

complete_graph(n, create_using=None)

source code 

Return the Complete graph K_n with n nodes.

Node labels are the integers 0 to n-1.

complete_bipartite_graph(n1, n2)

source code 

Return the complete bipartite graph K_{n1_n2}.

Composed of two partitions with n1 nodes in the first and n2 nodes in the second. Each node in the first is connected to each node in the second.

Node labels are the integers 0 to n1+n2-1

circular_ladder_graph(n)

source code 

Return the circular ladder graph CL_n of length n.

CL_n consists of two concentric n-cycles in which each of the n pairs of concentric nodes are joined by an edge.

Node labels are the integers 0 to n-1

cycle_graph(n, create_using=None)

source code 

Return the cycle graph C_n over n nodes.

C_n is the n-path with two end-nodes connected.

Node labels are the integers 0 to n-1 If create_using is a DiGraph, the direction is in increasing order.

dorogovtsev_goltsev_mendes_graph(n)

source code 

Return the hierarchically constructed Dorogovtsev-Goltsev-Mendes graph.

n is the generation. See: arXiv:/cond-mat/0112143 by Dorogovtsev, Goltsev and Mendes.

empty_graph(n=0, create_using=None)

source code 

Return the empty graph with n nodes and zero edges.

Node labels are the integers 0 to n-1

For example: >>> from networkx import * >>> G=empty_graph(10) >>> G.number_of_nodes() 10 >>> G.number_of_edges() 0

The variable create_using should point to a "graph"-like object that will be cleaned (nodes and edges will be removed) and refitted as an empty "graph" with n nodes with integer labels. This capability is useful for specifying the class-nature of the resulting empty "graph" (i.e. Graph, DiGraph, MyWeirdGraphClass, etc.).

The variable create_using has two main uses: Firstly, the variable create_using can be used to create an empty digraph, network,etc. For example,

>>> n=10
>>> G=empty_graph(n,create_using=DiGraph())

will create an empty digraph on n nodes.

Secondly, one can pass an existing graph (digraph, pseudograph, etc.) via create_using. For example, if G is an existing graph (resp. digraph, pseudograph, etc.), then empty_graph(n,create_using=G) will empty G (i.e. delete all nodes and edges using G.clear() in base) and then add n nodes and zero edges, and return the modified graph (resp. digraph, pseudograph, etc.).

See also create_empty_copy(G).

grid_2d_graph(m, n, periodic=False)

source code 
Return the 2d grid graph of mxn nodes, each connected to its nearest neighbors. Optional argument periodic=True will connect boundary nodes via periodic boundary conditions.

grid_graph(dim, periodic=False)

source code 

Return the n-dimensional grid graph.

The dimension is the length of the list 'dim' and the size in each dimension is the value of the list element.

E.g. G=grid_graph(dim=[2,3]) produces a 2x3 grid graph.

If periodic=True then join grid edges with periodic boundary conditions.

hypercube_graph(n)

source code 

Return the n-dimensional hypercube.

Node labels are the integers 0 to 2**n - 1.

ladder_graph(n)

source code 

Return the Ladder graph of length n.

This is two rows of n nodes, with each pair connected by a single edge.

Node labels are the integers 0 to 2*n - 1.

lollipop_graph(m, n)

source code 

Return the Lollipop Graph; K_m connected to P_n.

This is the Barbell Graph without the right barbell.

For m>1 and n>=0, the complete graph K_m is connected to the path P_n. The resulting m+n nodes are labelled 0,...,m-1 for the complete graph and m,...,m+n-1 for the path. The 2 subgraphs are joined via the edge (m-1,m). If n=0, this is merely a complete graph.

Node labels are the integers 0 to number_of_nodes - 1.

(This graph is an extremal example in David Aldous and Jim Fill's etext on Random Walks on Graphs.)

null_graph(create_using=None)

source code 

Return the Null graph with no nodes or edges.

See empty_graph for the use of create_using.

path_graph(n, create_using=None)

source code 

Return the Path graph P_n of n nodes linearly connected by n-1 edges.

Node labels are the integers 0 to n - 1. If create_using is a DiGraph then the edges are directed in increasing order.

star_graph(n)

source code 
Return the Star graph with n+1 nodes:
one center node, connected to n outer nodes.

Node labels are the integers 0 to n.

wheel_graph(n)

source code 
Return the wheel graph: a single hub node connected
to each node of the (n-1)-node cycle graph.

Node labels are the integers 0 to n - 1.