问题描述
目前我有以下的code为重presents一定的概率的树木和使用自定义结构的顶点和边类型项目:
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;
我现在有使用升压graphviz的一些简单的树木,但没有标签一个简单的视觉重新presentation。我想有被标记中的边缘结构中发现的概率顶点和标记的顶点结构中的副名称顶点之间的连接。我在做这第一次尝试使用这个code:
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?
推荐答案
看起来这只是因为我不graphviz的正确理解。下面code和预期一样:
Looks like this was just because I didn't understand graphviz properly. The following code worked as expected:
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);
这篇关于提升的graphviz自定义顶点标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!