繁体   English   中英

boost图形库 - 顶点颜色和graphviz输出的最小示例

[英]boost graph library - minimal example of vertex colors and graphviz output

作为对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?
}

尝试:

boost::dynamic_properties dp;
dp.property("color", get(&vertex_info::color, g));
dp.property("node_id", get(boost::vertex_index, g));
write_graphviz_dp(outf, g, dp);

而不是你的write_graphviz调用。 有关此示例,请参阅http://www.boost.org/doc/libs/1_47_0/libs/graph/example/graphviz.cpp 请注意,我发布的代码会将颜色写为整数,而不是像Dot要求的颜色名称。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM