![](/img/trans.png)
[英]Boost Graph Library write graphviz format with simple vertex property (string)
[英]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.