boost::transitive_closure用例详解
在C++语言的Boost库中,有一个非常实用的算法boost::transitive_closure,它可以生成图的传递闭包。传递闭包是指在一个有向图(或无向图)中,若存在从节点A到节点B的路径,则在传递闭包中描绘为从节点A到节点B的有向边,此时该边被称为“传递性边”。因此,传递闭包可以用来表示图中所有节点之间的可达性关系。
下面是一个简单的示例程序,演示了boost::transitive_closure算法的用法:
#include <iostream>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/transitive_closure.hpp>
using namespace boost;
int main()
{
typedef adjacency_list<vecS, vecS, directedS> Graph;
Graph g(4);
add_edge(0, 1, g);
add_edge(1, 2, g);
add_edge(2, 3, g);
// Compute the transitive closure of g
Graph tc;
transitive_closure(g, tc);
// Print the edges of tc
std::cout << "Edges in the transitive closure:" <<