Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-19 09:09:48

0001 #ifndef ATOOLS_Math_Cluster_Algorithm_H
0002 #define ATOOLS_Math_Cluster_Algorithm_H
0003 
0004 #include <vector>
0005 
0006 namespace ATOOLS {
0007 
0008   struct cs {
0009 
0010     enum code {
0011       num  = 0,
0012       dist = 1
0013     };
0014 
0015   };// end of struct cs
0016 
0017   template <class PointType,class MeasureType,class RecombinationType>
0018   class Cluster_Algorithm {
0019   public:
0020 
0021     typedef PointType         Point_Type;
0022     typedef MeasureType       Measure_Type;
0023     typedef RecombinationType Recombination_Type;
0024 
0025     typedef std::vector<Point_Type> Point_Vector;
0026     typedef std::vector<std::size_t>     Size_Vector;
0027     typedef std::vector<int>        Int_Vector;
0028 
0029     typedef std::vector<double>        Double_Vector;
0030     typedef std::vector<Double_Vector> Double_Matrix;
0031 
0032   private:
0033 
0034     Point_Vector m_p, m_lp, m_sp;
0035     Size_Vector  m_i;
0036     Int_Vector   m_j;
0037     std::size_t  m_n, m_imin, m_jmin;
0038 
0039     Double_Matrix m_d;
0040     Double_Vector m_r;
0041     double        m_dmin;
0042 
0043     Measure_Type       m_measure;
0044     Recombination_Type m_recom;
0045 
0046     bool m_recalc;
0047 
0048     inline void SetDMin(const std::size_t &i, const std::size_t &j,const double &dij) 
0049     {
0050       if (dij<m_dmin) {
0051     m_dmin=dij;
0052     m_imin=i;
0053     m_jmin=j;
0054       }
0055     }
0056 
0057     bool ArrangePoints();
0058 
0059   public:
0060 
0061     // constructor
0062     Cluster_Algorithm();
0063 
0064     // member functions
0065     bool Cluster(const double &crit,const cs::code &code=cs::dist);
0066 
0067     // inline functions
0068     inline void SetPoints(const Point_Vector &p)   { m_sp=m_p=p; }
0069     inline void SetClusters(const Point_Vector &p) { m_p=p;      }
0070 
0071     inline void SetRecalc(const bool &recalc) { m_recalc=recalc; }
0072 
0073     inline bool Recalc() const { return m_recalc; }
0074 
0075     inline Measure_Type       &Measure()       { return m_measure; }
0076     inline Recombination_Type &Recombination() { return m_recom;   }
0077 
0078     inline const Point_Vector  &Points() const    { return m_sp; }
0079     inline const Point_Vector  &Clusters() const  { return m_p;  }
0080     inline const Point_Vector  &Losts() const     { return m_lp; }
0081     inline const Int_Vector    &Positions() const { return m_j;  }
0082     inline const Double_Vector &DMins() const     { return m_r;  }
0083 
0084     inline std::size_t NClusters() const { return m_n;    }
0085     inline double DMin() const           { return m_dmin; }
0086 
0087     inline const Size_Vector &CPos() const { return m_i; }
0088 
0089   };// end of class Cluster
0090 
0091 }// end of namespace ATOOLS
0092 
0093 #endif