作为 boost 图形库的新手,我发现通常很难梳理出哪些示例与特定示例相关联以及哪些部分是通用的。
作为一个练习,我正在尝试制作一个简单的图形,为顶点分配一个颜色属性,并将结果输出到 graphviz,以便颜色显示为被渲染的颜色属性。任何帮助,将不胜感激!这是我到目前为止所拥有的(更具体的使用问题在这里的评论中):
#include "fstream"
#include "boost/graph/graphviz.hpp"
#include "boost/graph/adjacency_list.hpp"
struct vertex_info {
int color;
};
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, vertex_info> Graph;
typedef std::pair<int, int> Edge;
int main(void) {
Graph g;
add_edge(0, 1, g);
add_edge(1, 2, g);
// replace this with some traversing and assigning of colors to the 3 vertices ...
// should I use bundled properties for this?
// it's unclear how I would get write_graphviz to recognize a bundled property as the color attribute
g[0].color = 1;
std::ofstream outf("min.gv");
write_graphviz(outf, g); // how can I make write_graphviz output the vertex colors?
}