c++boostboost-graphgraph-layout

boost Kamada-Kawai spring layout vertices collision


I'm trying to layout a graph using boost Kamada-Kawai-spring-layout algorithm.The problem is that vertices collide with each other in some graphs.I add all edges with weight 1.0

add_edge(a,b,1.0,g);

then I layout the graph like this :

minstd_rand gen;
topology_type topo(gen,0,0,widht,height);
random_graph_layout(g,position,topo);
bool kamada=kamada_kawai_spring_layout(g,position,get(edge_weight,g),topo,side_length(width),kamada_kawai_done());

Some graphs work fine while other produce output like this enter image description here

I think the layout is fine but the length of edges need to be increased but i don't know how


Solution

  • You can used boost::edge_length(e) instead of boost::side_length(s) in order to control the edge length on the graph

    bool kamada=kamada_kawai_spring_layout(g,position,get(edge_weight,g),topo,boost::edge_length(length),kamada_kawai_done());