//======================================================================= // Copyright 2001 Jeremy G. Siek, Andrew Lumsdaine, Lie-Quan Lee, // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) //======================================================================= // changed by me :-) #include #include #include #include #include #include #include #include #include #include #include #include #include "bfs_distmap_as_color_map.hpp" using namespace boost; struct VertexP { // boost::default_color_type color; int vertex_degree; int vertex_in_degree; int vertex_out_degree; int distance; }; int main(int , char* []) { typedef boost::adjacency_list< boost::mapS, boost::vecS, boost::bidirectionalS, VertexP> Graph; Graph G(5); boost::add_edge(0, 2, G); boost::add_edge(1, 1, G); boost::add_edge(1, 3, G); boost::add_edge(1, 4, G); boost::add_edge(2, 1, G); boost::add_edge(2, 3, G); boost::add_edge(2, 4, G); boost::add_edge(3, 1, G); boost::add_edge(3, 4, G); boost::add_edge(4, 0, G); boost::add_edge(4, 1, G); typedef Graph::vertex_descriptor Vertex; Graph G_copy(5); // Array to store predecessor (parent) of each vertex. This will be // used as a Decorator (actually, its iterator will be). std::vector p(boost::num_vertices(G)); // VC++ version of std::vector has no ::pointer, so // I use ::value_type* instead. typedef std::vector::value_type* Piter; typedef boost::graph_traits::vertex_iterator VI; VI vi, vi_end; for (tie(vi, vi_end)=vertices(G); vi!=vi_end; vi++) { G[*vi].distance = -1; } // map //MapAsColorMap::vertices_size_type>, int> //MapAsColorMap MapAsColorMap::type, boost::default_color_type> colormap(get(&VertexP::distance, G), -1); // colormap = make_map_as_colormap(G, get(&VertexP::distance, G), size_t(), -1); // The source vertex Vertex s = *(vertices(G).first); G[s].distance = 0; p[s] = s; breadth_first_search (G, s , visitor(boost::make_bfs_visitor (std::make_pair(record_distances(get(&VertexP::distance, G), on_tree_edge()), record_predecessors(&p[0], on_tree_edge()) ))) . color_map(colormap) ); // boost::print_graph(G); return 0; }