나는 정점 벡터에 대해 ID가 x &y 인 꼭지점 벡터를 가지고 있으며, 정점에 대한 거듭 제곱 법칙 그래프를 생성하려고합니다. Boost Library 그래프는 power law plod_iterator()을 제공하지만 어떻게하면이를 정점으로 생성 할 수 있습니까? 누구든지 도울 수 있니?Boost Graph Library C++/Power Law
0
A
답변
3
Boost 설명서에 이러한 생성기가 나와 있습니다.
이 반복자는 말한다 약간의 혼란 (http://www.boost.org/doc/libs/1_55_0/libs/graph/doc/plod_generator.html)
"이 클래스 템플릿은 전원 법 아웃 학위 (터벅 터벅 걷다) 알고리즘을 사용하여 스케일이없는 그래프의 발전기를 구현합니다."
대신 데이터로 구조체의 벡터를 작성한 다음 같은 수의 노드로 전력 법 그래프를 생성합니다.
부스트 문서에서 수정이 100 개 노드 2.5의 지수 법칙의 지수를 사용하여 규모 무료 그래프의 설정합니다 여기#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/plod_generator.hpp>
#include <boost/random/linear_congruential.hpp>
struct VertData{
size_t id;
size_t x;
size_t y;
};
typedef boost::adjacency_list<> Graph;
typedef boost::plod_iterator<boost::minstd_rand, Graph> SFGen;
int main()
{
vector<VertData> vertData;
//... Initialize with data ...
boost::minstd_rand gen;
// Create graph with 100 nodes
Graph g(SFGen(gen, 100, 2.5, 1000), SFGen(), 100);
typedef property_map<Graph, vertex_index_t >::type VertexIndexMap;
VertexIndexMap iMap = get(vertex_index,g);
// ... get some vertex v
size_t vertexIndex = iMap[v];
//...
vertexData.at(vertexIndex).x = 4;//or what ever
return 0;
}
.
노드의 데이터에 액세스하려면 인덱스에 액세스하고 구조체 벡터를 조회하면됩니다. 이 같은 인덱스를 얻을 수 있습니다 :
typedef property_map<Graph, vertex_index_t >::type VertexIndexMap;
VertexIndexMap iMap = get(vertex_index,g);
size_t vertexIndex = iMap[v];
...
vertexData.at(vertexIndex).x = 4;//or what ever
이되지 않을 수 있습니다 절대 가장 좋은 방법,하지만 내 일을 완수 할 수있었습니다.