![](/img/trans.png)
[英]Boost::Graph: how to import graphviz with custom Vertex class
[英]Boost graphviz custom vertex labels
目前,我有一個代表一些概率樹的項目的代碼,並為頂點和邊緣類型使用自定義結構:
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graphviz.hpp>
struct Vertex{
std::string name;
size_t times_visited;
float value;
bool terminal_node;
bool root_node;
};
struct Edge{
float probability;
};
//Some typedefs for simplicity
typedef boost::adjacency_list<boost::listS, boost::vecS, boost::directedS, Vertex, Edge> directed_graph_t;
typedef boost::graph_traits<directed_graph_t>::vertex_descriptor vertex_t;
typedef boost::graph_traits<directed_graph_t>::edge_descriptor edge_t;
我目前使用boost graphviz但沒有標簽的一些簡單樹的簡單視覺表示。 我希望頂點之間的連接用Edge結構中找到的概率標記,頂點用Vertex結構中找到的關聯名稱標記。 我第一次嘗試這樣做是為了使用這段代碼:
std::ofstream outf("test.dot");
boost::dynamic_properties dp;
dp.property("name", get(&Vertex::name, test));
dp.property("node_id", get(boost::vertex_index, test));
write_graphviz_dp(outf, test, dp);
但這似乎沒有做我想要的,因為它不輸出頂點的名稱。 我應該在這里改變什么?
看起來這只是因為我沒有正確理解graphviz。 以下代碼按預期工作:
std::ofstream outf("test.dot");
boost::dynamic_properties dp;
dp.property("label", boost::get(&Vertex::name, test));
dp.property("node_id", boost::get(boost::vertex_index, test));
dp.property("label", boost::get(&Edge::probability, test));
write_graphviz_dp(outf, test, dp);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.