简体   繁体   English

使用索引增强图形边缘

[英]Boost Graph edges with indexes

I am trying to define a graph with undirected edges from a set of pair(int,int) edges (where each int represents a vertex index). 我正在尝试从一对pair(int,int)边(其中每个int代表一个顶点索引)中定义具有无向边的图。 Each such edge has an index of its own. 每个这样的边都有自己的索引。

The catch is that I want that the internal vertex index of the graph will be consistent with the original vertex indexes. 问题是我希望图形的内部顶点索引与原始顶点索引一致。 I also like to be able to extract the original edge index from an edge descriptor. 我还希望能够从边缘描述符中提取原始边缘索引。

From http://www.boost.org/doc/libs/1_47_0/libs/graph/doc/using_property_maps.html ( Exterior Properties section) I understand that I should use the following graph type: http://www.boost.org/doc/libs/1_47_0/libs/graph/doc/using_property_maps.html (“ 外部属性”部分)中,我了解到我应该使用以下图形类型:

typedef adjacency_list<vecS, vecS, udirectedS, 
no_property, property<edge_index_t, std::size_t> > Graph;

Unfortunately there's no explanation on how to use edge_index_t property. 不幸的是,没有关于如何使用edge_index_t属性的解释。

It's clear that I could just use a map(pair(int,int),int) but I'm looking for a more elegant boost oriented solution. 显然,我可以只使用map(pair(int,int),int),但是我正在寻找一种更优雅的面向Boost的解决方案。

Thank you, Kiril 谢谢基里尔

Since you use vectors to define collection of vertices there is one-to one correspondence between vertex indices and vertex descriptors. 由于使用向量来定义顶点集合,因此顶点索引和顶点描述符之间存在一一对应的关系。 You just need to define you graph object as follows: 您只需要按以下方式定义图形对象:

Graph g(N);

Where N is number of vertices. 其中N是顶点数。 This allocates N vertices, each vertex descriptor is a number from 0 to N-1. 这分配了N个顶点,每个顶点描述符是一个从0到N-1的数字。

To get edge index from the edge descriptor you can use get function: get(edge_index, g, edge_descriptor); 要从边缘描述符获取边缘索引,可以使用get函数: get(edge_index, g, edge_descriptor); . The edge descriptor you can get from iterators returned by adjacent_vertices(v, g) function. 您可以从neighbor_vertices adjacent_vertices(v, g)函数返回的迭代器中获取边缘描述符。

Hope it what you've meant. 希望它是您的意思。

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

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