To achieve a planar embedding with fixed positions for some vertices,
- I am currently using the force-directed layout method. Is this approach feasible?
- I am currently facing an issue with compiling the kamada_kawai_spring_layout from the Boost library.
typedef geometry::model::point<double, 2, geometry::cs::cartesian> point ;
typedef boost::adjacency_list<
boost::vecS,
boost::vecS,
boost::undirectedS,
boost::property<boost::vertex_index_t, int>,
boost::property<boost::edge_index_t, int,
boost::property<boost::edge_weight_t, int> >
graph;
graph g(this->HubSet.size());
//Add edge
map<pairs,int>::iterator iter;
for(iter = this->edge.begin() ; iter != this->edge.end() ; iter++)
{
pairs tmpPair = iter->first;
add_edge(tmpPair.first, tmpPair.second, 1.0, g);
}
//Position Map
typedef vector<point> PositionMap;
PositionMap position(num_vertices(g));
position[33] = point(250.0, 2000.0);
position[35] = point(8000.0, 2000.0);
auto position_map = boost::make_iterator_property_map(position.begin(), get(boost::vertex_index, g));
//Topology
std::minstd_rand gen;
rectangle_topology<std::minstd_rand> topo(gen, 0.0, 0.0, 9000.0, 9000.0);
random_graph_layout(g, position_map, topo);
//Call Force directed algorithm
boost::kamada_kawai_spring_layout(g,
position_map,
get(edge_weight, g),
topo,
edge_length(100.0) );
I would like to inquire about an issue with my code compilation. Could you please help me identify the modifications needed for successful compilation?
It’s impossible to figure out what error you are getting, because you post incomplete code.
If I make up some of the missing code my best guess is that your position map fails to match the documented criteria:
So, instead use:
Then, when we also make the edge weight arithmetically compatible with the coordinate types, this has the potential to compile:
Live On Coliru
BONUS
If you MUST have geometry support down the road, you can adapt the point type:
At that point you can use
boost::geometry::make<Point>(x,y)instead of the bespoke lambda.