5

Boost Graph Library について理解を深めようとしているところですが、いくつか質問があります。BGL グラフのラッパー クラスであるコードを書いています。アイデアは、必要に応じてグラフを操作し、ラッパー メソッドを呼び出してグラフを GEXF (XML) 形式で出力できるということです。

私のコードは次のようなものです:

struct Vertex {
   std::string label;
   ...
};

struct Edge {
   std::string label;
   double weight;
   ...
};

typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, Vertex, Edge> GraphType;

template <typename Graph>
class GEXF
{
   private:
      Graph graph;
   ...
};

template <typename Graph>
void GEXF<Graph>::buildXML()
{
   ...

   // output the edges
   property_map<adjacency_list<>, edge_index_t>::type edge_id = get(edge_index, graph);
   GraphType::edge_iterator e, e_end;
   for(tie(e, e_end) = edges(graph); e != e_end; ++e)
   {
      xmlpp::Element *edge = ePtr->add_child("edge");

      // next line gives an error, property not found
      edge->set_attribute("id", tostring<size_t>(get(edge_id, *e)));
      edge->set_attribute("source", tostring<size_t>(source(*e, graph)));
      edge->set_attribute("target", tostring<size_t>(target(*e, graph)));
   }
}

...
// instantiate in main():
GEXF<GraphType> gexf;

ここに私の質問があります:

  1. バンドルされたプロパティを使用すると、vertex_index にはアクセスできますが、edge_index にはアクセスできません。エッジ インデックスにアクセスするにはどうすればよいですか?

  2. 上記のコードでは、GEXF クラスをジェネリックにしたかったのですが、宣言しようとしたときに問題が発生しましたGraph::edge_iterator e, e_end;。上記のコードは機能しますが、具象型を使用しています。edge_iterator を一般的に宣言するにはどうすればよいですか?

4

1 に答える 1

3

boost::adjacency_list<...>1 つを維持すると複雑さに影響するため、オブジェクトにはデフォルトで edge_index はありません。自分で作成する必要がありますが、目的の機能を提供するように注意する必要があります。

以前 :

Boost Subgraph と Bundled プロパティ

すべてのエッジの edge_index ゼロ?

インデックスを使用してグラフ エッジをブーストする

于 2011-10-21T05:07:33.563 に答える