3
我有使用boost圖形佈局算法的問題。 boost verision 1_41_0 mingw g ++ 4.4.0。如何使用Boost 1.41.0圖形佈局算法
所以有我遇到的問題你可以建議我與他們?
- 未編譯函數fruchterman_reingold_force_directed_layout。
- 已編譯kamada_kawai_spring_layout但程序崩潰。
- 將佈局算法升級到佈局算法是錯誤的,未對fruchterman_reingold_force_directed_layout進行編譯。
這是我的例子。使用功能只需取消註釋。串60,61,63
#include <boost/config.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graph_utility.hpp>
#include <boost/graph/simple_point.hpp>
#include <boost/property_map/property_map.hpp>
#include <boost/graph/circle_layout.hpp>
#include <boost/graph/fruchterman_reingold.hpp>
#include <boost/graph/kamada_kawai_spring_layout.hpp>
#include <iostream>
//typedef boost::square_topology<>::point_difference_type Point;
typedef boost::square_topology<>::point_type Point;
struct VertexProperties
{
std::size_t index;
Point point;
};
struct EdgeProperty
{
EdgeProperty(const std::size_t &w):weight(w) {}
double weight;
};
typedef boost::adjacency_list<boost::listS,
boost::listS, boost::undirectedS,
VertexProperties, EdgeProperty > Graph;
typedef boost::property_map<Graph, std::size_t VertexProperties::*>::type VertexIndexPropertyMap;
typedef boost::property_map<Graph, Point VertexProperties::*>::type PositionMap;
typedef boost::property_map<Graph, double EdgeProperty::*>::type WeightPropertyMap;
typedef boost::graph_traits<Graph>::vertex_descriptor VirtexDescriptor;
int main()
{
Graph graph;
VertexIndexPropertyMap vertexIdPropertyMap = boost::get(&VertexProperties::index, graph);
for (int i = 0; i < 3; ++i) {
VirtexDescriptor vd = boost::add_vertex(graph);
vertexIdPropertyMap[vd] = i + 2;
}
boost::add_edge(boost::vertex(1, graph), boost::vertex(0, graph), EdgeProperty(5), graph);
boost::add_edge(boost::vertex(2, graph), boost::vertex(0, graph), EdgeProperty(5), graph);
std::cout << "Vertices\n";
boost::print_vertices(graph, vertexIdPropertyMap);
std::cout << "Edges\n";
boost::print_edges(graph, vertexIdPropertyMap);
PositionMap positionMap = boost::get(&VertexProperties::point, graph);
WeightPropertyMap weightPropertyMap = boost::get(&EdgeProperty::weight, graph);
boost::circle_graph_layout(graph, positionMap, 100);
// boost::fruchterman_reingold_force_directed_layout(graph, positionMap, boost::square_topology<>());
boost::kamada_kawai_spring_layout(graph, positionMap, weightPropertyMap,
boost::square_topology<>(), boost::side_length<double>(10), boost::layout_tolerance<>(),
1, vertexIdPropertyMap);
std::cout << "Coordinates\n";
boost::graph_traits<Graph>::vertex_iterator i, end;
for (boost::tie(i, end) = boost::vertices(graph); i != end; ++i) {
std::cout << "ID: (" << vertexIdPropertyMap[*i] << ") x: " << positionMap[*i][0] << " y: " << positionMap[*i][1] << "\n";
}
return 0;
}
謝謝你的回答。我只是研究boost圖庫。你能否使用boost的圖形庫佈局算法爲我提供示例。我認爲boost的圖表示例和文檔已經過時。 Daniil – Daniil 2010-03-29 08:43:24
試試這裏:http://www.boost.org/doc/libs/1_42_0/libs/graph/test/layout_test.cpp – baol 2010-03-30 18:42:48