1 // Copyright 2005 The Trustees of Indiana University.
3 // Use, modification and distribution is subject to the Boost Software
4 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
7 // Authors: Douglas Gregor
9 #include <boost/graph/compressed_sparse_row_graph.hpp>
11 #include <boost/graph/iteration_macros.hpp>
14 #include <boost/graph/graphviz.hpp>
16 using namespace boost
;
26 typedef std::pair
<int, int> E
;
27 const char* urls
[6] = {
28 "http://www.boost.org/libs/graph/doc/index.html",
29 "http://www.boost.org/libs/graph/doc/table_of_contents.html",
30 "http://www.boost.org/libs/graph/doc/adjacency_list.html",
31 "http://www.boost.org/libs/graph/doc/history.html",
32 "http://www.boost.org/libs/graph/doc/bundles.html",
33 "http://www.boost.org/libs/graph/doc/using_adjacency_list.html",
36 E the_edges
[] = { E(0, 1), E(0, 2), E(0, 3), E(1, 0), E(1, 3), E(1, 5),
37 E(2, 0), E(2, 5), E(3, 1), E(3, 4), E(4, 1), E(5, 0),
40 typedef compressed_sparse_row_graph
<directedS
, WebPage
> WebGraph
;
41 WebGraph
g(boost::edges_are_sorted
, &the_edges
[0], &the_edges
[0] + sizeof(the_edges
)/sizeof(E
), 6);
43 // Set the URLs of each vertex
45 BGL_FORALL_VERTICES(v
, g
, WebGraph
)
46 g
[v
].url
= urls
[index
++];
48 // Output each of the links
49 std::cout
<< "The web graph:" << std::endl
;
50 BGL_FORALL_EDGES(e
, g
, WebGraph
)
51 std::cout
<< " " << g
[source(e
, g
)].url
<< " -> " << g
[target(e
, g
)].url
54 // Output the graph in DOT format
55 dynamic_properties dp
;
56 dp
.property("label", get(&WebPage::url
, g
));
57 std::ofstream
out("web-graph.dot");
58 write_graphviz(out
, g
, dp
, std::string(), get(vertex_index
, g
));