00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef _terimber_mst_h_
00029 #define _terimber_mst_h_
00030
00031 #include "base/vector.h"
00032
00033 BEGIN_TERIMBER_NAMESPACE
00034
00035 #pragma pack(4)
00036
00039 typedef _vector< size_t > priority_queue_vec_t;
00040
00043 template < class T >
00044 class priority_queue
00045 {
00046 public:
00048 inline
00049 priority_queue( byte_allocator& all,
00050 size_t N,
00051 const _vector< T >& pred,
00052 size_t dim = 3
00053 );
00055 inline
00056 bool
00057 empty() const;
00059 inline
00060 size_t
00061 size() const;
00063 inline
00064 void
00065 insert( size_t v
00066 );
00068 inline
00069 size_t
00070 getmin();
00072 inline
00073 void
00074 lower( size_t v
00075 );
00076
00077 private:
00079 inline
00080 void
00081 exchange( size_t i,
00082 size_t j
00083 );
00085 inline
00086 void
00087 fixUp( size_t i
00088 );
00090 inline
00091 void
00092 fixDown( size_t k,
00093 size_t N
00094 );
00095
00096 private:
00097 size_t _dim;
00098 size_t _Num;
00099 priority_queue_vec_t _pq;
00100 priority_queue_vec_t _qp;
00101 const _vector< T >& _pred;
00102 };
00103
00106 class mst_edge
00107 {
00108 public:
00110 mst_edge( size_t from,
00111 size_t to,
00112 double distance) :
00113 _from(from),
00114 _to(to),
00115 _distance(distance)
00116 {
00117 }
00119 inline
00120 bool
00121 operator<(const mst_edge& x) const
00122 {
00123 return _from != x._from ? _from < x._from : _to < x._to;
00124 }
00125
00126 size_t _from;
00127 size_t _to;
00128 double _distance;
00129 };
00130
00131
00134 typedef _map< size_t, size_t > mst_head_map_t;
00137 typedef mst_head_map_t::const_iterator mst_head_map_citer_t;
00138
00141 class mst_head_compare_counts
00142 {
00143 public:
00145 inline
00146 bool
00147 operator()( mst_head_map_citer_t x,
00148 mst_head_map_citer_t y
00149 ) const
00150 {
00151 return *x > *y;
00152 }
00153 };
00154
00157 class cluster_info
00158 {
00159 public:
00161 cluster_info( size_t ident,
00162 double distance
00163 ) :
00164 _cluster_ident(ident),
00165 _cluster_distance(distance)
00166 {
00167 }
00168
00169 size_t _cluster_ident;
00170 double _cluster_distance;
00171 };
00172
00175 typedef _vector< mst_edge > mst_vec_t;
00178 typedef _vector< double > mst_dist_t;
00179
00182 template < class T, class N >
00183 class mst
00184 {
00185 public:
00187 mst( const T& container,
00188 const N& notifier,
00189 byte_allocator& all,
00190 byte_allocator& temp
00191 );
00193 inline
00194 const mst_vec_t&
00195 get_mst() const;
00196
00197 private:
00199 void pfs( size_t s,
00200 byte_allocator& tmp
00201 );
00202
00203 private:
00204 const T& _container;
00205 const N& _notifier;
00206 const size_t _length;
00207 mst_dist_t _wt;
00208 mst_vec_t _fr;
00209 mst_vec_t _mst;
00210 };
00211
00214 typedef _list< size_t > cluster_list_t;
00217 typedef _map< size_t, cluster_list_t > cluster_map_t;
00220 typedef _map< mst_edge, cluster_info > cluster_mst_map_t;
00221
00224 template < class T, class N >
00225 class cluster_processor
00226 {
00227 public:
00229 cluster_processor(const T& container,
00230 const N& notifier,
00231 double max_vertex_distance,
00232 double max_cluster_distance,
00233 double avg_cluster_distance
00234 );
00236 inline
00237 const
00238 cluster_map_t&
00239 get_clusters() const;
00240
00241 private:
00243 void
00244 cut( double max_vertex_distance,
00245 double max_cluster_distance,
00246 double avg_cluster_distance
00247 );
00249 inline
00250 double
00251 avg_distance( cluster_map_t::const_iterator citer,
00252 size_t index
00253 ) const;
00254
00255 private:
00256 const T& _container;
00257 const N& _notifier;
00258 cluster_mst_map_t _mst_map;
00259 cluster_map_t _clusters;
00260 byte_allocator _all;
00261 };
00262
00263 #pragma pack()
00264 END_TERIMBER_NAMESPACE
00265
00266 #endif