| 1 | #include <boost/config.hpp>
 | 
|---|
| 2 | #include <boost/graph/adjacency_list.hpp>
 | 
|---|
| 3 | #include <boost/graph/graph_utility.hpp>
 | 
|---|
| 4 | #include <boost/graph/simple_point.hpp>
 | 
|---|
| 5 | #include <boost/property_map/property_map.hpp>
 | 
|---|
| 6 | #include <boost/graph/circle_layout.hpp>
 | 
|---|
| 7 | #include <boost/graph/fruchterman_reingold.hpp>
 | 
|---|
| 8 | #include <boost/graph/kamada_kawai_spring_layout.hpp>
 | 
|---|
| 9 | #include <iostream>
 | 
|---|
| 10 | 
 | 
|---|
| 11 | //typedef boost::square_topology<>::point_difference_type Point;
 | 
|---|
| 12 | typedef boost::square_topology<>::point_type Point;
 | 
|---|
| 13 | 
 | 
|---|
| 14 | struct VertexProperties
 | 
|---|
| 15 | {
 | 
|---|
| 16 |         std::size_t index;
 | 
|---|
| 17 |         Point point;
 | 
|---|
| 18 | };
 | 
|---|
| 19 | 
 | 
|---|
| 20 | struct EdgeProperty
 | 
|---|
| 21 | {
 | 
|---|
| 22 |         EdgeProperty(const std::size_t &w):weight(w) {}
 | 
|---|
| 23 |         double weight;
 | 
|---|
| 24 | };
 | 
|---|
| 25 | 
 | 
|---|
| 26 | 
 | 
|---|
| 27 | typedef boost::adjacency_list<boost::listS,
 | 
|---|
| 28 | boost::listS, boost::undirectedS,
 | 
|---|
| 29 | VertexProperties, EdgeProperty > Graph;
 | 
|---|
| 30 | 
 | 
|---|
| 31 | typedef boost::property_map<Graph, std::size_t VertexProperties::*>::type VertexIndexPropertyMap;
 | 
|---|
| 32 | typedef boost::property_map<Graph, Point VertexProperties::*>::type PositionMap;
 | 
|---|
| 33 | typedef boost::property_map<Graph, double EdgeProperty::*>::type WeightPropertyMap;
 | 
|---|
| 34 | 
 | 
|---|
| 35 | typedef boost::graph_traits<Graph>::vertex_descriptor VirtexDescriptor;
 | 
|---|
| 36 | 
 | 
|---|
| 37 | int main()
 | 
|---|
| 38 | {
 | 
|---|
| 39 |         Graph graph;
 | 
|---|
| 40 | 
 | 
|---|
| 41 |         VertexIndexPropertyMap vertexIdPropertyMap = boost::get(&VertexProperties::index, graph);
 | 
|---|
| 42 | 
 | 
|---|
| 43 |         for (int i = 0; i < 3; ++i) {
 | 
|---|
| 44 |                 VirtexDescriptor vd = boost::add_vertex(graph);
 | 
|---|
| 45 |                 vertexIdPropertyMap[vd] = i + 2;
 | 
|---|
| 46 |         }
 | 
|---|
| 47 | 
 | 
|---|
| 48 |         boost::add_edge(boost::vertex(1, graph), boost::vertex(0, graph), EdgeProperty(5), graph);
 | 
|---|
| 49 |         boost::add_edge(boost::vertex(2, graph), boost::vertex(0, graph), EdgeProperty(5), graph);
 | 
|---|
| 50 | //      boost::add_edge(boost::vertex(3, graph), boost::vertex(0, graph), EdgeProperty(5), graph);
 | 
|---|
| 51 | //      boost::add_edge(boost::vertex(4, graph), boost::vertex(0, graph), EdgeProperty(5), graph);
 | 
|---|
| 52 | //      boost::add_edge(boost::vertex(5, graph), boost::vertex(0, graph), EdgeProperty(5), graph);
 | 
|---|
| 53 | 
 | 
|---|
| 54 |         std::cout << "Vertices\n";
 | 
|---|
| 55 |         boost::print_vertices(graph, vertexIdPropertyMap);
 | 
|---|
| 56 | 
 | 
|---|
| 57 |         std::cout << "Edges\n";
 | 
|---|
| 58 |         boost::print_edges(graph, vertexIdPropertyMap);
 | 
|---|
| 59 | 
 | 
|---|
| 60 |         PositionMap positionMap = boost::get(&VertexProperties::point, graph);
 | 
|---|
| 61 |         WeightPropertyMap weightPropertyMap = boost::get(&EdgeProperty::weight, graph);
 | 
|---|
| 62 | 
 | 
|---|
| 63 |         //boost::circle_graph_layout(graph, positionMap, 100);
 | 
|---|
| 64 |         //boost::fruchterman_reingold_force_directed_layout(graph, positionMap, boost::square_topology<>());
 | 
|---|
| 65 | 
 | 
|---|
| 66 |         boost::kamada_kawai_spring_layout(graph, positionMap, weightPropertyMap,
 | 
|---|
| 67 |                 boost::square_topology<>(), boost::side_length<double>(10), boost::layout_tolerance<>(),
 | 
|---|
| 68 |                 1, vertexIdPropertyMap);
 | 
|---|
| 69 | 
 | 
|---|
| 70 |         std::cout << "Coordinates\n";
 | 
|---|
| 71 |         boost::graph_traits<Graph>::vertex_iterator i, end;
 | 
|---|
| 72 |         for (boost::tie(i, end) = boost::vertices(graph); i != end; ++i) {
 | 
|---|
| 73 |                 std::cout << "ID: (" << vertexIdPropertyMap[*i] << ") x: " << positionMap[*i][0] << " y: " << positionMap[*i][1] << "\n";
 | 
|---|
| 74 |         }
 | 
|---|
| 75 | 
 | 
|---|
| 76 |         return 0;
 | 
|---|
| 77 | }
 | 
|---|
| 78 | 
 | 
|---|