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

Module networkx.generators.classic

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 1,..,100 as a simple graph. Except for empty_graph, all these generators return a Graph class (i.e. a simple undirected graph).


Function Summary
  balanced_tree(r, h)
Return the perfectly balanced r-tree of height h.
  barbell_graph(m1, m2)
Return the Barbell Graph: two complete graphs connected by a path.
  circular_ladder_graph(n)
Return the circular ladder graph CL_n of length n.
  complete_bipartite_graph(n1, n2)
Return the complete bipartite graph K_{n1_n2}.
  complete_graph(n)
Return the Complete graph K_n with n nodes.
  cycle_graph(n)
Return the cycle graph C_n over n nodes.
  dorogovtsev_goltsev_mendes_graph(n)
Return the hierarchically constructed Dorogovtsev-Goltsev-Mendes graph.
  empty_graph(n, create_using, **kwds)
Return the empty graph with n nodes (with integer labels 1,...,n) and zero edges.
  grid_2d_graph(m, n)
Return the 2d grid graph of mxn nodes, each connected to its nearest neighbors.
  grid_graph(dim, periodic)
Return the n-dimensional grid graph.
  hypercube_graph(n)
return the n-dimensional hypercube.
  ladder_graph(n)
Return the Ladder graph of length n.
  lollipop_graph(m, n)
Return the Lollipop Graph; K_m connected to P_n.
  null_graph(create_using, **kwds)
Return the Null graph with no nodes or edges.
  path_graph(n)
Return the Path graph P_n of n nodes linearly connected by n-1 edges.
  periodic_grid_2d_graph(m, n)
Return the 2-D Grid Graph of mxn nodes, each connected to its nearest neighbors.
  star_graph(n)
Return the Star graph with n+1 nodes: one center node, connected to n outer nodes.
  trivial_graph()
Return the Trivial graph with one node (with integer label 1) and no edges.
  wheel_graph(n)
Return the wheel graph: a single hub node connected to each node of the (n-1)-node cycle graph.

Variable Summary
str __author__ = 'Aric Hagberg (hagberg@lanl.gov)\nPieter Sw...
str __credits__ = ''
str __date__ = '$Date: 2005-06-17 14:06:03 -0600 (Fri, 17 Ju...
str __revision__ = '$Revision: 1056 $'

Function Details

balanced_tree(r, h)

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.

Graph order=1+r+r**2+...+r**h=(r**(h+1)-1)/(r-1), graph size=order-1.

Node labels are integers numbered 1 (the root) up to order.

barbell_graph(m1, m2)

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

For m1>1 and m2>=0.

Two 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 1,...,m1 for the left barbell, m1+1,...,m1+m2 for the path, and m1+m2+1,...,2*m1+m2 for the right barbell. The 3 subgraphs are joined via the edges (m1,m1+1) and (m1+m2,m1+m2+1). 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.

circular_ladder_graph(n)

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.

complete_bipartite_graph(n1, n2)

Return the complete bipartite graph K_{n1_n2}.

Contains n1 nodes in the first subgraph and n2 nodes in the second subgraph.

complete_graph(n)

Return the Complete graph K_n with n nodes.

cycle_graph(n)

Return the cycle graph C_n over n nodes.

C_n is P_n with two end-nodes connected.

dorogovtsev_goltsev_mendes_graph(n)

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, **kwds)

Return the empty graph with n nodes (with integer labels 1,...,n) and zero edges.

>>> G=empty_graph(n) 

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.).

Firstly, the variable create_using can be used to create an empty digraph, network,etc. For example,

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

will create an empty digraph on n nodes, and

>>> 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 baseNX) and then add n nodes and zero edges, and return the modified graph (resp. digraph, pseudograph, etc.).

WARNING: The graph dna is not scrubbed in this process.

See also create_empty_copy(G).

grid_2d_graph(m, n)

Return the 2d grid graph of mxn nodes, each connected to its nearest neighbors.

grid_graph(dim, periodic=False)

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)

return the n-dimensional hypercube.

ladder_graph(n)

Return the Ladder graph of length n.

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

lollipop_graph(m, n)

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 1,...,m for the complete graph and m+1,...,m+n for the path. The 2 subgraphs are joined via the edge (m,n). If n=0, this is merely a complete graph.

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

null_graph(create_using=None, **kwds)

Return the Null graph with no nodes or edges.

path_graph(n)

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

periodic_grid_2d_graph(m, n)

Return the 2-D Grid Graph of mxn nodes, each connected to its nearest neighbors.

Boundary nodes are identified in a periodic fashion.

star_graph(n)

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

trivial_graph()

Return the Trivial graph with one node (with integer label 1) and no edges.

wheel_graph(n)

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


Variable Details

__author__

Type:
str
Value:
'''Aric Hagberg (hagberg@lanl.gov)
Pieter Swart (swart@lanl.gov)'''                                       

__credits__

Type:
str
Value:
''                                                                     

__date__

Type:
str
Value:
'$Date: 2005-06-17 14:06:03 -0600 (Fri, 17 Jun 2005) $'                

__revision__

Type:
str
Value:
'$Revision: 1056 $'                                                    

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