如何为我的图提供 vertex_index 属性

发布于 2024-12-12 17:03:09 字数 349 浏览 5 评论 0原文

由于我的图使用 setS 作为顶点,我必须为我的图提供 vertex_index 属性映射,或者为 write_graphviz 提供显式的 vertex_id 参数,以便能够使用 write_graphviz。 我的图定义为: typedef adjacency_list图; 其中 NodeData 和 EdgeData 是结构体。 您能否给我一个非常简单的示例,说明如何为我的图提供 vertex_index 属性映射?或者如何向 write_graphviz 提供显式的 vertex_id 参数?

谢谢

Since my graph use setS for vertex, I have to either provide a vertex_index property map for my graph, or give an explicit vertex_id argument to write_graphviz, to be able to use write_graphviz.
My graph is defined as: typedef adjacency_list<setS, setS, undirectedS, NodeData, EdgeData> Graph;
Where NodeData and EdgeData are structures.
Can you please give me a very simple example of how to provide a vertex_index property map for my graph ? or how to give an explicit vertex_id argument to write_graphviz ?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瞎闹 2024-12-19 17:03:10

解决办法就是:
1) 假设顶点描述符定义为 typedef Graph::vertex_descriptor NodeID; 那么您需要定义一个关联属性映射,如下所示:

typedef map<NodeID, size_t> IndexMap;
IndexMap mapIndex;
associative_property_map<IndexMap> propmapIndex(mapIndex);

2) 在代码中,按如下方式索引所有顶点:

int i=0;
BGL_FORALL_VERTICES(v, g, Graph)
{
   put(propmapIndex, v, i++);
}

3) 您现在可以使用 graphvize 绘制/可视化您的图表,如下所示:

ofstream myfile;
myfile.open ("example.txt");
write_graphviz(myfile, g, default_writer(), default_writer(), default_writer(), propmapIndex);
myfile.close();

该图表将在 example.txt 中描述,您可以使用 graphviz 可视化它。

The solution is just to:
1) Say the vertex descriptor is defined as typedef Graph::vertex_descriptor NodeID; then you need to define an associative property map as following:

typedef map<NodeID, size_t> IndexMap;
IndexMap mapIndex;
associative_property_map<IndexMap> propmapIndex(mapIndex);

2) In the code, index all vertices as following:

int i=0;
BGL_FORALL_VERTICES(v, g, Graph)
{
   put(propmapIndex, v, i++);
}

3) You can now use graphvize to drow/visualize your graph as following:

ofstream myfile;
myfile.open ("example.txt");
write_graphviz(myfile, g, default_writer(), default_writer(), default_writer(), propmapIndex);
myfile.close();

The graph will be described in example.txt, you can visualize it using graphviz.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文