3 Copyright (C) 2001, Andreas Scherer, Jeremy Siek, Lie-Quan Lee,
6 Distributed under the Boost Software License, Version 1.0.
7 (See accompanying file LICENSE_1_0.txt or copy at
8 http://www.boost.org/LICENSE_1_0.txt)
11 <Title>Boost Graph Library: Stanford Graph Interface
</Title>
12 <BODY BGCOLOR=
"#ffffff" LINK=
"#0000ee" TEXT=
"#000000" VLINK=
"#551a8b"
14 <IMG SRC=
"../../../boost.png"
15 ALT=
"C++ Boost" width=
"277" height=
"86">
20 Using SGB Graphs in BGL
23 The Boost Graph Library (BGL) header,
<a
24 href=
"../../../boost/graph/stanford_graph.hpp"
25 ><tt><boost/graph/stanford_graph.hpp
></tt></a>, adapts a
26 Stanford GraphBase (SGB)
<tt>Graph
</tt> pointer into a BGL-compatible
27 <a href=
"./VertexListGraph.html">VertexListGraph
</a>.
Note that
28 a graph adaptor
<b>class
</b> is
<i>not
</i> used; SGB's
<tt>Graph*
</tt>
29 itself becomes a model of VertexListGraph.
The VertexListGraph
30 concept is fulfilled by defining the appropriate non-member functions
33 <H2><a name=
"sec:SGB"></a>
34 The Stanford GraphBase
38 "The <a href="http://www-cs-staff.stanford.edu/~knuth/sgb.html
">Stanford
39 GraphBase</a> (SGB) is a collection of datasets and computer programs that
40 generate and examine a wide variety of graphs and networks." The SGB was
41 developed and published by
42 <a href=
"http://www-cs-staff.stanford.edu/~knuth">Donald E. Knuth
</a>
43 in
1993.
The fully documented source code is available for anonymous ftp
44 from
<a href=
"ftp://labrea.stanford.edu/pub/sgb/sgb.tar.gz">Stanford
45 University
</a> and in the book
"The Stanford GraphBase, A Platform for
46 Combinatorial Computing," published jointly by ACM Press and Addison-Wesley
47 Publishing Company in
1993.
(This book contains several chapters with
48 additional information not available in the electronic distribution.)
50 <H3><a name=
"sec:CWEB"></a>
54 The source code of SGB is written in accordance with the rules of the
55 <a href=
"http://www-cs-staff.stanford.edu/~knuth/lp.html">Literate
56 Programming
</a> paradigm, so you need to make sure that your computer supports
57 the
<a href=
"http://www-cs-staff.stanford.edu/~knuth/cweb.html">CWEB
</a>
58 system.
The CWEB sources are available for anonymous ftp from
59 <a href=
"ftp://labrea.stanford.edu/pub/cweb/cweb.tar.gz">Stanford
60 University
</a>.
Bootstrapping CWEB on Unix systems is elementary and
61 documented in the CWEB distribution; pre-compiled binary executables of the
62 CWEB tools for Win32 systems are available from
63 <a href=
"http://www.literateprogramming.com">www.literateprogramming.com
</a>.
65 <H3><a name=
"sec:SGB:Installation"></a>
69 After you have acquired the
<a href=
"#sec:SGB">SGB sources
</a> and have
70 installed a working
<a href=
"#sec:CWEB">CWEB system
</a> (at least the
71 "ctangle" processor is required), you're almost set for compiling the SGB
72 sources.
SGB is written in
"old-style C," but the Boost Graph Library
73 expects to handle
"modern C" and C++.
Fortunately, the SGB distribution
74 comes with an appropriate set of patches that convert all the sources from
75 "KR-C" to
"ANSI-C," thus allowing for smooth integration of the Stanford
76 GraphBase in the Boost Graph Library.
80 <b>Unix
</b>: After extracting the SGB archive, but prior to invoking
81 "<tt>make tests</tt>" and
"<tt>make install</tt>," you should say
82 "<tt>ln -s PROTOTYPES/*.ch .</tt>" in the root directory where you extracted
83 the SGB files (or you can simply copy the change files next to the proper
84 source files).
The Unix
<tt>Makefile
</tt> coming with SGB conveniently
85 looks for
"change files" matching the SGB source files and automatically
86 applies them with the
"ctangle" processor.
The resulting C files will
87 smoothly run through the compiler.
90 <b>Win32
</b>: The
"MSVC" subdirectory of the SGB distribution contains a
91 complete set of
"Developer Studio Projects" (and a single
"Workspace"),
92 applicable with Microsoft Developer Studio
6.
The installation process
93 is documented in the accompanying file
<tt>README.MSVC
</tt>.
The
"MSVC"
94 contribution has been updated to make use of the
"PROTOTYPES" as well, so you
95 don't need to worry about that.
99 <H3><a name=
"sec:UsingSGB"></a>
103 After you have run
<a href=
"#sec:SGB:Installation">the installation
104 process
</a> of the SGB, you can use the BGL graph interface with the
105 SGB
<tt>Graph*
</tt>,
<a href=
"../../../boost/graph/stanford_graph.hpp"
106 ><tt><boost/graph/stanford_graph.hpp
></tt></a>, which will be
107 described
<a href=
"#sec:BGL:Interface">next
</a>.
All you have to
108 do is tell the C++ compiler where to look for the SGB headerfiles (by
109 default,
<tt>/usr/local/sgb/include
</tt> on Unix and the
"MSVC"
110 subdirectory of the SGB installation on Win32) and the linker where to
111 find the SGB static library file (
<tt>libgb.a
</tt> on Unix and
112 <tt>libgb.lib
</tt> on Win32); consult the documentation of your
113 particular compiler about how to do that.
115 <H3><a name=
"sec:SGB:Problems"></a>
121 <b>Headerfile selection
</b>: The two SGB modules
<tt>gb_graph
</tt> and
122 <tt>gb_io
</tt> use the preprocessor switch
<tt>SYSV
</tt> to select either the
123 headerfile
<tt><string.h
></tt> (if
<tt>SYSV
</tt> is
<tt>#define
</tt>d)
124 or the headerfile
<tt><strings.h
></tt> (if
<tt>SYSV
</tt> is
<i>not
</i>
125 <tt>#define
</tt>d).
Some compilers, like
<tt>gcc
</tt>/
<tt>g++
</tt>,
126 don't care much (
<tt>gcc
</tt> "knows" about the
"string" functions without
127 refering to
<tt><string.h
></tt>), but others, like MSVC on Win32, do (so
128 all
"Developer Studio Projects" in the
"MSVC" subdirectory of the
129 <a href=
"#sec:SGB">SGB distribution
</a> appropriately define
<tt>SYSV
</tt>).
130 You should be careful to set (or not)
<tt>SYSV
</tt> according to the needs of
134 <b>Missing include guards
</b>: None of the SGB headerfiles uses
"internal
135 include guards" to protect itself from multiple inclusion.
To avoid
136 trouble, you must
<i>not
</i> <tt>#include
</tt> any of the SGB headerfiles
137 before or after
<a href=
"#sec:Wrapper">the BGL wrapper
</a> in a compilation
138 unit; it will fully suffice to use the BGL interface.
141 <b>Preprocessor macros
</b>: The SGB headerfiles make liberal use of the
142 preprocessor
<i>without
</i> sticking to a particular convention (like
143 all-uppercase names or a particular prefix).
At the time of writing,
144 already three of these preprocessor macros collide with the conventions of
145 either C++, g++, or BGL, and are fixed in
<a href=
"#sec:Wrapper">the BGL
146 wrapper
</a>.
We can not guarantee that no other preprocessor-induced
147 problems may arise (but we are willing to learn about any such collisions).
151 <H2><a name=
"sec:BGL:Interface"></a>
152 The BGL Interface for the SGB
155 <H3><a name=
"sec:Wrapper"></a>
159 <a href=
"../../../boost/graph/stanford_graph.hpp"
160 ><tt><boost/graph/stanford_graph.hpp
></tt></a>
162 <p> The main purpose of this Boost Graph Library (BGL) headerfile is to
163 <tt>#include
</tt> all global definitions for the general stuff of the
164 <a href=
"#sec:SGB">Stanford GraphBase
</a> (SGB) and its various graph generator
165 functions by reading all
<a href=
"#sec:SGB:Problems">SGB headerfiles
</a> as in
166 section
2 of the
"<tt>test_sample</tt>" program.
168 <p> On top of the SGB stuff, the BGL
<tt>stanford_graph.hpp
</tt>
169 header adds and defines appropriate types and functions for using the
170 SGB graphs in the BGL framework.
Apart from the improved
171 interface, the
<a href=
"#sec:UsingSGB">SGB (static) library
</a> is
172 used
"as is" in the context of BGL.
178 <a href=
"./VertexListGraph.html">Vertex List Graph
</a> and
<a
179 href=
"./PropertyGraph.html">Property Graph
</a>. The set of property
180 tags that can be used with the SGB graph is described in the
<a
181 href=
"#properties">Vertex and Edge Properties
</a> section below.
184 <H3><a name=
"sec:Example"></a>
188 The example program
<a href=
"../example/miles_span.cpp">
189 <tt><example/miles_span.cpp
></tt></a> represents the first
190 application of the generic framework of BGL to an SGB graph.
It
191 uses Prim's algorithm to solve the
"minimum spanning tree"
192 problem.
In addition, the programs
<a
193 href=
"../../../libs/graph/example/girth.cpp">
194 <tt><example/girth.cpp
></tt></a> and
<a
195 href=
"../example/roget_components.cpp">
196 <tt><example/roget_components.cpp
></tt></a> have been ported
197 from the SGB.
We intend to implement more algorithms from SGB in
198 a generic fashion and to provide the remaining example programs of SGB
199 for the BGL framework.
If you would like to help, feel free to
200 submit your contributions!
208 <tt>graph_traits
<Graph*
>::vertex_descriptor
</tt><br><br>
209 The type for the vertex descriptors associated with the
<tt>Graph*
</tt>.
210 We use the type
<tt>Vertex*
</tt> as the vertex descriptor.
214 <tt>graph_traits
<Graph*
>::edge_descriptor
</tt><br><br> The type
215 for the edge descriptors associated with the
<tt>Graph*
</tt>. This is
216 the type
<tt>boost::sgb_edge
</tt>. In addition to supporting all the
217 required operations of a BGL edge descriptor, the
218 <tt>boost::sgb_edge
</tt> class has the following constructor.
220 sgb_edge::sgb_edge(Arc* arc, Vertex* source)
225 <tt>graph_traits
<Graph*
>::vertex_iterator
</tt><br><br>
226 The type for the iterators returned by
<tt>vertices()
</tt>.
230 <tt>graph_traits
<Graph*
>::out_edge_iterator
</tt><br><br>
231 The type for the iterators returned by
<tt>out_edges()
</tt>.
235 <tt>graph_traits
<Graph*
>::adjacency_iterator
</tt><br><br>
236 The type for the iterators returned by
<tt>adjacent_vertices()
</tt>.
240 <tt>graph_traits
<Graph*
>::vertices_size_type
</tt><br><br>
241 The type used for dealing with the number of vertices in the graph.
245 <tt>graph_traits
<Graph*
>::edge_size_type
</tt><br><br>
246 The type used for dealing with the number of edges in the graph.
250 <tt>graph_traits
<Graph*
>::degree_size_type
</tt><br><br>
251 The type used for dealing with the number of edges incident to a vertex
256 <tt>graph_traits
<Graph*
>::directed_category
</tt><br><br>
257 Provides information about whether the graph is directed or
258 undirected. An SGB
<tt>Graph*
</tt> is directed so this type is
259 <tt>directed_tag
</tt>.
263 <tt>graph_traits
<Graph*
>::traversal_category
</tt><br><br>
264 An SGB
<tt>Graph*
</tt> provides traversal of the vertex set,
265 out edges, and adjacent vertices. Therefore the traversal category
266 tag is defined as follows:
268 struct sgb_traversal_tag :
269 public virtual vertex_list_graph_tag,
270 public virtual incidence_graph_tag,
271 public virtual adjacency_graph_tag { };
276 <tt>graph_traits
<Graph*
>::edge_parallel_category
</tt><br><br>
277 This describes whether the graph class allows the insertion of parallel edges
278 (edges with the same source and target).
The SGB
<tt>Graph*
</tt>
279 does not prevent addition of parallel edges, so this type
280 is
<tt>allow_parallel_edge_tag
</tt>.
291 std::pair
<vertex_iterator,
vertex_iterator
>
292 vertices(Graph*
g)
294 Returns an iterator-range providing access to the vertex set of graph
300 std::pair
<out_edge_iterator,
out_edge_iterator
>
301 out_edges(vertex_descriptor
v, Graph*
g)
303 Returns an iterator-range providing access to the out-edges of vertex
304 <tt>v
</tt> in graph
<tt>g
</tt>.
<br>
305 There is no corresponding
<tt>in_edges
</tt> function.
310 std::pair
<adjacency_iterator,
adjacency_iterator
>
311 adjacent_vertices(vertex_descriptor
v, Graph*
g)
313 Returns an iterator-range providing access to the adjacent vertices of vertex
314 <tt>v
</tt> in graph
<tt>g
</tt>.
320 source(edge_descriptor
e, Graph*
g)
322 Returns the source vertex of edge
<tt>e
</tt>.
328 target(edge_descriptor
e, Graph*
g)
330 Returns the target vertex of edge
<tt>e
</tt>.
336 out_degree(vertex_descriptor
v, Graph*
g)
338 Returns the number of edges leaving vertex
<tt>v
</tt>.
<br>
339 There is no corresponding
<tt>in_degree
</tt> function.
345 num_vertices(Graph*
g)
347 Returns the number of vertices in the graph
<tt>g
</tt>.
353 num_edges(Graph*
g)
355 Returns the number of edges in the graph
<tt>g
</tt>.
361 vertex(vertices_size_type
n, Graph*
g)
363 Returns the (
0-based) nth vertex in the graph's vertex list.
368 template
<class
<a href=
"./PropertyTag.html">PropertyTag
</a>>
369 property_map
<Graph*, PropertyTag
>::type
370 get(PropertyTag, Graph*
& g)
372 template
<class
<a href=
"./PropertyTag.html">PropertyTag
</a>>
373 property_map
<Graph*, Tag
>::const_type
374 get(PropertyTag, const Graph*
& g)
376 Returns the property map object for the vertex property specified by
377 <TT>PropertyTag
</TT>. The
<TT>PropertyTag
</TT> must be one of
382 <h3><a name=
"properties">Vertex and Edge Properties
</a></h3>
384 The SGB
<tt>Vertex
</tt> and
<tt>Arc
</tt> structures provide
385 "utility
" fields for storing extra information. We provide
386 BGL wrappers that provide access to these fields through
<a
387 href=
"../../property_map/doc/property_map.html">property maps
</a>. In
388 addition, vertex index and edge length maps are provided. A property
389 map object can be obtained from a SGB
<tt>Graph*
</tt> using the
390 <tt>get()
</tt> function described in the
<a
391 href=
"./PropertyGraph.html">Property Graph
</a> concept.
394 The following list of property tags can be used to specify which
395 utility field you would like a property map for.
399 <i>// vertex properties
</i>
400 template
<class T
> u_property;
401 template
<class T
> v_property;
402 template
<class T
> w_property;
403 template
<class T
> x_property;
404 template
<class T
> y_property;
405 template
<class T
> z_property;
407 <i>// edge properties
</i>
408 template
<class T
> a_property;
409 template
<class T
> b_property;
413 The template parameter
<tt>T
</tt> for these tags is limited to the
414 types in the
<tt>util
</tt> union declared in the SGB header
415 <tt>gb_graph.h
</tt>, which are
<tt>Vertex*
</tt>,
<tt>Arc*
</tt>,
416 <tt>Graph*
</tt>,
<tt>char*
</tt>, and
<tt>long
</tt>. The property maps
417 for the utility fields are models of
<a
418 href=
"../../property_map/doc/LvaluePropertyMap.html">Lvalue Property
423 The property map for vertex indices can be obtained using the
424 <tt>vertex_index_t
</tt> tag, and this property map is a
<a
425 href=
"../../property_map/doc/ReadablePropertyMap.html">Readable Property
426 Map
</a>. A property map for edge length's can be obtained using the
427 <tt>edge_length_t
</tt> tag, and this property map is a
<a
428 href=
"../../property_map/doc/LvaluePropertyMap.html">Lvalue Property
429 Map
</a> whose value type is
<tt>long
</tt>.
433 Property map objects can be obtained via the
<tt>get()
</tt> function
434 of the Property Graph concept. The type of the property map is given
435 by the
<a href=
"./property_map.html"><tt>property_map
</tt></a> traits
442 <TD nowrap
>Copyright
© 2001</TD><TD>
443 <A HREF=
"http://people.freenet.de/andreas.scherer">Andreas Scherer
</A>,
445 HREF=
"mailto:andreas_freenet@freenet.de">andreas_freenet@freenet.de
</A>)
<br>
446 <A HREF=
"http://www.boost.org/people/jeremy_siek.htm">Jeremy Siek
</A>,
447 Indiana University (
<A
448 HREF=
"mailto:jsiek@osl.iu.edu">jsiek@osl.iu.edu
</A>)
<br>
449 <A HREF=
"http://www.boost.org/people/liequan_lee.htm">Lie-Quan Lee
</A>,
450 Indiana University (
<A
451 HREF=
"mailto:llee@cs.indiana.edu">llee@cs.indiana.edu
</A>)
<br>
452 <A HREF=
"http://www.osl.iu.edu/~lums">Andrew Lumsdaine
</A>,
453 Indiana University (
<A
454 HREF=
"mailto:lums@osl.iu.edu">lums@osl.iu.edu
</A>)