How to print a boost graph in graphviz with one of the properties displayed?(如何在显示属性之一的 graphviz 中打印增强图?)
问题描述
我在使用属性映射时看到了这样的例子,但在使用结构来处理顶点和边时却没有看到(我认为这被称为包").
I see examples of this when using property maps, but not when using structs to handle the vertices and edges (I think this is called 'bundles').
我在邻接列表图中定义了顶点和边.
I have vertices and edges defined as such, in an adjacency list graph.
struct Vertex
{
string name;
int some_int;
};
struct Edge
{
double weight;
};
图的构造如下:
typedef boost::adjacency_list<boost::listS, boost::vecS, boost::directedS, Vertex, Edge> boost_graph;
我想以 Graphviz 格式打印这些对象的图形,以便我可以将其作为图像查看.但是,我不仅想要节点和边.我还希望顶点上的属性 name 和边缘上的 weight 出现在图像中.我该怎么做?
I want to print my graph of these objects in Graphviz format, so I can view it as an image. However, I don't only want the nodes and edges. I also want the attribute name on vertices and weight on edges to appear in the image. How can I do this?
推荐答案
我第一次提供了错误信息.这是正确答案.
I gave bad info the first time. Here is the correct answer.
#include <boost/graph/graphviz.hpp>
using namespace boost;
// Graph type
typedef adjacency_list<vecS, vecS, directedS, VertexProperties, EdgeProperty> Graph;
Graph g;
std::vector<std::string> NameVec; // for dot file names
// write the dot file
std::ofstream dotfile (strDotFile.c_str ());
write_graphviz (dotfile, g, make_label_writer(&NameVec[0]));
这篇关于如何在显示属性之一的 graphviz 中打印增强图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在显示属性之一的 graphviz 中打印增强图?
基础教程推荐
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- CString 到 char* 2021-01-01
