Boost graphviz 自定义顶点标签
目前,我有一个项目的以下代码,该项目表示一些概率树,并使用顶点和边类型的自定义结构:
#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);
但这似乎没有达到我想要的效果,因为它不输出顶点的名称。我应该在这里改变什么?
Currently I have the following code for a project that represents some probability trees and uses custom structs for the vertex and edge types:
#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;
I currently have a simple visual representation of some simple trees using boost graphviz but with no labels. I would like to have the connections between vertices being labeled with the probability found in the Edge struct and the vertices labeled with the associate name found in the Vertex struct. My first attempt at doing this was to use this code:
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);
But this seems to not do what I want as it doesn't output the name of the vertex. What should I be changing here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来这只是因为我没有正确理解 graphviz。以下代码按预期工作:
Looks like this was just because I didn't understand graphviz properly. The following code worked as expected: