Boost.Graph vertexからvertex_descriptorを取得する
vertexのインデックスからvertex_descriptorを取得するには、vertex()関数を使用します。
第1引数はvertexのインデックス、第2引数はグラフオブジェクトへの参照です。
#include <vector> #include <utility> #include <boost/graph/adjacency_list.hpp> typedef boost::adjacency_list<> Graph; typedef std::pair<int, int> Edge; enum { A, B, C, D, E, N }; int main() { const std::vector<Edge> edges = { {A, B}, {A, C}, {A, D}, {B, E}, {C, E}, {D, E} }; const Graph g(edges.begin(), edges.end(), N); // vertex_descriptorを取得する boost::graph_traits<Graph>::vertex_descriptor v = vertex(A, g); }
Boost.Graphが定義するコンセプトにvertex()が含まれるものはなくて、adjacency_list、adjacency_matrix、compressed_sparse_row_graphにはあったので、ドキュメント上はこれらのクラス特有の機能になると思われます。
VertexListの型をlistSにしても通ったので、 id:amedama41 さんがおっしゃるところのIndexedGraphでなくてもなぜか使用できるようです(参照:「boost::adjacency_listのVertexListテンプレート引数とvertex_indexの関係 - あめ工場」)。