st_number.h

00001 //==========================================================================
00002 //
00003 //   st_number.h
00004 //
00005 //==========================================================================
00006 // $Id: st_number.h,v 1.17 2002/12/20 08:26:08 chris Exp $
00007 
00008 #ifndef GTL_ST_NUMBER_H
00009 #define GTL_ST_NUMBER_H
00010 
00011 #include <GTL/GTL.h>
00012 #include <GTL/graph.h>
00013 #include <GTL/node_map.h>
00014 #include <GTL/edge_map.h>
00015 #include <GTL/algorithm.h>
00016 
00017 #include <list>
00018 #include <utility>
00019 
00020 __GTL_BEGIN_NAMESPACE
00021 
00025 class GTL_EXTERN pathfinder 
00026 {
00027 public:
00028     //---------------------------------------------------------- CONSTRUCTOR
00029         
00033     pathfinder(const graph& G, edge st, node s);    
00034         
00038     bool is_valid()
00039     {
00040         return is_biconn;
00041     }
00042         
00043     //------------------------------------------------------------- ITERATOR
00044         
00048     class const_iterator 
00049     {
00050     public:
00054         const_iterator(pathfinder& _pf) : pf (_pf)
00055         {
00056         }
00057 
00061         const_iterator(pathfinder& _pf, node n);        
00062                 
00066         const_iterator& operator++();
00070         const_iterator operator++(int);
00074         const node& operator*() const 
00075         {
00076             return curr;
00077         }
00078                 
00082         bool operator==(const const_iterator& it) 
00083         {
00084             return curr == it.curr;
00085         }
00086 
00090         bool operator!=(const const_iterator& it)
00091         {
00092             return curr != it.curr;
00093         }
00094     private:
00098         enum iteration_state {END, UP, DOWN};
00099 
00103         iteration_state state;
00104 
00108         node curr;
00109 
00113         pathfinder& pf;
00114     };
00115         
00119     const_iterator path(node n)
00120     {
00121         return const_iterator(*this, n);
00122     }
00123         
00127     const_iterator end()
00128     {
00129         return const_iterator (*this);
00130     }
00131         
00132 private:
00133     //------------------------------------------------------------ FUNCTIONS
00134                 
00138     void dfs_sub (node&, node&);
00139                 
00140     //-------------------------------------------------------------- MEMBERS 
00141                 
00145     node_map<int> dfs_num;
00146 
00150     node_map<int> low_num;
00151 
00155     node_map<list<edge> > tree;
00156 
00160     node_map<list<edge> > back;
00161 
00165     node_map<list<edge> > forward;
00166 
00170     node_map<list<edge>::iterator> to_low;
00171 
00175     node_map<list<edge>::iterator> to_father;
00176                 
00180     typedef pair<list<edge>::iterator, list<edge>::iterator> pos_pair;
00181 
00185     edge_map<pos_pair > pos;
00186 
00190     node_map<int> used;
00191                 
00195     int act_dfs_num;
00196 
00200     int new_nodes;
00201 
00205     bool is_biconn;
00206                 
00211     friend class const_iterator;
00212 };
00213 
00232 class GTL_EXTERN st_number : public algorithm 
00233 {
00234 public:
00242     st_number() : algorithm()
00243     {
00244     }
00245 
00249     virtual ~st_number()
00250     {
00251     }
00252         
00258     void st_edge(edge e)
00259     {
00260         st = e;
00261     }
00262 
00268     edge st_edge() const
00269     {
00270         return st;
00271     }
00272 
00282     void s_node(node n) 
00283     {
00284         s = n;
00285     }
00286 
00292     node s_node() const
00293     {
00294         return s;
00295     }
00296 
00304     int& operator[](const node& n)
00305     {
00306         return st_num[n];
00307     }
00308     
00312     typedef list<node>::iterator iterator;
00313 
00317     typedef list<node>::reverse_iterator reverse_iterator;
00318         
00325     iterator begin()
00326     {
00327         return st_ord.begin();
00328     }   
00329 
00335     iterator end()
00336     {
00337         return st_ord.end();
00338     }
00339         
00347     reverse_iterator rbegin()
00348     {
00349         return st_ord.rbegin();
00350     }
00351         
00358     reverse_iterator rend()
00359     {
00360         return st_ord.rend();
00361     }
00362         
00363 
00379     int check(graph& G);
00380 
00381 
00394     int run(graph& G);
00395 
00396 
00404     void reset()
00405     {
00406         st_ord.erase (st_ord.begin(), st_ord.end());
00407     }
00408 protected:
00412     edge st;
00413 
00417     node s;
00418 
00422     pathfinder* pf;
00423 
00427     list<node> st_ord;
00428 
00432     node_map<int> st_num;
00433 };
00434 
00435 __GTL_END_NAMESPACE
00436 
00437 #endif // GTL_ST_NUMBER_H
00438 
00439 //--------------------------------------------------------------------------
00440 //   end of file
00441 //--------------------------------------------------------------------------