c_cpp 使用带有listS的Boost Graph连接组件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 使用带有listS的Boost Graph连接组件相关的知识,希望对你有一定的参考价值。
typedef boost::adjacency_list<boost::listS,
boost::listS,
boost::undirectedS,
boost::property<boost::vertex_index_t, size_t, VertexProperty>> Graph;
typedef boost::graph_traits<Graph>::vertex_descriptor Vertex;
typedef boost::graph_traits<Graph>::edge_descriptor Edge;
typedef boost::graph_traits<Graph>::vertex_iterator VertexIter;
typedef boost::graph_traits<Graph>::edge_iterator EdgeIter;
typedef boost::shared_ptr<std::vector<unsigned long>> VertexComponentMap;
typedef boost::filtered_graph<Graph,
boost::function<bool(Graph::edge_descriptor)>,
boost::function<bool(Graph::vertex_descriptor)>> ComponentGraph;
std::vector<ComponentGraph> connectedComponents(Graph &g) {
boost::property_map<Graph, boost::vertex_index_t>::type index_map = boost::get(boost::vertex_index, g);
size_t count = 0;
for (auto v : boost::make_iterator_range(boost::vertices(g)))
boost::put(index_map, v, count++);
size_t num = boost::connected_components(g, index_map);
std::vector<ComponentGraph> componentGraphs;
for (size_t i = 0; i < num; ++i) {
componentGraphs.emplace_back(g,
[i, &g, index_map](Graph::edge_descriptor e) {
return boost::get(index_map, boost::source(e, g)) == i ||
boost::get(index_map, boost::target(e, g)) == i;
},
[i, index_map](Graph::vertex_descriptor v) {
return boost::get(index_map, v) == i;
});
}
return componentGraphs;
}
以上是关于c_cpp 使用带有listS的Boost Graph连接组件的主要内容,如果未能解决你的问题,请参考以下文章
c_cpp 使用boost列出目录中的所有内容
c_cpp 使用boost库的cpp程序的参数解析器。
c_cpp boost :: any-like class
c_cpp boost_signals2_plus_fusion.cc
c_cpp 为Kinect SDK v2正文数据序列化Boost.Serialization(XML)的定义
如何使用 boost :: 适配器链的 boost 范围获取 std::list