src/ell/LT_BarrierTree.hh
Go to the documentation of this file.00001 #ifndef LT_BARRIERTREE_HH_
00002 #define LT_BARRIERTREE_HH_
00003
00004 #include <biu/HashMap.hh>
00005
00006 #include "ell/LT_MinimaSet.hh"
00007 #include "ell/State.hh"
00008
00009 #include <vector>
00010 #include <iostream>
00011 #include <string>
00012
00013
00014
00015
00016
00017
00018 namespace ell
00019 {
00020
00054 class LT_BarrierTree: public LT_MinimaSet {
00055
00056 public:
00057
00060 static const std::string LT_ID;
00061
00062
00063 protected:
00064
00065 class StateList;
00066 class NodeList;
00067
00071 class Node {
00072 public:
00074 Node* parent;
00076 NodeList* children;
00078 StateList* content;
00079
00081 Node( Node* parent,
00082 NodeList* children,
00083 StateList* content,
00084 const bool isRoot = false );
00085
00087 ~Node();
00088 };
00089
00090 class NodeList {
00091 public:
00093 Node* current;
00096 NodeList* next;
00097
00099 NodeList( Node* current, NodeList* next );
00100
00102 ~NodeList();
00103
00105 static
00106 void
00107 addToList( NodeList*& list, Node* toAdd );
00108
00109 static
00110 void
00111 remFromList( NodeList*& listHead, const Node* toRem );
00112
00113 };
00114
00115 class StateList {
00116 public:
00118 State* current;
00121 StateList* next;
00122
00124 StateList( State* current, StateList* next );
00125
00127 ~StateList();
00128
00130 static
00131 void
00132 addToList( StateList*& list, State* toAdd );
00133 };
00134
00135 #ifdef HAVE_GNU_HASH_MAP
00136
00137 class hash_StateP {
00138 public:
00139 size_t operator()(const State* s) const {
00140 return (size_t)s;
00141 }
00142 };
00143 class hash_NodeP {
00144 public:
00145 size_t operator()(const Node* n) const {
00146 return (size_t)n;
00147 }
00148 };
00149
00150 typedef __gnu_cxx::hash_map< const State*, Node*, hash_StateP > Min2Node_MAP;
00151 typedef __gnu_cxx::hash_map< const Node*, const Node*, hash_NodeP > Node2Node_MAP;
00152 typedef __gnu_cxx::hash_map< const Node*, size_t, hash_NodeP > Node2SizeT_MAP;
00153 typedef __gnu_cxx::hash_map< const Node*, int, hash_NodeP > Node2Int_MAP;
00154 typedef __gnu_cxx::hash_map< size_t, const Node* > SizeT2Node_MAP;
00155 #else
00156 typedef std::map< const State*, Node* > Min2Node_MAP;
00157 typedef std::map<const Node*, const Node* > Node2Node_MAP;
00158 typedef std::map<const Node*, size_t > Node2SizeT_MAP;
00159 typedef std::map<const Node*, int > Node2Int_MAP;
00160 typedef std::map< size_t, const Node* > SizeT2Node_MAP;
00161 #endif
00162
00163 protected:
00164
00166 using LT_MinimaSet::vMinima;
00168 using LT_MinimaSet::mfeIndex;
00170 using LT_MinimaSet::sorted;
00171
00173 double maxMergeBarrier;
00175 Node* root;
00177 Min2Node_MAP min2node;
00179 size_t numOfLeaves;
00180
00181 public:
00182
00184 LT_BarrierTree( const double maxMergeBarrier = 0.0 );
00185
00187 LT_BarrierTree( const LT_BarrierTree& toCopy );
00188
00190 virtual ~LT_BarrierTree();
00191
00192
00194
00200 virtual
00201 bool
00202 addSaddle(const size_t i, const size_t j, const State* const s);
00203
00209 virtual
00210 bool
00211 addSaddle(const State* const m_i, const State* const m_j, const State* const s);
00212
00219 virtual
00220 const size_t
00221 addMin(const State* const m);
00222
00237 virtual
00238 double
00239 getDistance(const LandscapeTopology* const lt) const;
00240
00243 virtual
00244 void
00245 clear();
00246
00251 virtual
00252 void
00253 write( std::ostream & out,
00254 const bool writeGraph = false ) const;
00255
00265 virtual
00266 std::pair<int,std::string>
00267 read( std::istream & in,
00268 const State * const templateState );
00269
00270
00275 bool
00276 isForest( void ) const;
00277
00280 size_t
00281 getNumOfTrees( void ) const;
00282
00286 size_t
00287 getNumOfLeaves( void ) const;
00288
00292 virtual
00293 LT_BarrierTree&
00294 operator = ( const LT_BarrierTree& toCopy );
00295
00299 virtual
00300 LT_BarrierTree&
00301 operator = ( const LT_MinimaSet& toCopy );
00302
00303
00309 virtual
00310 const State*
00311 getBarrier( const size_t m1, const size_t m2 ) const;
00312
00313
00320 virtual
00321 const State*
00322 getBarrier( const State* const m1, const State* const m2 ) const;
00323
00324
00325 protected:
00326
00332 Node*
00333 getHighestParentLEQ( Node* child, const double maxEnergy );
00334
00341 const Node*
00342 getHighestParentLEQ( const Node* child, const double maxEnergy ) const;
00343
00347 Node*
00348 mergeSubTrees( Node* t1, Node* t2 );
00349
00354 Node*
00355 getLCA( Node* n1, Node* n2 );
00356
00362 const Node*
00363 getLCA( const Node* n1, const Node* n2 ) const;
00364
00370 Node*
00371 checkIfObsolete( Node* n );
00372
00373 public:
00374
00391 void
00392 write_PStree( std::ostream& out, const size_t maxLeaves2print = UINT_MAX ) ;
00393
00394 protected:
00395
00399 class nodeT {
00400 public:
00401 nodeT() : height(0.0), saddle_height(0.0), father(INT_MAX), label(NULL) {}
00402 float height;
00403 float saddle_height;
00404 int father;
00405 char *label;
00406 };
00407
00411 class linkT {
00412 public:
00413 linkT() : x(0), next(NULL) {}
00414 int x;
00415 linkT *next;
00416 };
00417
00427 static void PS_tree_plot( std::ostream& out
00428 , const std::vector<nodeT> &nodes
00429 );
00430
00433 class cmp_saddle {
00434 public:
00436 cmp_saddle(const std::vector<nodeT> *leaves_) : leaves(leaves_) {}
00439 const std::vector<nodeT> *leaves;
00445 bool operator() (int A,int B);
00446 };
00447
00448 };
00449
00450 }
00451
00452
00453
00454
00455 #include "ell/LT_BarrierTree.icc"
00456
00457
00458
00459 #endif