Ticket #6033: patchfile.patch
File patchfile.patch, 5.0 KB (added by , 11 years ago) |
---|
-
biconnected_components.hpp
27 27 { 28 28 template<typename ComponentMap, typename DiscoverTimeMap, 29 29 typename LowPointMap, typename PredecessorMap, 30 typename OutputIterator, typename Stack, 30 typename OutputIterator, typename Stack, 31 typename ArticulationVector, typename IndexMap, 31 32 typename DFSVisitor> 32 33 struct biconnected_components_visitor : public dfs_visitor<> 33 34 { 34 35 biconnected_components_visitor 35 (ComponentMap comp, std::size_t& c, DiscoverTimeMap dtm, 36 (ComponentMap comp, std::size_t& c, 37 std::size_t& children_of_root, DiscoverTimeMap dtm, 36 38 std::size_t& dfs_time, LowPointMap lowpt, PredecessorMap pred, 37 OutputIterator out, Stack& S, DFSVisitor vis) 38 : comp(comp), c(c), children_of_root(0), dtm(dtm), 39 dfs_time(dfs_time), lowpt(lowpt), 40 pred(pred), out(out), S(S), vis(vis) { } 39 OutputIterator out, Stack& S, 40 ArticulationVector& is_articulation_point, IndexMap index_map, 41 DFSVisitor vis) 42 : comp(comp), c(c), children_of_root(children_of_root), 43 dtm(dtm), dfs_time(dfs_time), lowpt(lowpt), 44 pred(pred), out(out), S(S), 45 is_articulation_point(is_articulation_point), 46 index_map(index_map), vis(vis) { } 41 47 42 48 template <typename Vertex, typename Graph> 43 49 void initialize_vertex(const Vertex& u, Graph& g) … … 88 94 89 95 typename boost::graph_traits<Graph>::vertex_descriptor src = source(e, g); 90 96 typename boost::graph_traits<Graph>::vertex_descriptor tgt = target(e, g); 91 if ( ( tgt != get(pred, src) || get(pred, src) == src ) && 92 get(dtm, tgt) < get(dtm, src) ) { 97 if ( tgt != get(pred, src) ) { 93 98 S.push(e); 94 99 put(lowpt, src, 95 100 min BOOST_PREVENT_MACRO_SUBSTITUTION(get(lowpt, src), … … 110 115 BOOST_USING_STD_MIN(); 111 116 Vertex parent = get(pred, u); 112 117 if (parent == u) { // Root of tree is special 113 if (children_of_root >= 2) { 114 *out++ = u; 115 } 116 return; 117 } 118 put(lowpt, parent, 119 min BOOST_PREVENT_MACRO_SUBSTITUTION(get(lowpt, parent), 118 is_articulation_point[get(index_map, u)] = (children_of_root > 1); 119 } else { 120 put(lowpt, parent, 121 min BOOST_PREVENT_MACRO_SUBSTITUTION(get(lowpt, parent), 120 122 get(lowpt, u))); 121 if ( get(lowpt, u) >= get(dtm, parent) ) { 122 if ( get(pred, parent) != parent ) { 123 *out++ = parent; 124 } 125 while ( get(dtm, source(S.top(), g)) >= get(dtm, u) ) { 123 if ( get(lowpt, u) >= get(dtm, parent) ) { 124 is_articulation_point[get(index_map, parent)] = true; 125 while ( get(dtm, source(S.top(), g)) >= get(dtm, u) ) { 126 put(comp, S.top(), c); 127 S.pop(); 128 } 129 assert (source(S.top(), g) == parent); 130 assert (target(S.top(), g) == u); 126 131 put(comp, S.top(), c); 127 132 S.pop(); 133 ++c; 128 134 } 129 assert (source(S.top(), g) == parent);130 assert (target(S.top(), g) == u);131 put(comp, S.top(), c);132 S.pop();133 ++c;134 135 } 136 if ( is_articulation_point[get(index_map, u)] ) { 137 *out++ = u; 138 } 135 139 vis.finish_vertex(u, g); 136 140 } 137 141 138 142 ComponentMap comp; 139 143 std::size_t& c; 140 std::size_t children_of_root;144 std::size_t& children_of_root; 141 145 DiscoverTimeMap dtm; 142 146 std::size_t& dfs_time; 143 147 LowPointMap lowpt; 144 148 PredecessorMap pred; 145 149 OutputIterator out; 146 150 Stack& S; 151 ArticulationVector& is_articulation_point; 152 IndexMap index_map; 147 153 DFSVisitor vis; 148 154 }; 149 155 … … 167 173 vertex_t> >(); 168 174 169 175 std::size_t num_components = 0; 176 std::size_t children_of_root; 170 177 std::size_t dfs_time = 0; 171 std::stack<edge_t> S; 178 std::stack<edge_t> S; 179 std::vector<char> is_articulation_point(num_vertices(g)); 172 180 173 174 175 176 vis(comp, num_components, dtm, dfs_time, lowpt, pred, out,177 S, dfs_vis);181 biconnected_components_visitor<ComponentMap, DiscoverTimeMap, 182 LowPointMap, PredecessorMap, OutputIterator, std::stack<edge_t>, 183 std::vector<char>, VertexIndexMap, DFSVisitor> 184 vis(comp, num_components, children_of_root, dtm, dfs_time, 185 lowpt, pred, out, S, is_articulation_point, index_map, dfs_vis); 178 186 179 187 depth_first_search(g, visitor(vis).vertex_index_map(index_map)); 180 188