如何为我的图的vertex_index属性 [英] how provide a vertex_index property for my graph

查看:117
本文介绍了如何为我的图的vertex_index属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我使用的图形设置顶点,我必须要么提供的vertex_index属性映射图我,或者给一个明确的vertex_id参数write_graphviz,才能够使用write_graphviz。
我的图被定义为:类型定义的adjacency_list<套,,undirectedS,NODEDATA,EdgeData>图;
凡NODEDATA和EdgeData的结构。
能否请您给我如何为我的图的vertex_index属性图一个很简单的例子吗?或者如何给一个明确的vertex_id参数write_graphviz?

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 ?

感谢

推荐答案

解决方案仅仅是:
1)说出顶点描述符定义为的typedef图:: vertex_descriptor的节点ID; ,那么你需要定义关联属性映射如下:

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)在code,指数所有顶点如下:

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

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

3)您现在可以使用graphvize以卓尔/可视化你的图形如下:

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();

该图将example.txt文件中的描述,可以使用graphviz的可视化它。

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

这篇关于如何为我的图的vertex_index属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆