我正在尝试在fruchterman_reingold_force_directed_layout
图表上运行boost::adjacency_list<boost::listS, boost::listS, boost::bidirectionalS, Vertex, Edge>
算法。
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/fruchterman_reingold.hpp>
#include <boost/graph/random_layout.hpp>
typedef boost::rectangle_topology<> RectTopology;
typedef RectTopology::point_type point;
struct Vertex {
Vertex(int i) : index(i) {};
int index;
point position;
};
struct Edge {
double weight;
};
typedef boost::adjacency_list<boost::listS, boost::listS, boost::bidirectionalS, Vertex, Edge> Graph;
int main() {
Graph graph;
auto vertexIdPropertyMap = boost::get(&Vertex::index, graph);
Vertex n1(0);
boost::add_vertex(std::move(n1), graph);
Vertex n2(1);
boost::add_vertex(std::move(n2), graph);
Vertex n3(2);
boost::add_vertex(std::move(n3), graph);
boost::add_edge(boost::vertex(0, graph), boost::vertex(1, graph), Edge(), graph);
boost::add_edge(boost::vertex(0, graph), boost::vertex(2, graph), Edge(), graph);
boost::minstd_rand gen;
RectTopology rectangleTopology(gen, -25, -25, 25, 25);
boost::random_graph_layout(graph, boost::get(&Vertex::position, graph), rectangleTopology);
boost::fruchterman_reingold_force_directed_layout(graph, boost::get(&Vertex::position, graph), rectangleTopology);
return 0;
}
编译时,第一个错误如下:
error: forming reference to void
typedef value_type& reference;
我做了一些研究,显然这是因为它是一个listS
顶点列表 - vecS
它有效。
但是,我仍然想使用listS
,显然它是possible:
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/fruchterman_reingold.hpp>
#include <boost/graph/random_layout.hpp>
enum vertex_position_t { vertex_position };
namespace boost { BOOST_INSTALL_PROPERTY(vertex, position); }
typedef boost::rectangle_topology<> RectTopology;
typedef RectTopology::point_type point;
struct simple_edge {
int first, second;
};
int main() {
enum { A, B, C };
simple_edge triangular_edges[2] = {
{A, B}, {A, C}
};
typedef boost::adjacency_list<boost::listS, boost::listS, boost::bidirectionalS,
// Vertex properties
boost::property<boost::vertex_index_t, int,
boost::property<vertex_position_t, point> >,
// Edge properties
boost::property<boost::edge_weight_t, double>> Graph;
Graph g(&triangular_edges[0], &triangular_edges[1], 3);
boost::minstd_rand gen;
RectTopology rect_top(gen, -25, -25, 25, 25);
boost::random_graph_layout(g, boost::get(vertex_position, g), rect_top);
boost::fruchterman_reingold_force_directed_layout(g, boost::get(vertex_position, g), rect_top);
return 0;
}
这里的问题是我不想使用“旧式”属性,而是使用bundled properties。 Here某人正在尝试类似的内容,但如果我没有误会,则fruchterman_reingold_force_directed_layout
不会提供此索引图。