#include #include #include #include #include #include #include #include #include //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 Graph; typedef boost::property_map::type VertexIndexPropertyMap; typedef boost::property_map::type PositionMap; typedef boost::property_map::type WeightPropertyMap; typedef boost::graph_traits::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); // boost::add_edge(boost::vertex(3, graph), boost::vertex(0, graph), EdgeProperty(5), graph); // boost::add_edge(boost::vertex(4, graph), boost::vertex(0, graph), EdgeProperty(5), graph); // boost::add_edge(boost::vertex(5, 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(10), boost::layout_tolerance<>(), 1, vertexIdPropertyMap); */ std::cout << "Coordinates\n"; boost::graph_traits::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; } /* 1>------ Build started: Project: GraphTest, Configuration: Debug Win32 ------ 1>Compiling... 1>GraphTest.cpp 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) 1> with 1> [ 1> _Ty=PointDiff, 1> _Alloc=std::allocator 1> ] 1> d:\sourcen\boost_1_42_0\boost\graph\topology.hpp(56): could be 'boost::convex_topology::point_difference boost::operator +(const boost::convex_topology::point_difference &,const boost::convex_topology::point_difference &)' [found using argument-dependent lookup] 1> with 1> [ 1> Dims=2 1> ] 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' 1> with 1> [ 1> _Ty=PointDiff, 1> _Alloc=std::allocator 1> ] 1> while trying to match the argument list '(const std::_Vector_iterator<_Ty,_Alloc>, const boost::detail::error_property_not_found)' 1> with 1> [ 1> _Ty=PointDiff, 1> _Alloc=std::allocator 1> ] 1> d:\sourcen\boost_1_42_0\boost\property_map\property_map.hpp(355) : while compiling class template member function 'boost::convex_topology::point_difference boost::iterator_property_map::operator [](void *) const' 1> with 1> [ 1> Dims=2, 1> RandomAccessIterator=std::_Vector_iterator>, 1> IndexMap=boost::adj_list_vertex_property_map, 1> T=boost::convex_topology<2>::point_difference, 1> R=boost::convex_topology<2>::point_difference & 1> ] 1> d:\sourcen\boost_1_42_0\boost\graph\fruchterman_reingold.hpp(392) : see reference to class template instantiation 'boost::iterator_property_map' being compiled 1> with 1> [ 1> RandomAccessIterator=std::_Vector_iterator>, 1> IndexMap=boost::adj_list_vertex_property_map, 1> T=boost::convex_topology<2>::point_difference, 1> R=boost::convex_topology<2>::point_difference & 1> ] 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::run,boost::linear_cooling,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 &)' being compiled 1> with 1> [ 1> Topology=boost::square_topology<>, 1> Graph=Graph, 1> PositionMap=PositionMap, 1> T=double, 1> AttractiveForce=boost::square_distance_attractive_force, 1> RepulsiveForce=boost::square_distance_repulsive_force, 1> ForcePairs=boost::grid_force_pairs,PositionMap>, 1> Cooling=boost::linear_cooling, 1> Tag=boost::attractive_force_t, 1> Base=boost::no_property 1> ] 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(const Graph &,PositionMap,const Topology &,const boost::bgl_named_params &)' being compiled 1> with 1> [ 1> Topology=boost::square_topology<>, 1> Graph=Graph, 1> PositionMap=PositionMap, 1> T=boost::square_distance_attractive_force, 1> Tag=boost::attractive_force_t, 1> Base=boost::no_property 1> ] 1> d:\sourcen\test\c++\graphtest\graphtest.cpp(64) : see reference to function template instantiation 'void boost::fruchterman_reingold_force_directed_layout,Graph,PositionMap>(const Graph &,PositionMap,const Topology &)' being compiled 1> with 1> [ 1> Graph=Graph, 1> PositionMap=PositionMap, 1> Topology=boost::square_topology<> 1> ] 1>Build Time 0:04 1>Build log was saved at "file://d:\Sourcen\Test\C++\GraphTest\Debug\BuildLog.htm" 1>GraphTest - 1 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== */