Boost Graph Library, The: User Guide and Reference Manual
- By Jeremy G. Siek, Lie-Quan Lee, Andrew Lumsdaine
- Published Dec 20, 2001 by Addison-Wesley Professional. Part of the C++ In-Depth Series series.
- Copyright 2002
- Dimensions: 7-3/8x9-1/4
- Pages: 352
- Edition: 1st
- ISBN-10: 0-201-72914-8
- ISBN-13: 978-0-201-72914-6
Register your product to gain access to bonus material or receive a coupon.
Product Author Bios
Jeremy G. Siek is a leading expert in C++ and generic programming and is currently pursuing his doctoral degree at Indiana University. He is interested in the design of programming languages that support generic programming and in high performance libraries. Jeremy is a member of the ISO C++ Standards Committee and is an active member of the Boost C++ Library Group, where he has contributed several libraries in addition to the BGL.
Lie-Quan (Rich) Lee developed the first version of the BGL. A doctoral candidate at the University of Notre Dame, his research interests include generic programming, scientific component libraries, and high performance computing. Rich is an active member of the Boost C++ Library Group.
Andrew Lumsdaine is an Associate Professor in the Computer Science Department and Associate Director of the Open Systems Laboratory at Indiana University. In addition to generic programming and software engineering, his research program includes projects in computational science and engineering, parallel and distributed computing, mathematical software, and numerical analysis. Andrew is a member of the ISO C++ Standards Committee and the Boost C++ Library Group.
“This book is unique because it discusses graph algorithms in terms of generic programming, and because it presents a concrete, usable library that embodies those algorithms.”—Matthew H. Austern, AT & T Labs-Research
The Boost Graph Library (BGL) is the first C++ library to apply the principles of generic programming to the construction of the advanced data structures and algorithms used in graph computations. Problems in such diverse areas as Internet packet routing, molecular biology, scientific computing, and telephone network design can be solved by using graph theory. This book presents an in-depth description of the BGL and provides working examples designed to illustrate the application of BGL to these real-world problems.
Written by the BGL developers, The Boost Graph Library: User Guide and Reference Manual gives you all the information you need to take advantage of this powerful new library. Part I is a complete user guide that begins by introducing graph concepts, terminology, and generic graph algorithms. This guide also takes the reader on a tour through the major features of the BGL; all motivated with example problems. Part II is a comprehensive reference manual that provides complete documentation of all BGL concepts, algorithms, and classes.
Readers will find coverage of:
Groundbreaking in its scope, this book offers the key to unlocking the power of the BGL for the C++ programmer looking to extend the reach of generic programming beyond the Standard Template Library.
30 of 30 people found the following review helpful
Solid and entertaining,
This review is from: The Boost Graph Library: User Guide and Reference Manual (Paperback)The first part of this book applies the algorithms of the Boost Graph Library (BGL) in fun ways. For example, it solves the problem of Make-style file dependency checking using BGL. And it explores everybody's favorite pastime, "Six Degrees of Kevin Bacon" and similar problems. These real-life examples greatly spice up an otherwise very boring topic.
BGL uses concept checking and property maps and a few other Boost approaches that aren't very well explored in the text. Granted, it's not a book about C++ programming in general (like "Modern C++ Design") but a bit more coverage of these key ideas would have been nice. Also, unlike the STL, several of the alogirithms are named by their canonical names instead of simply specifying their behavior and performance (e.g. names like dijkstra_visitor and bellman_visitor vs. list and map) . This means that library users may need to refer back to the text to figure out which algorithm they desire.
The choice to typeset... Read more
12 of 12 people found the following review helpful
A fine addition for any STL/C++ programmer,
This review is from: The Boost Graph Library: User Guide and Reference Manual (Paperback)The boost graph library extends the STL tool box of containers into graph containers. Wished for a general purpose graph? This is the place. Never studied graph's in a CS course, but know basic data structures like lists, hashes and trees? This is a fine place to start. The book goes from basic, what is a graph good for, (solving search, and routing problems) to what are the various drawbacks to the different approaches.
If you are used to using the C++ STL library you will feel right at home using this. (BTW this library works with MSVC 6.5)
9 of 9 people found the following review helpful
Excellent book on applied graph theory with the BGL,
This review is from: The Boost Graph Library: User Guide and Reference Manual (Paperback)I really like the BGL book!
What strikes me the most is the accessibility - the introductions hit the right key immediately, so there's really no need to keep reference material at hand. The samples are equally good, and they're the right size to be easily transformed into solutions to related problems. The book currently rests on my bedside table, and only my favorites make it there...
Room for improvements:
Finally: I like the book a lot, and even if you're not "a graph person", chances are that you will be after reading the BGL book.
I highly recommend it!
› See all 10 customer reviews...
Online Sample Chapter
Table of Contents
I User Guide.
2.Generic Programming in C++.
3. A BGL Tutorial.
4. Basic Graph Algorithms.
5. Shortest-Paths Problems.
6. Minimum-Spanning-Tree Problem.
7. Connected Components.
8. Maximum Flow.
9. Implicit Graphs: A Knight's Tour.
10. Interfacing with Other Graph Libraries.
11. Performance Guidelines.
12. BGL Concepts.
13. BGL Algorithms.
14. BGL Classes.
15. Property Map Library.
16 Auxiliary Concepts, Classes, and Functions.
The graph abstraction is a powerful problem-solving tool used to describe relationships between discrete objects. Many practical problems can be modeled in their essential form by graphs. Such problems appear in many domains: Internet packet routing, telephone network design, software build systems, Web search engines, molecular biology, automated road-trip planning, scientific computing, and so on. The power of the graph abstraction arises from the fact that the solution to a graph-theoretic problem can be used to solve problems in a wide variety of domains. For example, the problem of solving a maze and the problem of finding groups of Web pages that are mutually reachable can both be solved using depth-first search, an important concept from graph theory. By concentrating on the essence of these problems—the graph model describing discrete objects and the relationships between them—graph theoreticians have created solutions to not just a handful of particular problems, but to entire families of problems.
Now a question arises. If graph theory is generally and broadly applicable to arbitrary problem domains, should not the software that implements graph algorithms be just as broadly applicable? Graph theory would seem to be an ideal area for software reuse. However, up until now the potential for reuse has been far from realized. Graph problems do not typically occur in a pure graph-theoretic form, but rather are embedded in larger domain-specific problems. As a result, the data to be modeled as a graph are often not explicitly represented as a graph but are instead encoded in some application-specific data structure. Even in the case where the application data are explicitly represented as a graph, the particular graph representation chosen by the programmer might not match the representation expected by a library that the programmer wants to use. Moreover, different applications may place different time and space requirements on the graph data structure.
This implies a serious problem for the graph library writer who wants to provide reusable software, for it is impossible to anticipate every possible data structure that might be needed and to write a different version of the graph algorithm specifically for each one. The current state of affairs is that graph algorithms are written in terms of whatever data structure is most convenient for the algorithm and users must convert their data structures to that format in order to use the algorithm. This is an inefficient undertaking, consuming programmer time and computational resources. Often, the cost is perceived not to be worthwhile, and the programmer instead chooses to rewrite the algorithm in terms of his or her own data structure. This approach is also time consuming and error prone, and will tend to lead to sub-optimal solutions since the application programmer may not be a graph algorithms expert.
Generic ProgrammingThe Standard Template Library (STL) was introduced in 1994 and was adopted shortly thereafter into the C++ Standard. The STL was a library of interchangeable components for solving many fundamental problems on sequences of elements. What set the STL apart from libraries that came before it was that each STL algorithm could work with a wide variety of sequential datastructures: linked-lists, arrays, sets, and so on. The iterator abstraction provided an interface between containers and algorithms and the C++ template mechanism provided the needed flexibility to allow implementation without loss of efficiency. Each algorithm in the STL is a function template parameterized by the types of iterators upon which it operates. Any iterator that satisfies a minimal set of requirements can be used regardless of the data structure traversed by the iterator. The systematic approach used in the STL to construct abstractions and interchangeable components is called generic programming.
Generic programming lends itself well to solving the reusability problem for graph libraries. With generic programming, graph algorithms can be made much more flexible, allowing them to be easily used in a wide variety applications. Each graph algorithm is written not in terms of a specific data structure, but instead to a graph abstraction that can be easily implemented by many different data structures. Writing generic graph algorithms has the additional advantage of being more natural; the abstraction inherent in the pseudo-code description of an algorithm is retained in the generic function. The Boost Graph Library (BGL) is the first C++ graph library to apply the notions of generic programming to the construction of graph algorithms.
Some BGL HistoryThe Boost Graph Library began its life as the Generic Graph Component Library (GGCL), a software project at the Lab for Scientific Computing (LSC). The LSC, under the direction of Professor Andrew Lumsdaine, was an interdisciplinary laboratory dedicated to research in algorithms, software, tools, and run-time systems for high-performance computational science and engineering.2Special emphasis was put on developing industrial-strength, high performance software using modern programming languages and techniques—most notably, generic programming.
Soon after the Standard Template Library was released, work began at the LSC to apply generic programming to scientific computing. The Matrix Template Library (MTL) was one of the first projects. Many of the lessons learned during construction of the MTL were applied to the design and implementation of the GGCL. The LSC has since evolved into the Open Systems Laboratory (OSL) http://www.osl.iu.edu.Although the name and location have changed, the research agenda remains the same.
An important class of linear algebra computations in scientific computing is that of sparse matrix computations, an area where graph algorithms play an important role. As the LSC was developing the sparse matrix capabilities of the MTL, the need for high-performance reusable (and generic) graph algorithms became apparent. However, none of the graph libraries available at the time (LEDA, GTL, Stanford GraphBase) were written using the generic programming style of the MTL and the STL, and hence did not fulfill the flexibility and high-performance requirements of the LSC. Other researchers were also expressing interest in a generic C++ graph library. During a meeting with Bjarne Stroustrup, we were introduced to several individuals at AT&T who needed such a library. Other early work in the area of generic graph algorithms included some codes written by Alexander Stepanov, as well as Dietmar Kühl’s master’s thesis.
With this in mind, and motivated by homework assignments in his algorithms class ,Jeremy Siek began prototyping an interface and some graph classes in the spring of1998. Lie-Quan Lee then developed the first version of the GGCL, which became his master’s thesis project. During the following year, the authors began collaborating with Alexander Stepanov and Matthew Austern. During this time, Stepanov’s disjoint-sets-based connected components implementation was added to the GGCL, and work began on providing concept documentation for the GGCL, similar to Austern’s STL documentation.
During this year the authors also became aware of Boost and were excited to find an organization interested in creating high-quality, open source C++ libraries. Boost included several people interested in generic graph algorithms, most notably Dietmar Kühl. Some discussions about generic interfaces for graph structures resulted in a revision of the GGCL that closely resembles the current Boost Graph Library interface. On September 4, 2000, the GGCL passed the Boost formal review (managed by David Abrahams) and became the Boost Graph Library. The first release of the BGL was September 27, 2000. The BGL is not a “frozen” library. It continues to grow as new algorithms are contributed, and it continues to evolve to meet users’ needs. We encourage readers to participate in the Boost group and help with extensions to the BGL.
What Is Boost?Boost is an online community that encourages development and peer-review of free C++ libraries. The emphasis is on portable and high-quality libraries that work well with (and are in the same spirit as) the C++ Standard Library. Members of the community submit proposals (library designs and implementations) for review. The Boost community (led by a review manager) then reviews the library, provides feedback to the contributors, and finally renders a decision as to whether the library should be included in the Boost library collection. The libraries are available at the Boost Web site http://www.boost.org. In addition, the Boost mailing list provides an important forum for discussing library plans and for organizing collaboration.
Obtaining and Installing the BGL SoftwareThe Boost Graph Library is available as part of the Boost library collection, which can be obtained in several different ways. The CD accompanying this book contains version 1.25.1 of the Boost library collection. In addition, releases of the Boost library collection can be obtained with your Web browser at http://www.boost.org/boost all.zip for the Windows zip archive of the latest release and http://www.boost.org/boostall.tar.gz for the UNIX archive of the latest release. The Boost libraries can also be downloaded via FTP at ftp://boost.sourceforge.net/pub-/boost/release/.
The zip archive of the Boost library collection can be unzipped by using WinZip or other similar tools. The UNIX “tar ball” can be expanded using the following command:
gunzip _cd boost all.tar.gz j tar xvf _
Extracting the archive creates a directory whose name consists of the word boost and a version number. For example, extracting the Boost release 1.25.1 creates a directory boost 1 25 1. Under this top directory, are two principal subdirectories: boost and libs. The subdirectory boost contains the header files for all the libraries in the collection. The subdirectory libs contains a separate subdirectory for each library in the collection. These subdirectories contain library-specific source and documentation files. You can point your Web browser to boost 1 251/index.htm and navigate the whole Boost library collection.
All of the BGL header files are in the directory boost/graph/. However, other Boost header files are needed since BGL uses other Boost components. The HTML documentation is in libs/graph/doc/ and the source code for the examples is inlibs/graph/example/. Regression tests for BGL are in libs/graph/test/. The source files in libs/graph/src/ implement the Graphviz file parsers and printers.
Except as described next, there are no compilation and build steps necessary to use BGL. All that is required is that the Boost header file directory be added to your compiler’s include path. For example, using Windows 2000, if you have unzipped release 1.25.1 from boost all.zip into the top level directory of your C drive, for Borland, GCC, and Metrowerks compilers add -Ic:/boost 1 25 1 to the compiler command line, and for the Microsoft Visual C++ compiler add /I "c:/boost 1 25 1". For IDEs, add c:/boost 1 25 1 (or whatever you have renamed it to) to the include search paths using the appropriate dialog. Before using the BGL interface to LEDA or Stanford GraphBase, LEDA or GraphBase must be installed according to their installation instructions. To use the read graphviz() functions (for reading AT&T Graphviz files), you must build and link to an additional library under boost 1 251/libs/graph/src.
The Boost Graph Library is written in ISO/IEC Standard C++ and compiles with most C++ compilers. For an up-to-date summary of the compatibility with a particular compiler, see the “Compiler Status” page at the Boost Web site http://www.boost.org/status/- compiler status.html.
How to Use This BookThis book is both a user guide and reference manual for the BGL. It is intended to allow the reader to begin using the BGL for real-life graph problems. This book should also be interesting for programmers who wish to learn more about generic programming. Although there are many books about how to use generic libraries (which in almost all cases means how to use the STL or Standard Library), there is very little available about how actually to build generic software. Yet generic programming is a vitally important new paradigm for software development. We hope that, by way of example, this book will show the reader how to do (and not simply use) generic programming and to apply and extend the generic programming paradigm beyond the basic container types and algorithms of the STL.
The third partner to the user guide and reference manual is the BGL code itself. The BGL code is not simply academic and instructional. It is intended to be used.
For students learning about graph algorithms and data structures, BGL provides a comprehensive graph algorithm framework. The student can concentrate on learning the important theory behind graph algorithms without becoming bogged down and distracted in too many implementation details. For practicing programmers, BGL provides high-quality implementations of graph data structures and algorithms. Programmers will realize significant time saving from this reliability. Time that would have otherwise been spent developing (and debugging) complicated graph data structures and algorithms can now be spent in more productive pursuits. Moreover, the flexible interface to the BGL will allow programmers to apply graph algorithms in settings where a graph may only exist implicitly.
For the graph theoretician, this book makes a persuasive case for the use of generic programming for implementing graph-theoretic algorithms. Algorithms written using the BGL interface will have broad applicability and will be able to be reused innumerous settings.
We assume that the reader has a good grasp of C++. Since there are many sources where the reader can learn about C++, we do not try to teach it here (see the references at the end of the book—The C++ Programming Language, Special ed., by Stroustrup and C++ Primer, 3rd ed., by Josee Lajoie and Stanley B. Lippman are our recommendations). We also assume some familiarity with the STL (see STL Tutorial and Reference Guide by David R. Musser, Gillmer J. Derge, and Atul Sainiand Generic Programming and the STL by Matthew Austern ). We do, however, present some of the more advanced C++ features used to implement generic libraries in general and the BGL in particular. Some necessary graph theory concepts are introduced here, but not in great detail. For a detailed discussion of elementary graph theory see Introduction to Algorithms by T. H. Cormen, C. E. Leiserson, and R.L. Rivest .
The Electronic ReferenceAn electronic version of the book is included on the accompanying CD, in the file bgl-book.pdf. The electronic version is searchable and is fully hyperlinked, making it a useful companion for the printed version. The hyperlinks include all internal references such as the literate programming “part” references as well as links to external Web pages.
AcknowledgmentsWe owe many debts of thanks to a number of individuals who both inspired and encouraged us in developing the BGL and in writing this book. A most profound thanks goes to Alexander Stepanov and David Musser for their pioneering work in generic programming, for their continued encouragement of our work, and for contributions to the BGL. We especially thank David Musser for his careful proofreading of this book. Matthew Austern’s work on documenting the concepts of the STL provided a foundation for creating the concepts in the BGL. We thank Dietmar Kühl for his work on generic graph algorithms and design patterns; especially for the property map abstraction. This work would not have been possible without the expressive power of Bjarne Stroustrup’s C++ language.
Dave Abrahams, Jens Maurer, Dietmar Kühl, Beman Dawes, Gary Powell, Greg Colvin and the rest of the group at Boost provided valuable input to the BGL interface, numerous suggestions for improvement, and proofreads of this book. We also thank the following BGL users whose questions helped to motivate and improve BGL (as well as this book): Gordon Woodhull, Dave Longhorn, Joel Phillips, Edward Luke, and Stephen North.
Thanks to a number of individuals who reviewed the book during its development: Jan Christiaan van Winkel, David Musser, Beman Dawes, and Jeffrey Squyres. A great thanks to our editor Deborah Lafferty; Kim Arney Mulcahy, Cheryl Ferguson, and Marcy Barnes, the production coordinator; and the rest of the team at Addison-Wesley. It was a pleasure to work with them.
Our original work on the BGL was supported in part by NSF grant ACI-9982205. Parts of the BGL were completed while the third author was on sabbatical at Lawrence Berkeley National Laboratory (where the first two authors were occasional guests).All of the graph drawings in this book were produced using the dot program from the Graphviz package.
LicenseThe BGL software is released under an open source “artistic” license. A copy of the BGL license is included with the source code in the LICENSE file.
The BGL may be used freely for both commercial and noncommercial use. The main restriction on BGL is that modified source code can only be redistributed if it is clearly marked as a nonstandard version of BGL. The preferred method for the distribution of BGL, and for submitting changes, is through the Boost Web site.
Downloadable Sample Chapter
Click below for Sample Chapter related to this title:
, (comma), 40
. (period), 40
; (semicolon), 73
Aabstract data types (ADTs), 19
accumulate function, 26-27
basic description of, 13-14
add_edge function, 9, 17, 43, 84, 121, 152-153, 226
EdgeMutablePropertyGraph concept and,157
performance guidelines and, 128
undirected graphs and, 141
AdditiveAbelianGroup class, 20-21
add_vertex function, 9, 43, 120, 152, 157, 128, 225
AdjacencyGraph concept, 46-47, 114, 115, 146-149
adjacency_graph_tag function, 124
adjacency_iterator function, 47, 146
adjacency_list class, 11-12, 13
Bacon numbers and, 63, 65
basic description of, 43
boost namespace and, 37-39
compilation order and, 37, 46
implicit graphs and, 114
interfacing with other graph libraries and,119
internal properties and, 52-53
maximum flow and, 107
minimum-spanning-tree problem and, 92
performance guidelines and, 127, 128, 130, 132
shortest-path problems and, 84
template parameters, 52
using topological sort with, 17-18
adjacency_list.hpp, 17, 216, 246
adjacency_matrix class, 11-12, 43
associated types, 238-239
basic description of, 235-242
member functions, 239-240
nonmember functions, 240-242
template parameters, 238
type requirements, 238
adjacency_vertices function, 46-47, 146
implicit graphs and, 114, 115
maximum flow and, 109
adjacent iterators, 7
ADTs (abstract data types), 19
advance_dispatch function, 33
advance function, 33
Algorithms. See also Algorithms (listed by name)
basic description of, 13-18, 61-74
Koenig lookup and, 39
Algorithms (listed by name) See also Algorithms
bellman_ford_shortest_paths algorithm, 40, 76-82, 162, 182-186
breadth_first_search algorithm, 11, 39, 61-67, 158-159, 165-169
depth_first_search algorithm, 13, 18, 44-46, 57, 67-75, 98, 160-161, 170-175
Dijkstra’s shortest-path algorithm, 76, 81-88, 161, 179-181, 277
Edmunds-Karp algorithm, 105, 109
Ford-Fulkerson algorithm, 105
Kruskal’s algorithm, 90-93, 95, 189-192
Prim’s algorithm, 89, 90, 94-96
push-relabel algorithm, 105
ANSI C, 262
archetype class, 36
array_traits class, 31-33
array traits, for pointer types, 32-33
Array type, 30
Assignable concept, 37, 28-29, 143
Associated types, 28-34, 143, 205
adjacency_list class, 216-217
adjacency_matrix class, 238-239
edge_list class, 251-252
filtered _raph class, 259-260
graph_property_iter_range class, 298
iterator_property_map class, 284
LEDA Graph class, 268-269
property_map class, 249
reverse_graph class, 253-255
associative_property_map adaptor, 103
Austern, Matthew, 28
Bback_edge function, 50, 67, 160
back_edge_recorder class, 70
back_edges vector, 71
backward edge, 106
Bacon, Kevin, 62-67
bacon_number array, 66
basic description of, 61-67
graph setup and, 63-65
input files and, 63-65
classes, 20, 21
basic block, 69
BCCL (Boost Concept Checking Library), 35, 36
bellman_ford_shortest_paths algorithm, 40, 162
basic description of, 76-82, 182-186
named parameters, 184
time complexity and, 185
BellmanFordVisitor concept, 161-162
BFS (breadth-first search), 11, 39. See also breadth_first_search algorithm
Bacon numbers and, 65-67
basic description of, 61-67
visitor concepts and, 158-159
bfs_name_printer class, 11
BFSVisitor interface, 66, 158-159
bgl_named_params class, 40
BidirectionalGraph concept, 69, 72, 124, 145-146
bidirectional_graph_tag class, 124
Binary method problem, 23-24
Boost Concept Checking Library (BCCL), 35, 36
adjacency_list class and, 37-38
basic description of, 37-39
boost:: prefix, 37-38
Boost Property Map Library, 55-56, 79, 80
Boost Tokenizer Library, 63
breadth-first search (BFS), 11, 39. See also breadth_first_search algorithm
Bacon numbers and, 65-67
basic description of, 61-67
visitor concepts and, 158-159
breadth_first_search algorithm, 11, 39. See also breadth-first search (BFS)
Bacon numbers and, 65-67
basic description of, 61-67, 165-169
named parameters, 167
visitor concepts and, 158-159
Breadth-first tree, 61
CC++ (high-level language)
associated types and, 28
binary method problem and, 23-24
code bloat and, 23
concept checking and, 34-37
generic programming in, 19-59
GNU, 127, 128
Koenig lookup and, 38-39
Monoid concept and, 291
named parameters and, 39-40
object-oriented programming and, 22-25
Standard, 22, 28, 55, 125
valid expressions and, 28
capacity_map parameter, 206
cap object, 108
Chessboard, Knight’s tour problem for, 113-118
Class(es). See also Classes (listed by name)
auxiliary, 242-251, 289-298
basic description of, 13-14, 213-275
base, 20, 21
typedefs nested in, 30-31
Classes (listed by name). See also adjacency_list class
AdditiveAbelianGroup class, 20-21
adjacency_matrix class, 11-12, 43, 234-242
adjacency_vertices class, 109, 114, 115
Download the sample pages (includes Chapter 3 and Index)
Click below for Errata related to this title:
Book + eBook Bundle
Book Price $35.99
eBook Price $12.60
eBook formats included
This book includes free shipping!
This book includes free shipping!
Includes EPUB, MOBI, and PDF
About eBook Formats
This eBook includes the following formats, accessible from your Account page after purchase:
EPUBThe open industry format known for its reflowable content and usability on supported mobile devices.
MOBIThe eBook format compatible with the Amazon Kindle and Amazon Kindle applications.
PDFThe popular standard, used most often with the free Adobe® Reader® software.
This eBook requires no passwords or activation to read. We customize your eBook by discretely watermarking it with your name, making it uniquely yours.
Get access to thousands of books and training videos about technology, professional development and digital media from more than 40 leading publishers, including Addison-Wesley, Prentice Hall, Cisco Press, IBM Press, O'Reilly Media, Wrox, Apress, and many more. If you continue your subscription after your 30-day trial, you can receive 30% off a monthly subscription to the Safari Library for up to 12 months. That's a total savings of $199.