2
0
mirror of https://github.com/boostorg/graph.git synced 2026-01-19 04:12:11 +00:00
Files
graph/example/transitive_closure.cpp
2025-07-20 17:51:15 +02:00

50 lines
1.5 KiB
C++

// Copyright (c) Jeremy Siek 2001
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// NOTE: this final is generated by libs/graph/doc/transitive_closure.w
#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
#error The transitive closure algorithm uses partial specialization.
#endif
#include <boost/graph/transitive_closure.hpp>
#include <boost/graph/graphviz.hpp>
#include <boost/graph/graph_utility.hpp>
int main(int, char*[])
{
using namespace boost;
using Name = property< vertex_name_t, char >;
using Index = property< vertex_index_t, std::size_t, Name >;
using graph_t = adjacency_list< listS, listS, directedS, Index >;
using vertex_t = graph_traits< graph_t >::vertex_descriptor;
graph_t G;
std::vector< vertex_t > verts(4);
for (int i = 0; i < 4; ++i)
verts[i] = add_vertex(Index(i, Name('a' + i)), G);
add_edge(verts[1], verts[2], G);
add_edge(verts[1], verts[3], G);
add_edge(verts[2], verts[1], G);
add_edge(verts[3], verts[2], G);
add_edge(verts[3], verts[0], G);
std::cout << "Graph G:" << std::endl;
print_graph(G, get(vertex_name, G));
adjacency_list<> TC;
transitive_closure(G, TC);
std::cout << std::endl << "Graph G+:" << std::endl;
char name[] = "abcd";
print_graph(TC, name);
std::cout << std::endl;
std::ofstream out("tc-out.dot");
write_graphviz(out, TC, make_label_writer(name));
return 0;
}