Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:37:32

0001 //=======================================================================
0002 // Copyright 2007 Aaron Windsor
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See
0005 // accompanying file LICENSE_1_0.txt or copy at
0006 // http://www.boost.org/LICENSE_1_0.txt)
0007 //=======================================================================
0008 #ifndef __MAKE_CONNECTED_HPP__
0009 #define __MAKE_CONNECTED_HPP__
0010 
0011 #include <boost/config.hpp>
0012 #include <boost/next_prior.hpp>
0013 #include <boost/tuple/tuple.hpp> //for tie
0014 #include <boost/graph/connected_components.hpp>
0015 #include <boost/property_map/property_map.hpp>
0016 #include <vector>
0017 
0018 #include <boost/graph/planar_detail/add_edge_visitors.hpp>
0019 #include <boost/graph/planar_detail/bucket_sort.hpp>
0020 
0021 namespace boost
0022 {
0023 
0024 template < typename Graph, typename VertexIndexMap, typename AddEdgeVisitor >
0025 void make_connected(Graph& g, VertexIndexMap vm, AddEdgeVisitor& vis)
0026 {
0027     typedef typename graph_traits< Graph >::vertex_iterator vertex_iterator_t;
0028     typedef typename graph_traits< Graph >::vertex_descriptor vertex_t;
0029     typedef typename graph_traits< Graph >::vertices_size_type v_size_t;
0030     typedef iterator_property_map< typename std::vector< v_size_t >::iterator,
0031         VertexIndexMap >
0032         vertex_to_v_size_map_t;
0033 
0034     std::vector< v_size_t > component_vector(num_vertices(g));
0035     vertex_to_v_size_map_t component(component_vector.begin(), vm);
0036     std::vector< vertex_t > vertices_by_component(num_vertices(g));
0037 
0038     v_size_t num_components = connected_components(g, component);
0039 
0040     if (num_components < 2)
0041         return;
0042 
0043     vertex_iterator_t vi, vi_end;
0044     boost::tie(vi, vi_end) = vertices(g);
0045     std::copy(vi, vi_end, vertices_by_component.begin());
0046 
0047     bucket_sort(vertices_by_component.begin(), vertices_by_component.end(),
0048         component, num_components);
0049 
0050     typedef typename std::vector< vertex_t >::iterator vec_of_vertices_itr_t;
0051 
0052     vec_of_vertices_itr_t ci_end = vertices_by_component.end();
0053     vec_of_vertices_itr_t ci_prev = vertices_by_component.begin();
0054     if (ci_prev == ci_end)
0055         return;
0056 
0057     for (vec_of_vertices_itr_t ci = boost::next(ci_prev); ci != ci_end;
0058          ci_prev = ci, ++ci)
0059     {
0060         if (component[*ci_prev] != component[*ci])
0061             vis.visit_vertex_pair(*ci_prev, *ci, g);
0062     }
0063 }
0064 
0065 template < typename Graph, typename VertexIndexMap >
0066 inline void make_connected(Graph& g, VertexIndexMap vm)
0067 {
0068     default_add_edge_visitor vis;
0069     make_connected(g, vm, vis);
0070 }
0071 
0072 template < typename Graph > inline void make_connected(Graph& g)
0073 {
0074     make_connected(g, get(vertex_index, g));
0075 }
0076 
0077 } // namespace boost
0078 
0079 #endif //__MAKE_CONNECTED_HPP__