1

我有一个 adjacency_list 图定义如下:

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

给定一个图、顶点和出边索引,我怎样才能得到相邻的顶点?

4

1 回答 1

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;

于 2012-06-21T14:01:47.020 回答