0

boostlibのbrandes_betweenness_centralityを使用してbetweenessを計算する簡単なプログラムを作成しようとしています。出力(CentralityMap)を取得するのに行き詰まりました。私はドキュメントを読んでいますが、すべてをまとめる方法がわかりません。

これが私の簡単なコードです:

#include <iostream> // std::cout
#include <utility>  // std::pair
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/betweenness_centrality.hpp>

using namespace boost;

int main()
{
  int nVertices = 100;
  srand ( time(NULL) );

  typedef std::pair<int, int> Edge;
  std::vector<Edge> edges;
  for(int i=0; i<nVertices; i++){
    std::cout << i << " :  ";
    for(int j=0; j<nVertices; j++){
      if(rand() % 100 < 9){ /// chances of making a connection is 9 out of 100. may not be accurate
    std::cout << j << "  ";
        edges.push_back(std::make_pair(i,j));
      }
    }
    std::cout << std::endl;
  }

  typedef adjacency_list<vecS, vecS, bidirectionalS, 
    property<vertex_color_t, default_color_type>
  > Graph;
  Graph g(edges.begin(), edges.end(), edges.size());

  brandes_betweenness_centrality(g,?????? );

  return 0;
}

私の理解から、結果が書き込まれる中心性マップを定義する必要があります。読み取り/書き込みプロパティマップに関連していますが、定義方法がわかりません。

最終的には、中間性を出力する必要があります。

4

1 に答える 1

2

不足している部分を埋める最も簡単な方法は次のとおりです。

boost::shared_array_property_map<double, boost::property_map<Graph, vertex_index_t>::const_type>
  centrality_map(num_vertices(g), get(boost::vertex_index, g));

centrality_map次に、中心性マップとしてに渡しbrandes_betweenness_centralityます。

于 2012-02-09T05:48:04.370 に答える