Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/graph/example/transitive_closure.cpp @ 12

Last change on this file since 12 was 12, checked in by landauf, 17 years ago

added boost

File size: 1.5 KB
Line 
1// Copyright (c) Jeremy Siek 2001
2//
3// Distributed under the Boost Software License, Version 1.0. (See
4// accompanying file LICENSE_1_0.txt or copy at
5// http://www.boost.org/LICENSE_1_0.txt)
6
7// NOTE: this final is generated by libs/graph/doc/transitive_closure.w
8
9#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
10#error The transitive closure algorithm uses partial specialization.
11#endif
12
13#include <boost/graph/transitive_closure.hpp>
14#include <boost/graph/graphviz.hpp>
15#include <boost/graph/graph_utility.hpp>
16
17int
18main(int, char *[])
19{
20  using namespace boost;
21  typedef property < vertex_name_t, char >Name;
22  typedef property < vertex_index_t, std::size_t, Name > Index;
23  typedef adjacency_list < listS, listS, directedS, Index > graph_t;
24  typedef graph_traits < graph_t >::vertex_descriptor vertex_t;
25  graph_t G;
26  std::vector < vertex_t > verts(4);
27  for (int i = 0; i < 4; ++i)
28    verts[i] = add_vertex(Index(i, Name('a' + i)), G);
29  add_edge(verts[1], verts[2], G);
30  add_edge(verts[1], verts[3], G);
31  add_edge(verts[2], verts[1], G);
32  add_edge(verts[3], verts[2], G);
33  add_edge(verts[3], verts[0], G);
34
35  std::cout << "Graph G:" << std::endl;
36  print_graph(G, get(vertex_name, G));
37
38  adjacency_list <> TC;
39  transitive_closure(G, TC);
40
41  std::cout << std::endl << "Graph G+:" << std::endl;
42  char name[] = "abcd";
43  print_graph(TC, name);
44  std::cout << std::endl;
45
46  std::ofstream out("tc-out.dot");
47  write_graphviz(out, TC, make_label_writer(name));
48
49  return 0;
50}
Note: See TracBrowser for help on using the repository browser.