问题描述
我有如下定义的邻接表。在这一点上我需要访问顶点描述为int类型。我怎样才能做到这一点 tvertex源= ...; INT source_as_int = ??? ???源
我记得我碰到同样的问题之前,解决它,但不记得如何使用它作为参考的BGL文件是没用的,他们应该尝试采取一看和学习的Javadocs
另一种可能是使用的一个可能的成员函数 vertex_descriptor的
键入或其他一些全球BGL功能用于此目的......没有人知道在哪里找这一点,他们似乎使全局函数或成员函数之间随机选择,共有直观的设计,如果你问我失败。
的typedef adjacency_list_traits<套,,bidirectionalS> ttraits;的typedef的adjacency_list<套,,bidirectionalS,
//顶点属性
财产< vertex_color_t,default_color_type>中
//边缘性质
财产< edge_capacity_t,INT,
财产< edge_residual_capacity_t,INT,
财产< edge_reverse_t,ttraits :: edge_descriptor的> > >中no_property,血管内皮细胞> tbgl_adjlist_bidir;typedef的graph_traits< tbgl_adjlist_bidir> :: vertex_descriptor的tvertex;
typedef的graph_traits< tbgl_adjlist_bidir> :: edge_descriptor的tedge;
typedef的property_map< tbgl_adjlist_bidir,edge_capacity_t> ::类型tedge_capacity_map;
typedef的property_map< tbgl_adjlist_bidir,edge_reverse_t> ::类型treverse_edge_map;
typedef的property_map< tbgl_adjlist_bidir,vertex_color_t> ::类型tvertex_color_map;
typedef的graph_traits< tbgl_adjlist_bidir> :: out_edge_iterator tout_edge_iterator;
typedef的graph_traits< tbgl_adjlist_bidir> :: in_edge_iterator tin_edge_iterator;
好吧,我想通了。添加顶点属性 vertex_index_t
解决问题。那么我可以访问的顶点INT指数是这样的:
的typedef adjacency_list_traits<设置,血管内皮细胞,bidirectionalS> ttraits;的typedef的adjacency_list<设置,血管内皮细胞,bidirectionalS,
//顶点属性
财产< vertex_index_t,INT,
财产< vertex_color_t,default_color_type> >中
//边缘性质
财产< edge_capacity_t,INT,
财产< edge_residual_capacity_t,INT,
财产< edge_reverse_t,ttraits :: edge_descriptor的> > >中no_property,血管内皮细胞> tbgl_adjlist_bidir;typedef的graph_traits< tbgl_adjlist_bidir> :: vertex_descriptor的tvertex;
typedef的graph_traits< tbgl_adjlist_bidir> :: edge_descriptor的tedge;
typedef的property_map< tbgl_adjlist_bidir,edge_capacity_t> ::类型tedge_capacity_map;
typedef的property_map< tbgl_adjlist_bidir,edge_reverse_t> ::类型treverse_edge_map;
typedef的property_map< tbgl_adjlist_bidir,vertex_color_t> ::类型tvertex_color_map;
typedef的property_map< tbgl_adjlist_bidir,vertex_index_t> ::类型tvertex_index_map;
typedef的graph_traits< tbgl_adjlist_bidir> :: vertex_iterator tvertex_iterator;
typedef的graph_traits< tbgl_adjlist_bidir> :: edge_iterator tedge_iterator;
typedef的graph_traits< tbgl_adjlist_bidir> :: out_edge_iterator tout_edge_iterator;
typedef的graph_traits< tbgl_adjlist_bidir> :: in_edge_iterator tin_edge_iterator;
然后我用这样的:
tbgl_adjlist_bidir bgl_adjlist_bidir;
// ...
tvertex_index_map指数=得到(的vertex_index,bgl_adjlist_bidir);
// ...
tvertex来源;
// ...
INT source_as_int =指数[来源]
I have an adjacency list defined as shown below. At this point I need to access vertex_descriptor as an int type. How can I do that tvertex source = ...; int source_as_int = ???source???
I remember bumping into this same question before and solved it but don't remember how and the BGL documentation is useless using it as reference, they should try to take a look at and learn from Javadocs.
Another possibility is to use a possible member function of the vertex_descriptor
type or otherwise some of the global BGL functions for this purpose ... one never knows where to look for this and they seem to randomly choose between making global functions or member functions, a total fail of an intuitive design if you ask me.
typedef adjacency_list_traits<setS, setS, bidirectionalS> ttraits;
typedef adjacency_list<setS, setS, bidirectionalS,
// vertex properties
property<vertex_color_t, default_color_type>,
// edge properties
property<edge_capacity_t, int,
property<edge_residual_capacity_t, int,
property<edge_reverse_t, ttraits::edge_descriptor> > >, no_property, vecS> tbgl_adjlist_bidir;
typedef graph_traits<tbgl_adjlist_bidir>::vertex_descriptor tvertex;
typedef graph_traits<tbgl_adjlist_bidir>::edge_descriptor tedge;
typedef property_map<tbgl_adjlist_bidir, edge_capacity_t>::type tedge_capacity_map;
typedef property_map<tbgl_adjlist_bidir, edge_reverse_t>::type treverse_edge_map;
typedef property_map<tbgl_adjlist_bidir, vertex_color_t>::type tvertex_color_map;
typedef graph_traits<tbgl_adjlist_bidir>::out_edge_iterator tout_edge_iterator;
typedef graph_traits<tbgl_adjlist_bidir>::in_edge_iterator tin_edge_iterator;
OK I figured it out. Adding the vertex property vertex_index_t
solves the problem. I can then access the int index of the vertex like this:
typedef adjacency_list_traits<setS, vecS, bidirectionalS> ttraits;
typedef adjacency_list<setS, vecS, bidirectionalS,
// vertex properties
property<vertex_index_t, int,
property<vertex_color_t, default_color_type> >,
// edge properties
property<edge_capacity_t, int,
property<edge_residual_capacity_t, int,
property<edge_reverse_t, ttraits::edge_descriptor> > >, no_property, vecS> tbgl_adjlist_bidir;
typedef graph_traits<tbgl_adjlist_bidir>::vertex_descriptor tvertex;
typedef graph_traits<tbgl_adjlist_bidir>::edge_descriptor tedge;
typedef property_map<tbgl_adjlist_bidir, edge_capacity_t>::type tedge_capacity_map;
typedef property_map<tbgl_adjlist_bidir, edge_reverse_t>::type treverse_edge_map;
typedef property_map<tbgl_adjlist_bidir, vertex_color_t>::type tvertex_color_map;
typedef property_map<tbgl_adjlist_bidir, vertex_index_t>::type tvertex_index_map;
typedef graph_traits<tbgl_adjlist_bidir>::vertex_iterator tvertex_iterator;
typedef graph_traits<tbgl_adjlist_bidir>::edge_iterator tedge_iterator;
typedef graph_traits<tbgl_adjlist_bidir>::out_edge_iterator tout_edge_iterator;
typedef graph_traits<tbgl_adjlist_bidir>::in_edge_iterator tin_edge_iterator;
then I use it like this:
tbgl_adjlist_bidir bgl_adjlist_bidir;
// ...
tvertex_index_map indices = get(vertex_index, bgl_adjlist_bidir);
// ...
tvertex source;
// ...
int source_as_int = indices[source];
这篇关于如何访问BGL的顶点描述为int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!