The SAGE [http://sage.math.washington.edu:9001/graph Graph Theory Project] aims to implement Graph objects and algorithms in ["SAGE"].

The goal of the Graph Database is to implement constructors for many common graphs, as well as thorough docstrings that can be used for reference. The Graph Database will grow as the Graph Theory Project does. Robert Miller has been working on a graphics primitive for SAGE Graph objects, which has allowed us to pre-set a position dictionary for the x-y coordinates of each node. (Browse code and examples below). We also have the ability to view graphs in a SAGE Graphics Array, write text on the graphs, etc. that we inherit from having an associated SAGE Graphics Object for each SAGE Graph.

As we implement algorithms into the Graph Theory Package, the constructors of known graphs would set their properties upon instantiation as well. For example, if someone created a very large complete bipartite graph and then asked if it is a bipartite graph (not currently implemented), then instead of running through an algorithm to check it, we could return a value set at instantiation. Further, this will improve the reference use of the docstrings as we would list the properties of each named graph.

I am also launching a survey of existing graph database software (wiki link coming soon). I am looking for a substantially large database of graphs and their properties, so that users can query properties.

Scroll down to see current status and examples. There are lots of pictures, so I recommend using the Table of Contents to navigate. Also, please note the suggestions section. Posting suggestions there will be easiest for me to keep on top of.

Emily Kirkman is working on this project.

TableOfContents

Suggestions

Graphs I Plan to Add

1. Inherited from NetworkX

2. Families of Graphs

3. Named Graphs

Currently implemented in Graph Database

1. Class Docstrings

A collection of constructors of common graphs.

USES:
    A list of all graphs and graph structures in this database is available via tab completion.
    Type "graphs." and then hit tab to see which graphs are available.

    The docstrings include educational information about each named graph with the hopes that this
    database can be used as a reference.

PLOTTING:
    All graphs (i.e., networks) have an associated SAGE graphics object, which you can display:
        
        sage: G = WheelGraph(15)
        sage: p = G.plot()
        sage: is_Graphics(p)
        True

    When creating a graph in SAGE, the default positioning of nodes is determined using the spring-layout
    algorithm.  Often, it is more efficient to pre-set the positions in a dictionary.  Additionally, we can use
    this position dictionary to display the graph in an intuitive manner, whereas the spring-layout would 
    fail if the graph is not very symmetric.  For example, consider the Petersen graph with default node
    positioning vs. the Petersen graph constructed by this database:

        sage: petersen_spring = Graph({0:[1,4,5], 1:[0,2,6], 2:[1,3,7], 3:[2,4,8], 4:[0,3,9],\
                5:[0,7,8], 6:[1,8,9], 7:[2,5,9], 8:[3,5,6], 9:[4,6,7]})
        sage.: petersen_spring.show()
        sage: petersen_database = graphs.PetersenGraph()
        sage.: petersen_database.show()
    
    For all the constructors in this database (except the random and empty graphs), the position dictionary
    is filled, instead of using the spring-layout algorithm.

ORGANIZATION:
    The constructors available in this database are organized as follows:
        Basic Structures:
            - EmptyGraph
            - CycleGraph
            - StarGraph
            - WheelGraph
        Named Graphs:
            - PetersenGraph
        Families of Graphs:
            - CompleteGraph
            - CompleteBipartiteGraph
            - RandomGNP
            - RandomGNPFast

AUTHORS:
    -- Robert Miller (2006-11-05): initial version - empty, random, petersen
    -- Emily Kirkman (2006-11-12): basic structures, node positioning for all constructors
    -- Emily Kirkman (2006-11-19): docstrings, examples
    
TODO:
    [] more named graphs
    [] thorough docstrings and examples
    [] set properties (as they are implemented)
    [] add query functionality for large database

2. Basic Structures

2.1. Empty Graphs

2.1.1. Info

2.1.2. Plotting

2.1.3. Code

 return graph.Graph()

2.1.4. Examples

2.1.4.1. Add one vertex to an empty graph.

 sage: empty1 = graphs.EmptyGraph()
 sage: empty1.add_vertex()
 sage: empty1.show()

attachment:empty1.png

2.1.4.2. Use for loops to build a graph from an empty graph.

 sage: empty2 = graphs.EmptyGraph()
 sage: for i in range(5):
 ...    empty2.add_vertex() # add 5 nodes, labeled 0-4
 ...
 sage: for i in range(3):
 ...    empty2.add_edge(i,i+1) # add edges {[0:1],[1:2],[2:3]}
 ...
 sage: for i in range(4)[1:]:
 ...    empty2.add_edge(4,i) # add edges {[1:4],[2:4],[3:4]}
 ...
 sage: empty2.show()

attachment:empty2.png

2.2. Cycle Graphs

2.2.1. Info

2.2.2. Plotting

2.2.3. Code

 pos_dict = {}
 for i in range(n):
     x = float(functions.cos((pi/2) + ((2*pi)/n)*i))
     y = float(functions.sin((pi/2) + ((2*pi)/n)*i))
     pos_dict[i] = [x,y]
 G = NX.cycle_graph(n)
 return graph.Graph(G, pos=pos_dict, name="Cycle graph on %d vertices"%n)

2.2.4. Examples

2.2.4.1. The following examples require NetworkX (to use default):

 sage: import networkx as NX

2.2.4.2. Compare the constructor speeds.

 time n = NX.cycle_graph(3989); spring3989 = Graph(n)

 time posdict3989 = graphs.CycleGraph(3989)

2.2.4.3. Compare the plotting speeds.

 sage: n = NX.cycle_graph(23)
 sage: spring23 = Graph(n)
 sage: posdict23 = graphs.CycleGraph(23)

 time spring23.show()

attachment:cycle_spr23.png

 time posdict23.show()

attachment:cycl_pd23.png

2.2.4.4. View many cycle graphs as a SAGE Graphics Array.

2.2.4.5. With the position dictionary filled:

 sage: g = []
 sage: j = []
 sage: for i in range(16):
 ...    k = graphs.CycleGraph(i+3)
 ...    g.append(k)
 ...
 sage: for i in range(4):
 ...    n = []
 ...    for m in range(4):
 ...        n.append(g[4*i + m].plot(node_size=50, with_labels=False))
 ...    j.append(n)
 ...
 sage: G = sage.plot.plot.GraphicsArray(j)
 sage: G.show()

attachment:cycle_pd_array.png

2.2.4.6. With the spring-layout algorithm:

 sage: g = []
 sage: j = []
 sage: for i in range(16):
 ...    spr = NX.cycle_graph(i+3)       
 ...    k = Graph(spr)
 ...    g.append(k)
 ...
 sage: for i in range(4):
 ...    n = []
 ...    for m in range(4):
 ...        n.append(g[4*i + m].plot(node_size=50, with_labels=False))
 ...    j.append(n)
 ...
 sage: G = sage.plot.plot.GraphicsArray(j)
 sage: G.show()

attachment:cycle_spr_array.png

2.3. Star Graphs

2.3.1. Info

2.3.2. Plotting

2.3.3. Code

 pos_dict = {}
 pos_dict[0] = [0,0]
 for i in range(n+1)[1:]:
     x = float(functions.cos((pi/2) + ((2*pi)/n)*(i-1)))
     y = float(functions.sin((pi/2) + ((2*pi)/n)*(i-1)))
     pos_dict[i] = [x,y]
 G = NX.star_graph(n)
 return graph.Graph(G, pos=pos_dict, name="Star graph on %d vertices"%(n+1))

2.3.4. Examples

2.3.4.1. The following examples require NetworkX (to use default):

 sage: import networkx as NX

2.3.4.2. Compare the constructor speeds.

 time n = NX.star_graph(3989); spring3989 = Graph(n)

 time posdict3989 = graphs.StarGraph(3989)

2.3.4.3. Compare the plotting speeds.

 sage: n = NX.star_graph(23)
 sage: spring23 = Graph(n)
 sage: posdict23 = graphs.StarGraph(23)

 time spring23.show()

attachment:star_spr23.png

 time posdict23.show()

attachment:star_pd23.png

2.3.4.4. View many star graphs as a SAGE Graphics Array.

2.3.4.5. With the position dictionary filled:

 sage: g = []
 sage: j = []
 sage: for i in range(16):
 ...    k = graphs.StarGraph(i+3)
 ...    g.append(k)
 ...
 sage: for i in range(4):
 ...    n = []
 ...    for m in range(4):
 ...        n.append(g[4*i + m].plot(node_size=50, with_labels=False))
 ...    j.append(n)
 ...
 sage: G = sage.plot.plot.GraphicsArray(j)
 sage: G.show()

attachment:star_array_pd.png

2.3.4.6. With the spring-layout algorithm:

 sage: g = []
 sage: j = []
 sage: for i in range(16):
 ...    spr = NX.star_graph(i+3)       
 ...    k = Graph(spr)
 ...    g.append(k)
 ...
 sage: for i in range(4):
 ...    n = []
 ...    for m in range(4):
 ...        n.append(g[4*i + m].plot(node_size=50, with_labels=False))
 ...    j.append(n)
 ...
 sage: G = sage.plot.plot.GraphicsArray(j)
 sage: G.show()

attachment:star_array_spr.png

2.4. Wheel Graphs

2.4.1. Info

2.4.2. Plotting

2.4.3. Code

pos_dict = {}
        pos_dict[0] = [0,0]
        for i in range(n)[1:]:
            x = float(functions.cos((pi/2) + ((2*pi)/(n-1))*(i-1)))
            y = float(functions.sin((pi/2) + ((2*pi)/(n-1))*(i-1)))
            pos_dict[i] = [x,y]
        G = NX.wheel_graph(n)
        return graph.Graph(G, pos=pos_dict, name="Wheel graph on %d vertices"%n)

2.4.4. Examples

2.4.4.1. The following examples require NetworkX (to use default):

 sage: import networkx as NX

2.4.4.2. Compare the constructor speeds.

 time n = NX.wheel_graph(3989); spring3989 = Graph(n)

 time posdict3989 = graphs.WheelGraph(3989)

2.4.4.3. Compare the plotting speeds.

 sage: n = NX.wheel_graph(23)
 sage: spring23 = Graph(n)
 sage: posdict23 = graphs.WheelGraph(23)

 time spring23.show()

attachment:wheel_spr23.png

 time posdict23.show()

attachment:wheel_pd23.png

2.4.4.4. View many wheel graphs as a SAGE Graphics Array.

2.4.4.5. With the position dictionary filled:

 sage: g = []
 sage: j = []
 sage: for i in range(16):
 ...    k = graphs.WheelGraph(i+3)
 ...    g.append(k)
 ...
 sage: for i in range(4):
 ...    n = []
 ...    for m in range(4):
 ...        n.append(g[4*i + m].plot(node_size=50, with_labels=False))
 ...    j.append(n)
 ...
 sage: G = sage.plot.plot.GraphicsArray(j)
 sage: G.show()

attachment:wheel_array_pd.png

2.4.4.6. With the spring-layout algorithm:

 sage: g = []
 sage: j = []
 sage: for i in range(16):
 ...    spr = NX.wheel_graph(i+3)       
 ...    k = Graph(spr)
 ...    g.append(k)
 ...
 sage: for i in range(4):
 ...    n = []
 ...    for m in range(4):
 ...        n.append(g[4*i + m].plot(node_size=50, with_labels=False))
 ...    j.append(n)
 ...
 sage: G = sage.plot.plot.GraphicsArray(j)
 sage: G.show()

attachment:wheel_array_spr.png

3. Named Graphs

3.1. Petersen

3.1.1. Info

3.1.2. Plotting

only has 10 vertices and 14 edges.

3.1.3. Properties

3.1.4. Code

 pos_dict = {}
 for i in range(5):
     x = float(functions.cos(pi/2 + ((2*pi)/5)*i))
     y = float(functions.sin(pi/2 + ((2*pi)/5)*i))
     pos_dict[i] = [x,y]
 for i in range(10)[5:]:
     x = float(0.5*functions.cos(pi/2 + ((2*pi)/5)*i))
     y = float(0.5*functions.sin(pi/2 + ((2*pi)/5)*i))
     pos_dict[i] = [x,y]
 P = graph.Graph({0:[1,4,5], 1:[0,2,6], 2:[1,3,7], 3:[2,4,8], 4:[0,3,9],\
            5:[0,7,8], 6:[1,8,9], 7:[2,5,9], 8:[3,5,6], 9:[4,6,7]},\
            pos=pos_dict, name="Petersen graph")
 return P

3.1.5. Examples

3.1.5.1. Petersen Graph as constructed in this database

 sage: petersen_database = graphs.PetersenGraph()
 sage: petersen_database.show()

attachment:petersen_pos.png

3.1.5.2. Petersen Graph plotted using the spring layout algorithm

 sage: petersen_spring = Graph({0:[1,4,5], 1:[0,2,6], 2:[1,3,7], 3:[2,4,8], 4:[0,3,9],\
                    5:[0,7,8], 6:[1,8,9], 7:[2,5,9], 8:[3,5,6], 9:[4,6,7]})
 sage: petersen_spring.show()

attachment:petersen_spring.png

4. Graph Families

4.1. Complete Graphs

4.1.1. Info

4.1.2. Plotting

4.1.3. Code

 pos_dict = {}
 for i in range(n):
     x = float(functions.cos((pi/2) + ((2*pi)/n)*i))
     y = float(functions.sin((pi/2) + ((2*pi)/n)*i))
     pos_dict[i] = [x,y]
 G = NX.complete_graph(n)
 return graph.Graph(G, pos=pos_dict, name="Complete graph on %d vertices"%n)

4.1.4. Examples

4.1.4.1. The following examples require NetworkX (to use default):

 sage: import networkx as NX

4.1.4.2. Compare the constructor speeds.

 time n = NX.complete_graph(1559); spring1559 = Graph(n)

 time posdict1559 = graphs.CompleteGraph(1559)

4.1.4.3. Compare the plotting speeds.

 sage: n = NX.complete_graph(23)
 sage: spring23 = Graph(n)
 sage: posdict23 = graphs.CompleteGraph(23)

 time spring23.show()

attachment:complete_spr23.png

 time posdict23.show()

attachment:complete_pd23.png

4.1.4.4. View many Complete graphs as a SAGE Graphics Array.

4.1.4.5. With the position dictionary filled:

 sage: g = []
 sage: j = []
 sage: for i in range(9):
 ...    k = graphs.CompleteGraph(i+3)
 ...    g.append(k)
 ...
 sage: for i in range(3):
 ...    n = []
 ...    for m in range(3):
 ...        n.append(g[3*i + m].plot(node_size=50, with_labels=False))
 ...    j.append(n)
 ...
 sage: G = sage.plot.plot.GraphicsArray(j)
 sage: G.show()

attachment:complete_array_pd.png

4.1.4.6. With the spring-layout algorithm:

 sage: g = []
 sage: j = []
 sage: for i in range(9):
 ...    spr = NX.complete_graph(i+3)       
 ...    k = Graph(spr)
 ...    g.append(k)
 ...
 sage: for i in range(3):
 ...    n = []
 ...    for m in range(3):
 ...        n.append(g[3*i + m].plot(node_size=50, with_labels=False))
 ...    j.append(n)
 ...
 sage: G = sage.plot.plot.GraphicsArray(j)
 sage: G.show()

attachment:complete_array_spr.png

4.2. Complete Bipartite Graphs

4.2.1. Info

4.2.2. Plotting

4.2.3. Code

 pos_dict = {}
 c1 = 1 # scaling factor for top row
 c2 = 1 # scaling factor for bottom row
 c3 = 0 # pad to center if top row has 1 node
 c4 = 0 # pad to center if bottom row has 1 node
 if n1 > n2:
     if n2 == 1:
         c4 = (n1-1)/2
     else:
         c2 = ((n1-1)/(n2-1))
 elif n2 > n1:
     if n1 == 1:
         c3 = (n2-1)/2
     else:
         c1 = ((n2-1)/(n1-1))
 for i in range(n1):
     x = c1*i + c3
     y = 1
     pos_dict[i] = [x,y]
 for i in range(n1+n2)[n1:]:
      x = c2*(i-n1) + c4
      y = 0
      pos_dict[i] = [x,y]
 G = NX.complete_bipartite_graph(n1,n2)
 return graph.Graph(G, pos=pos_dict, name="Complete bipartite graph on %d vertices"%(n1+n2))

4.2.4. Examples

4.2.4.1. The following examples require NetworkX (to use default):

 sage: import networkx as NX

4.2.4.2. Compare the constructor speeds.

 time n = NX.complete_bipartite_graph(389,157); spring_big = Graph(n)

 time posdict_big = graphs.CompleteBipartiteGraph(389,157)

4.2.4.3. Compare the plotting speeds.

 sage: n = NX.complete_bipartite_graph(11,17)
 sage: spring_med = Graph(n)
 sage: posdict_med = graphs.CompleteBipartiteGraph(11,17)

 time spring_med.show()

attachment:compbip_spr_med.png

 time posdict_med.show()

attachment:compbip_pd_med.png

4.2.4.4. View many Complete Bipartite graphs as a SAGE Graphics Array.

4.2.4.5. With the position dictionary filled:

 sage: g = []
 sage: j = []
 sage: for i in range(9):
 ...    k = graphs.CompleteBipartiteGraph(i+1,4)
 ...    g.append(k)
 ...
 sage: for i in range(3):
 ...    n = []
 ...    for m in range(3):
 ...        n.append(g[3*i + m].plot(node_size=50, with_labels=False))
 ...    j.append(n)
 ...
 sage: G = sage.plot.plot.GraphicsArray(j)
 sage: G.show()

attachment:compbip_array_pd.png

4.2.4.6. With the spring-layout algorithm:

 sage: g = []
 sage: j = []
 sage: for i in range(9):
 ...    spr = NX.complete_bipartite_graph(i+1,4)       
 ...    k = Graph(spr)
 ...    g.append(k)
 ...
 sage: for i in range(3):
 ...    n = []
 ...    for m in range(3):
 ...        n.append(g[3*i + m].plot(node_size=50, with_labels=False))
 ...    j.append(n)
 ...
 sage: G = sage.plot.plot.GraphicsArray(j)
 sage: G.show()

attachment:compbip_array.spr.png

5. Random Graph Generators

5.1. RandomGNP

5.1.1. Info

5.1.2. Plotting

5.1.3. Code

 G = NX.gnp_random_graph(n, p, seed)
 return graph.Graph(G)

5.1.4. Examples

5.1.4.1. Compare the speed of RandomGNP and RandomGNPFast:

5.1.4.2. Sparse Graphs

 time regular_sparse = graphs.RandomGNP(1559,.22)

 time fast_sparse =  graphs.RandomGNPFast(1559,.22)

5.1.4.3. Dense Graphs

 time regular_dense = graphs.RandomGNP(1559,.88)

 time fast_dense = graphs.RandomGNP(1559,.88)

5.1.4.4. Plot a random graph on 12 nodes with p = .71

 sage: gnp = graphs.RandomGNP(12,.71)
 sage: gnp.show()

attachment:rand_reg.png

5.1.4.5. View many random graphs using a SAGE Graphics Array

 sage: g = []
 sage: j = []
 sage: for i in range(16):
 ...    k = graphs.RandomGNP(i+3,.43)
 ...    g.append(k)
 ...
 sage: for i in range(4):
 ...    n = []
 ...    for m in range(4):
 ...        n.append(g[4*i + m].plot(node_size=50, with_labels=False))
 ...    j.append(n)
 ...
 sage: G = sage.plot.plot.GraphicsArray(j)
 sage: G.show()

attachment:rand_array_reg.png

5.2. RandomGNPFast

5.2.1. Info

5.2.2. Plotting

5.2.3. Code

 G = NX.fast_gnp_random_graph(n, p, seed)
 return graph.Graph(G)

5.2.4. Examples

5.2.4.1. Compare the speed of RandomGNP and RandomGNPFast:

5.2.4.2. Sparse Graphs

 time regular_sparse = graphs.RandomGNP(1559,.22)

 time fast_sparse =  graphs.RandomGNPFast(1559,.22)

5.2.4.3. Dense Graphs

 time regular_dense = graphs.RandomGNP(1559,.88)

 time fast_dense = graphs.RandomGNP(1559,.88)

5.2.4.4. Plot a random graph on 12 nodes with p = .71

 sage: fast = graphs.RandomGNPFast(12,.71)
 sage: fast.show()

attachment:rand_fast.png

5.2.4.5. View many random graphs using a SAGE Graphics Array

 sage: g = []
 sage: j = []
 sage: for i in range(16):
 ...    k = graphs.RandomGNPFast(i+3,.43)
 ...    g.append(k)
 ...
 sage: for i in range(4):
 ...    n = []
 ...    for m in range(4):
 ...        n.append(g[4*i + m].plot(node_size=50, with_labels=False))
 ...    j.append(n)
 ...
 sage: G = sage.plot.plot.GraphicsArray(j)
 sage: G.show()

attachment:rand_array_fast.png