目前我有一个项目的以下代码,它代表一些概率树,并为顶点和边类型使用自定义结构:
#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);
但这似乎不符合我的要求,因为它不输出顶点的名称。我应该在这里改变什么?