Boost logo

Boost Users :

From: Jive Dadson (jdadson_at_[hidden])
Date: 2002-05-06 18:21:10


rzako23 wrote:
>
> Consider an application used by a school for keeping track of students,
> courses, teachers, rooms, books, meals, buses and other objects that
> are part of the school [...]
>
> As I understand it, in order to use the BGL -- indeed to use any graph
> library with which I am familiar -- one would have to derive both the
> Student and Course classes from some common base class:
>
> class SchoolObject { ... };
>
> class Student : public SchoolObject { ... };
>
> class Course : public SchoolObject { ... };
>
> Then one could create a graph for which each node is a SchoolObject.

Nope, that's not the way BGL works. BGL was designed specifically to do
the kind of thing you want. Indeed, the BGL distribution contains
simple adapters that allow you to use BGL functions on data types
defined in other graph packages by "other programmers", e.g. Stanford
GraphBase and LEDA.

STL containers work differently than BGL graphs, but they don't require
a "SchooldObject" base class either. (I don't know of any C++ library
that does!) You can create STL containers that contain references
(pointers) to objects. The underlying objects are not "part of" or
"owned by" the containers, and don't necessarily need to "know" that
they are referenced by the containers.

BGL graphs are even more detached from application-level semantics.
They are pure graph abstractions - opaque edges and vertices, and that's
all. If you are holding two distinct BGL edges, they are like two
potatoes that are so similar that "the only difference between them is
that they are different." The association between edges/vertices and
their labels is not part of the graph. Instead, the programmer creates
the association using abstract "property maps". You could, for example,
use an STL container, such as a map<>, to implement the property map.
Frequently, a vector<> or deque<> will suffice. You can have more than
one set of labels for a graph, and you can use them simultaneously. For
example, you can have one set of labels that implement the
application-semantics and another that is used by an algorithm to "mark"
vertices as the algorithm inspects them.

I highly recommend The Boost Graph Library User Guide and Reference
Manual by Jeremy G. Siek, et al.

Jive


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net