在boost :: graph中,如何给定相邻顶点给定有向邻接图,顶点和外边缘索引?

时间:2012-06-20 21:51:55

标签: boost boost-graph

我有一个adjacency_list图,定义如下:

struct VertexProperties{
    std::string name;
    ...
};
typedef boost::adjacency_list<boost::vecS,
                              boost::vecS,
                              boost::directedS,
                              VertexProperties> GraphType;
typedef GraphType::vertex_descriptor VertexType;

给定图形,顶点和外边缘索引,如何获得相邻顶点?

1 个答案:

答案 0 :(得分:0)

解决:

typedef 
boost::graph_traits<GraphType>::out_edge_iterator
out_edge_iterator;

typedef 
std::pair<out_edge_iterator, out_edge_iterator>
out_edge_iterator_range;

out_edge_iterator_range range = boost::out_edges(current_vertex, graph);
if (out_index > range.second - range.first){
    // out_index is invalid
}
out_edge_iterator iter = range.first + row;

VertexType out_vertex = iter->m_target;