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 | /*
|
---|
67 | boost::kamada_kawai_spring_layout(graph, positionMap, weightPropertyMap,
|
---|
68 | boost::square_topology<>(), boost::side_length<double>(10), boost::layout_tolerance<>(),
|
---|
69 | 1, vertexIdPropertyMap);
|
---|
70 | */
|
---|
71 |
|
---|
72 | std::cout << "Coordinates\n";
|
---|
73 | boost::graph_traits<Graph>::vertex_iterator i, end;
|
---|
74 | for (boost::tie(i, end) = boost::vertices(graph); i != end; ++i) {
|
---|
75 | std::cout << "ID: (" << vertexIdPropertyMap[*i] << ") x: " << positionMap[*i][0] << " y: " << positionMap[*i][1] << "\n";
|
---|
76 | }
|
---|
77 |
|
---|
78 | return 0;
|
---|
79 | }
|
---|
80 |
|
---|
81 |
|
---|
82 | /*
|
---|
83 |
|
---|
84 | 1>------ Build started: Project: GraphTest, Configuration: Debug Win32 ------
|
---|
85 | 1>Compiling...
|
---|
86 | 1>GraphTest.cpp
|
---|
87 | 1>d:\sourcen\boost_1_42_0\boost\property_map\property_map.hpp(355) : error C2678: binary '+' : no operator found which takes a left-hand operand of type 'const std::_Vector_iterator<_Ty,_Alloc>' (or there is no acceptable conversion)
|
---|
88 | 1> with
|
---|
89 | 1> [
|
---|
90 | 1> _Ty=PointDiff,
|
---|
91 | 1> _Alloc=std::allocator<PointDiff>
|
---|
92 | 1> ]
|
---|
93 | 1> d:\sourcen\boost_1_42_0\boost\graph\topology.hpp(56): could be 'boost::convex_topology<Dims>::point_difference boost::operator +(const boost::convex_topology<Dims>::point_difference &,const boost::convex_topology<Dims>::point_difference &)' [found using argument-dependent lookup]
|
---|
94 | 1> with
|
---|
95 | 1> [
|
---|
96 | 1> Dims=2
|
---|
97 | 1> ]
|
---|
98 | 1> c:\program files\microsoft visual studio 8\vc\include\vector(366): or 'std::_Vector_iterator<_Ty,_Alloc> std::_Vector_iterator<_Ty,_Alloc>::operator +(__w64 int) const'
|
---|
99 | 1> with
|
---|
100 | 1> [
|
---|
101 | 1> _Ty=PointDiff,
|
---|
102 | 1> _Alloc=std::allocator<PointDiff>
|
---|
103 | 1> ]
|
---|
104 | 1> while trying to match the argument list '(const std::_Vector_iterator<_Ty,_Alloc>, const boost::detail::error_property_not_found)'
|
---|
105 | 1> with
|
---|
106 | 1> [
|
---|
107 | 1> _Ty=PointDiff,
|
---|
108 | 1> _Alloc=std::allocator<PointDiff>
|
---|
109 | 1> ]
|
---|
110 | 1> d:\sourcen\boost_1_42_0\boost\property_map\property_map.hpp(355) : while compiling class template member function 'boost::convex_topology<Dims>::point_difference boost::iterator_property_map<RandomAccessIterator,IndexMap,T,R>::operator [](void *) const'
|
---|
111 | 1> with
|
---|
112 | 1> [
|
---|
113 | 1> Dims=2,
|
---|
114 | 1> RandomAccessIterator=std::_Vector_iterator<PointDiff,std::allocator<PointDiff>>,
|
---|
115 | 1> IndexMap=boost::adj_list_vertex_property_map<Graph,boost::detail::error_property_not_found,const boost::detail::error_property_not_found &,boost::vertex_index_t>,
|
---|
116 | 1> T=boost::convex_topology<2>::point_difference,
|
---|
117 | 1> R=boost::convex_topology<2>::point_difference &
|
---|
118 | 1> ]
|
---|
119 | 1> d:\sourcen\boost_1_42_0\boost\graph\fruchterman_reingold.hpp(392) : see reference to class template instantiation 'boost::iterator_property_map<RandomAccessIterator,IndexMap,T,R>' being compiled
|
---|
120 | 1> with
|
---|
121 | 1> [
|
---|
122 | 1> RandomAccessIterator=std::_Vector_iterator<PointDiff,std::allocator<PointDiff>>,
|
---|
123 | 1> IndexMap=boost::adj_list_vertex_property_map<Graph,boost::detail::error_property_not_found,const boost::detail::error_property_not_found &,boost::vertex_index_t>,
|
---|
124 | 1> T=boost::convex_topology<2>::point_difference,
|
---|
125 | 1> R=boost::convex_topology<2>::point_difference &
|
---|
126 | 1> ]
|
---|
127 | 1> d:\sourcen\boost_1_42_0\boost\graph\fruchterman_reingold.hpp(421) : see reference to function template instantiation 'void boost::detail::fr_force_directed_layout<boost::detail::error_property_not_found>::run<Topology,Graph,PositionMap,boost::square_distance_attractive_force,boost::square_distance_repulsive_force,boost::grid_force_pairs<Topology,PositionMap>,boost::linear_cooling<T>,boost::square_distance_attractive_force,boost::attractive_force_t,boost::no_property>(const Graph &,PositionMap,const Topology &,AttractiveForce,RepulsiveForce,ForcePairs,Cooling,boost::detail::error_property_not_found,const boost::bgl_named_params<boost::square_distance_attractive_force,Tag,Base> &)' being compiled
|
---|
128 | 1> with
|
---|
129 | 1> [
|
---|
130 | 1> Topology=boost::square_topology<>,
|
---|
131 | 1> Graph=Graph,
|
---|
132 | 1> PositionMap=PositionMap,
|
---|
133 | 1> T=double,
|
---|
134 | 1> AttractiveForce=boost::square_distance_attractive_force,
|
---|
135 | 1> RepulsiveForce=boost::square_distance_repulsive_force,
|
---|
136 | 1> ForcePairs=boost::grid_force_pairs<boost::square_topology<>,PositionMap>,
|
---|
137 | 1> Cooling=boost::linear_cooling<double>,
|
---|
138 | 1> Tag=boost::attractive_force_t,
|
---|
139 | 1> Base=boost::no_property
|
---|
140 | 1> ]
|
---|
141 | 1> d:\sourcen\boost_1_42_0\boost\graph\fruchterman_reingold.hpp(433) : see reference to function template instantiation 'void boost::fruchterman_reingold_force_directed_layout<Topology,Graph,PositionMap,boost::square_distance_attractive_force,boost::attractive_force_t,boost::no_property>(const Graph &,PositionMap,const Topology &,const boost::bgl_named_params<T,Tag,Base> &)' being compiled
|
---|
142 | 1> with
|
---|
143 | 1> [
|
---|
144 | 1> Topology=boost::square_topology<>,
|
---|
145 | 1> Graph=Graph,
|
---|
146 | 1> PositionMap=PositionMap,
|
---|
147 | 1> T=boost::square_distance_attractive_force,
|
---|
148 | 1> Tag=boost::attractive_force_t,
|
---|
149 | 1> Base=boost::no_property
|
---|
150 | 1> ]
|
---|
151 | 1> d:\sourcen\test\c++\graphtest\graphtest.cpp(64) : see reference to function template instantiation 'void boost::fruchterman_reingold_force_directed_layout<boost::square_topology<>,Graph,PositionMap>(const Graph &,PositionMap,const Topology &)' being compiled
|
---|
152 | 1> with
|
---|
153 | 1> [
|
---|
154 | 1> Graph=Graph,
|
---|
155 | 1> PositionMap=PositionMap,
|
---|
156 | 1> Topology=boost::square_topology<>
|
---|
157 | 1> ]
|
---|
158 | 1>Build Time 0:04
|
---|
159 | 1>Build log was saved at "file://d:\Sourcen\Test\C++\GraphTest\Debug\BuildLog.htm"
|
---|
160 | 1>GraphTest - 1 error(s), 0 warning(s)
|
---|
161 | ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
|
---|
162 |
|
---|
163 |
|
---|
164 | */
|
---|