boost : : boost.graph : : adjacency_list














































boost : : boost.graph : : adjacency_list




Using boost_adjacency_list


Graphs consist of points and lines. To create a graph, you have to define a set of points and any lines between them. The example code below contains a first simple graph consisting of four points and no lines.


An example code for a graph of type boost :: adjacency_list with four vertices


#include <boost/graph/adjacency_list.hpp> #include <iostream> using namespace boost; int main() { adjacency_list<> g; adjacency_list<>::vertex_descriptor v1 = add_vertex(g); adjacency_list<>::vertex_descriptor v2 = add_vertex(g); adjacency_list<>::vertex_descriptor v3 = add_vertex(g); adjacency_list<>::vertex_descriptor v4 = add_vertex(g); std::cout << v1 << ", " << v2 << ", " << v3 << ", " << v4 << '\n'; }



Output





Boost.Graph provides three containers to define graphs. 

The most important container is boost::adjacency_list which is used in nearly all of the examples in this chapter. To use this class, include the header file boost/graph/adjacency_list.hpp. If you want to use another container, you must include another header file. There is no master header file to get access to all classes and functions from Boost.Graph.

boost::adjacency_list is a template that is instantiated with default parameters in the above example code. This class is defined in boost. All classes and functions from Boost.Graph are defined in this namespace.

The above example identifies points through positive integers. These numbers are indexes to a vector that is used internally in boost::adjacency_list.







Comments