1

グラフをストリームにダンプするのに苦労しています。ここで、グラフは の構成されたバージョンですboost::subgraph

プロパティライターを提供しようとしましたが、メソッドが必要なようで、基本的に失敗しますboost::get(PropertyWriter, VertexDescriptor)。グラフが期待どおりに機能しないsubgraph場合と同じ方法論を使用します。

hereにあるように、 boost::dynamic_properties(以下のコードを参照)を使用する必要がありますが、グラフが書き込み可能でない場合は失敗します(ドキュメントでは、グラフが構成された参照として使用されることが示されています)。

これは私が仕事に就けない簡単な例です:

#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graphviz.hpp>
#include <boost/graph/subgraph.hpp>

struct VertexProperties
{
  std::string name;
};

int main()
{
  typedef boost::subgraph<
    boost::adjacency_list<
      boost::vecS, boost::vecS,
      boost::directedS,
      boost::property<boost::vertex_index_t, std::size_t, VertexProperties>,
      boost::property<boost::edge_index_t, std::size_t> > > Graph;

  Graph const g;

  boost::dynamic_properties dp;
  dp.property("name", boost::get(&VertexProperties::name, g));
  dp.property("node_id", boost::get(boost::vertex_index, g));
  boost::write_graphviz_dp(std::cout, g, dp);
}

どんなヒントでも大歓迎です!どうもありがとう、


編集

私の場合、「失敗」が何を意味するかについて言及するのを忘れていました。コンパイルしようとしたときのエラーは次のとおりです。

エラー: 'std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(const std::basic_string の 'this' 引数として 'const std::basic_string' を渡しています<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits, _Alloc = std::allocator, std::basic_string<_CharT, _Traits, _Alloc> = std::basic_string]' 修飾子を破棄 [ -fpermissive]

4

1 に答える 1

1

示唆されたように、これは Boost.Graph のバグであると報告しました (チケットを参照)。

m_graph回避策として、パブリック スコープにあるメンバーにアクセスすることで、サブグラフの代わりに基になるグラフを使用できるようです。

プロパティライターを使用して、問題を回避する方法を次に示します。

struct VertexProperties
{
  std::string name;
};

template <typename Graph> struct prop_writer
{
  prop_writer(Graph const& g): g_(g) {}

  template <typename Vertex> void operator()(std::ostream& out, Vertex v) const
  {
    out << g_[v].name;
  }

  Graph const& g_;
}

typedef boost::subgraph<
  boost::adjacency_list<
    boost::vecS, boost::vecS,
    boost::directedS,
    boost::property<boost::vertex_index_t, std::size_t, VertexProperties>,
    boost::property<boost::edge_index_t, std::size_t> > > Graph;

Graph const g;

// Note the use of g.m_graph here.
boost::write_graphviz(std::cout, g.m_graph, prop_writer<Graph>(g));
于 2012-03-28T12:12:20.273 に答える