I have a an adjacency_list graph with randomly connected nodes using Erdos-Renyi edge generation.
The graph uses bundled properties by defining data structures both for the vertices (Graph_Node
) and edges (Graph_Edge
), which is used to assign the position of the nodes and the weights of the edges.
I'm trying to use force-directed graph drawing to assign good positions for the nodes, using kamada_kawai_spring_layout
.
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/erdos_renyi_generator.hpp>
#include <boost/random/linear_congruential.hpp>
#include <boost/graph/kamada_kawai_spring_layout.hpp>
using namespace boost;
struct Graph_Node
{
typedef convex_topology<2>::point tPoint;
tPoint Position;
};
struct Graph_Edge
{
unsigned int ID;
double weight = 100.;
};
typedef adjacency_list<vecS, vecS, undirectedS, Graph_Node, Graph_Edge> Graph;
static random::minstd_rand rng;
typedef erdos_renyi_iterator<random::minstd_rand, Graph> ERGen;
static const int ER_INIT_NODES = 50;
static const double p = 0.05;
static Graph g(ERGen(rng, ER_INIT_NODES, p), ERGen(), ER_INIT_NODES);
int main()
{
ball_topology<2> T(1.);
detail::graph::edge_or_side<1, double> scaling(1.);
kamada_kawai_spring_layout(g, get(&Graph_Node::Position, g), get(&Graph_Edge::weight, g), T, scaling);
Graph::vertex_iterator v, v_end;
for (std::tie(v, v_end) = vertices(g); v != v_end; ++v)
std::cout << g[*v].Position[0] << ", " << g[*v].Position[1] << std::endl;
}
Graph_Node::Position
is intended to be assigned using kamada_kawai_spring_layout
, but the Position
of all the vertices in g
are 0,0
after assignment. Why?