biconnectivity.h

00001 //==========================================================================
00002 //
00003 //   biconnectivity.h
00004 //
00005 //==========================================================================
00006 // $Id: biconnectivity.h,v 1.18 2003/03/26 13:37:14 raitner Exp $
00007 
00008 #ifndef GTL_BICONNECTIVITY_H
00009 #define GTL_BICONNECTIVITY_H
00010 
00011 #include <GTL/GTL.h>
00012 #include <GTL/dfs.h>
00013 
00014 #include <list>
00015 #include <stack>
00016 
00017 __GTL_BEGIN_NAMESPACE
00018 
00035 class GTL_EXTERN biconnectivity : public dfs 
00036 {
00037 public:
00043     biconnectivity ();
00044 
00050     virtual ~biconnectivity () {}
00051 
00065     virtual int check (graph& G);
00066 
00067     virtual void reset ();
00068 
00075     int low_number (const node& n) const 
00076         {return low_num[n];}
00077 
00083     bool is_biconnected () const 
00084         {return num_of_components == 1;}
00085 
00092     bool store_components () const
00093         { return store_comp; }
00094 
00105     void store_components (bool set) 
00106         { store_comp  = set; if (set) scan_whole_graph (set); }
00107     
00119     void make_biconnected (bool set) 
00120         { add_edges = set; if (set) scan_whole_graph (set); }
00121     
00129     bool make_biconnected () const 
00130         { return add_edges; }
00131     
00138     list<edge>::iterator additional_begin ()
00139         { return additional.begin (); }
00140 
00147     list<edge>::iterator additional_end ()
00148         { return additional.end (); }
00149     
00153     typedef list<node>::iterator cutpoint_iterator;
00154 
00164     cutpoint_iterator cut_points_begin () 
00165         { return cut_points.begin(); }
00166 
00173     cutpoint_iterator cut_points_end () 
00174         { return cut_points.end(); }
00175 
00176 
00180     typedef list<pair<list<node>, list<edge> > >::iterator component_iterator;
00181 
00195     component_iterator components_begin ()
00196         { return components.begin(); }
00197 
00198 
00205     component_iterator components_end ()
00206         { return components.end(); }
00207 
00213     int number_of_components () const
00214         {return num_of_components; }
00215 
00216     //-----------------------------------------------------------------------
00217     //   Handler used to extend dfs to biconnectivity
00218     //-----------------------------------------------------------------------
00222     virtual void init_handler (graph&);
00223 
00227     virtual void entry_handler (graph&, node&, node&);
00228 
00232     virtual void before_recursive_call_handler (graph&, edge&, node&);
00233 
00237     virtual void after_recursive_call_handler (graph&, edge&, node&);
00238 
00242     virtual void old_adj_node_handler (graph&, edge&, node&);
00243 
00247     virtual void new_start_handler (graph&, node&);    
00248 
00252     virtual void leave_handler (graph&, node&, node&);    
00253 
00257     virtual void end_handler (graph&);    
00258 
00259 
00260 protected:
00264     list<edge> self_loops;
00265 
00269     node_map<component_iterator> in_component;
00270 
00274     node_map<int> low_num;
00278     int num_of_components;
00282     bool store_comp;
00286     bool add_edges;
00290     node last;
00294     stack<node> node_stack;
00298     stack<edge> edge_stack;
00302     list<pair<list<node>, list<edge> > > components;
00306     list<node> cut_points;
00310     node_map<int> cut_count;
00314     list<edge> additional;
00318     node_map<node> first_child;
00319 };
00320 
00321 __GTL_END_NAMESPACE
00322 
00323 #endif // GTL_BICONNECTIVITY_H
00324 
00325 //--------------------------------------------------------------------------
00326 //   end of file
00327 //--------------------------------------------------------------------------