• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2005 The Trustees of Indiana University.
2 
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)
6 
7 //  Authors: Douglas Gregor
8 //           Andrew Lumsdaine
9 
10 #include <boost/graph/compressed_sparse_row_graph.hpp>
11 #include <string>
12 #include <boost/graph/iteration_macros.hpp>
13 #include <iostream>
14 #include <fstream>
15 #include <boost/graph/graphviz.hpp>
16 
17 using namespace boost;
18 
19 class WebPage
20 {
21 public:
22     std::string url;
23 };
24 
main()25 int main()
26 {
27     typedef std::pair< int, int > E;
28     const char* urls[6] = {
29         "http://www.boost.org/libs/graph/doc/index.html",
30         "http://www.boost.org/libs/graph/doc/table_of_contents.html",
31         "http://www.boost.org/libs/graph/doc/adjacency_list.html",
32         "http://www.boost.org/libs/graph/doc/history.html",
33         "http://www.boost.org/libs/graph/doc/bundles.html",
34         "http://www.boost.org/libs/graph/doc/using_adjacency_list.html",
35     };
36 
37     E the_edges[] = { E(0, 1), E(0, 2), E(0, 3), E(1, 0), E(1, 3), E(1, 5),
38         E(2, 0), E(2, 5), E(3, 1), E(3, 4), E(4, 1), E(5, 0), E(5, 2) };
39 
40     typedef compressed_sparse_row_graph< directedS, WebPage > WebGraph;
41     WebGraph g(boost::edges_are_sorted, &the_edges[0],
42         &the_edges[0] + sizeof(the_edges) / sizeof(E), 6);
43 
44     // Set the URLs of each vertex
45     int index = 0;
46     BGL_FORALL_VERTICES(v, g, WebGraph)
47     g[v].url = urls[index++];
48 
49     // Output each of the links
50     std::cout << "The web graph:" << std::endl;
51     BGL_FORALL_EDGES(e, g, WebGraph)
52     std::cout << "  " << g[source(e, g)].url << " -> " << g[target(e, g)].url
53               << std::endl;
54 
55     // Output the graph in DOT format
56     dynamic_properties dp;
57     dp.property("label", get(&WebPage::url, g));
58     std::ofstream out("web-graph.dot");
59     write_graphviz_dp(out, g, dp, std::string(), get(vertex_index, g));
60     return 0;
61 }
62