0

I have a vector of vertex with id,x & y coordinates, I want to generate a power law graph for my vertices. The Boost Library graph provide power law plod_iterator() but how can I generate that with my vertices. anyone can help?

manlio
  • 18,345
  • 14
  • 76
  • 126
zaza
  • 365
  • 2
  • 7

1 Answers1

3

The Boost documentation states that these are generators.

"This class template implements a generator for scale-free graphs using the Power Law Out Degree (PLOD) algorithm" (http://www.boost.org/doc/libs/1_55_0/libs/graph/doc/plod_generator.html)

It is a little confusing that it says iterator.

I would instead create a vector of structs with your data then generate a power-law graph with the same number of nodes.

Modified from boost documentation:

#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;
}

Here this will set of a scale free graph with 100 nodes using the power-law exponent of 2.5.

Then when you want to access a node's data, just access its index and do a look up in your struct vector. You can get the index like this:

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

This may not be the absolute best way, but it has enabled me to get my work done.

pbible
  • 1,259
  • 1
  • 18
  • 34