Ticket #6033: patchfile.patch

File patchfile.patch, 5.0 KB (added by Jan Hazla <jan.hazla@…>, 11 years ago)

Proposed patch for fixing the lowpoint problem

  • biconnected_components.hpp

     
    2727  {
    2828    template<typename ComponentMap, typename DiscoverTimeMap,
    2929             typename LowPointMap, typename PredecessorMap,
    30              typename OutputIterator, typename Stack,
     30             typename OutputIterator, typename Stack,
     31             typename ArticulationVector, typename IndexMap,
    3132             typename DFSVisitor>
    3233    struct biconnected_components_visitor : public dfs_visitor<>
    3334    {
    3435      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,
    3638         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) { }
    4147
    4248      template <typename Vertex, typename Graph>
    4349      void initialize_vertex(const Vertex& u, Graph& g)
     
    8894
    8995        typename boost::graph_traits<Graph>::vertex_descriptor src = source(e, g);
    9096        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) ) {
    9398          S.push(e);
    9499          put(lowpt, src,
    95100              min BOOST_PREVENT_MACRO_SUBSTITUTION(get(lowpt, src),
     
    110115        BOOST_USING_STD_MIN();
    111116        Vertex parent = get(pred, u);
    112117        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),
    120122                                                 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);
    126131            put(comp, S.top(), c);
    127132            S.pop();
     133            ++c;
    128134          }
    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;
    134135        }
     136        if ( is_articulation_point[get(index_map, u)] ) {
     137          *out++ = u;
     138        }
    135139        vis.finish_vertex(u, g);
    136140      }
    137141
    138142      ComponentMap comp;
    139143      std::size_t& c;
    140       std::size_t children_of_root;
     144      std::size_t& children_of_root;
    141145      DiscoverTimeMap dtm;
    142146      std::size_t& dfs_time;
    143147      LowPointMap lowpt;
    144148      PredecessorMap pred;
    145149      OutputIterator out;
    146150      Stack& S;
     151      ArticulationVector& is_articulation_point;
     152      IndexMap index_map;
    147153      DFSVisitor vis;
    148154    };
    149155
     
    167173                                                  vertex_t> >();
    168174
    169175    std::size_t num_components = 0;
     176    std::size_t children_of_root;
    170177    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));
    172180
    173       biconnected_components_visitor<ComponentMap, DiscoverTimeMap,
    174           LowPointMap, PredecessorMap, OutputIterator, std::stack<edge_t>,
    175           DFSVisitor>
    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);
    178186
    179187    depth_first_search(g, visitor(vis).vertex_index_map(index_map));
    180188