C++ Boost

Using SGB Graphs in BGL

The Boost Graph Library (BGL) header, <boost/graph/stanford_graph.hpp>, adapts a Stanford GraphBase (SGB) Graph pointer into a BGL-compatible VertexListGraph.  Note that a graph adaptor class is not used; SGB's Graph* itself becomes a model of VertexListGraph.  The VertexListGraph concept is fulfilled by defining the appropriate non-member functions for Graph*.

A special version of the test_sample.w test routine shipped with the SGB distribution, test_sample.ch, has been created to make sure that the stanford_graph.hpp header is a comprehensive replacement for the complete set of SGB headerfiles.

The Stanford GraphBase

"The Stanford GraphBase (SGB) is a collection of datasets and computer programs that generate and examine a wide variety of graphs and networks."  The SGB was developed and published by Donald E. Knuth in 1993.  The fully documented source code is available for anonymous ftp from Stanford University and in the book "The Stanford GraphBase, A Platform for Combinatorial Computing," published jointly by ACM Press and Addison-Wesley Publishing Company in 1993.  (This book contains several chapters with additional information not available in the electronic distribution.)

Prerequisites

The source code of SGB is written in accordance with the rules of the Literate Programming paradigm, so you need to make sure that your computer supports the CWEB system.  The CWEB sources are available for anonymous ftp from Stanford University.  Bootstrapping CWEB on Unix systems is elementary and documented in the CWEB distribution; pre-compiled binary executables of the CWEB tools for Win32 systems are available from www.literateprogramming.com.

Installing the SGB

After you have acquired the SGB sources and have installed a working CWEB system (at least the "ctangle" processor is required), you're almost set for compiling the SGB sources.  SGB is written in "old-style C," but the Boost Graph Library expects to handle "modern C" and C++.  Fortunately, the SGB distribution comes with an appropriate set of patches that convert all the sources from "KR-C" to "ANSI-C," thus allowing for smooth integration of the Stanford GraphBase in the Boost Graph Library.

Using the SGB

After you have run the installation process of the SGB, you can use the BGL graph interface with the SGB Graph*, <boost/graph/stanford_graph.hpp>, which will be described next.  All you have to do is tell the C++ compiler where to look for the SGB headerfiles (by default, /usr/local/sgb/include on Unix and the "MSVC" subdirectory of the SGB installation on Win32) and the linker where to find the SGB static library file (libgb.a on Unix and libgb.lib on Win32); consult the documentation of your particular compiler about how to do that.

Technicalities

The BGL Interface for the SGB

Where Defined

<boost/graph/stanford_graph.hpp>

The main purpose of this Boost Graph Library (BGL) headerfile is to #include all global definitions for the general stuff of the Stanford GraphBase (SGB) and its various graph generator functions by reading all SGB headerfiles as in section 2 of the "test_sample" program.

On top of the SGB stuff, the BGL stanford_graph.hpp header adds and defines appropriate types and functions for using the SGB graphs in the BGL framework.  Apart from the improved interface, the SGB (static) library is used "as is" in the context of BGL.

Model Of

VertexListGraph

Example

The example program <example/miles_span.cpp> represents the first application of the generic framework of BGL to an SGB graph.  It uses Prim's algorithm to solve the "minimum spanning tree" problem.  We intend to implement more algorithms from SGB in a generic fashion and to provide the remaining example programs of SGB for the BGL framework.  If you would like to help, feel free to submit your contributions!

Associated Types


graph_traits<Graph*>::vertex_descriptor

The type for the vertex descriptors associated with the Graph*.
graph_traits<Graph*>::edge_descriptor

The type for the edge descriptors associated with the Graph*.
graph_traits<Graph*>::vertex_iterator

The type for the iterators returned by vertices().
graph_traits<Graph*>::out_edge_iterator

The type for the iterators returned by out_edges().
graph_traits<Graph*>::adjacency_iterator

The type for the iterators returned by adjacent_vertices().
graph_traits<Graph*>::vertices_size_type

The type used for dealing with the number of vertices in the graph.
graph_traits<Graph*>::edge_size_type

The type used for dealing with the number of edges in the graph.
graph_traits<Graph*>::degree_size_type

The type used for dealing with the number of edges incident to a vertex in the graph.
graph_traits<Graph*>::directed_category

Provides information about whether the graph is directed (directed_tag) or undirected (undirected_tag).
graph_traits<Graph*>::edge_parallel_category

This describes whether the graph class allows the insertion of parallel edges (edges with the same source and target).  The two tags are allow_parallel_edge_tag and disallow_parallel_edge_tag.  The setS and hash_setS variants disallow parallel edges, while the others allow parallel edges.

Non-Member Functions


std::pair<vertex_iterator, vertex_iterator>
vertices(Graph* g)
Returns an iterator-range providing access to the vertex set of graph g.
std::pair<out_edge_iterator, out_edge_iterator>
out_edges(vertex_descriptor v, Graph* g)
Returns an iterator-range providing access to the out-edges of vertex v in graph g.
There is no corresponding in_edges function.
std::pair<adjacency_iterator, adjacency_iterator>
adjacent_vertices(vertex_descriptor v, Graph* g)
Returns an iterator-range providing access to the adjacent vertices of vertex v in graph g.
vertex_descriptor
source(edge_descriptor e, Graph* g)
Returns the source vertex of edge e.
vertex_descriptor
target(edge_descriptor e, Graph* g)
Returns the target vertex of edge e.
degree_size_type
out_degree(vertex_descriptor v, Graph* g)
Returns the number of edges leaving vertex v.
There is no corresponding in_degree function.
vertices_size_type
num_vertices(Graph* g)
Returns the number of vertices in the graph g.
edge_size_type
num_edges(Graph* g)
Returns the number of edges in the graph g.
vertex_descriptor
vertex(vertices_size_type n, Graph* g)
Returns the (0-based) nth vertex in the graph's vertex list.
Copyright © 2001 Andreas Scherer, Aachen (andreas.scherer@pobox.com)
Jeremy Siek, Univ.of Notre Dame (jsiek@lsc.nd.edu)
Lie-Quan Lee, Univ.of Notre Dame (llee1@lsc.nd.edu)
Andrew Lumsdaine, Univ.of Notre Dame (lums@lsc.nd.edu)