我已经使用read_graphviz()阅读了一个图,并且知道该图包含子图。但是,我找不到Boost文档在哪里涵盖如何访问所述子图的地方。我只能找到create_subgraph(),它显然无法访问现有的子图。我想念什么?
提前致谢
该文件列出了这些成员函数,援助在子穿越/导航:
subgraph& root()
返回子图树的根图。
bool is_root() const
如果图是子图树的根,则返回true,否则返回false。
subgraph& parent()
返回父图。
std::pair<children_iterator, children_iterator> children() const
返回用于访问子图子的迭代器对。
以我对Graphviz支持的子图更完整的演示(此处为Boost.Graph和Graphviz嵌套子图)为基础的示例,这是一个简单的演示:
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/subgraph.hpp>
#include <iostream>
template <typename SubGraph> SubGraph create_data()
{
enum { A,B,C,D,E,F,N }; // main edges
SubGraph main(N);
SubGraph& sub1 = main.create_subgraph();
SubGraph& sub2 = main.create_subgraph();
auto A1 = add_vertex(A, sub1);
auto B1 = add_vertex(B, sub1);
auto E2 = add_vertex(E, sub2);
auto C2 = add_vertex(C, sub2);
auto F2 = add_vertex(F, sub2);
add_edge(A1, B1, sub1);
add_edge(E2, F2, sub2);
add_edge(C2, F2, sub2);
add_edge(E, B, main);
add_edge(B, C, main);
add_edge(B, D, main);
add_edge(F, D, main);
// setting some graph viz attributes
get_property(main, boost::graph_name) = "G0";
get_property(sub1, boost::graph_name) = "clusterG1";
get_property(sub2, boost::graph_name) = "clusterG2";
return main;
}
using Graph = boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS,
boost::no_property,
boost::property<boost::edge_index_t, int>,
boost::property<boost::graph_name_t, std::string>
>;
template <typename G>
void list_nested(boost::subgraph<G>& g, std::string const& prefix = "") {
std::cout << prefix
<< " * " << get_property(g, boost::graph_name)
<< " (" << num_vertices(g) << "+" << num_edges(g) << " v+e)"
<< "\n";
for (auto& child : make_iterator_range(g.children())) {
list_nested(child, " -");
}
}
int main() {
auto g = create_data<boost::subgraph<Graph> >();
list_nested(g);
}
版画
* G0 (6+7 v+e)
- * clusterG1 (2+1 v+e)
- * clusterG2 (3+2 v+e)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句