OBOE 0.1
|
00001 // Copyright (c) 2004-2007 University of Geneva, HEC, Logilab 00002 // 00003 // OBOE is published under the Common Public License. 00004 // 00005 // Authors : 00006 // Nidhi Sawhney <nsawhney@yahoo.com> 00007 // The OBOE team 00008 // 00009 00010 #ifndef ACCPM_VECTOR_H 00011 #define ACCPM_VECTOR_H 00012 #include "AccpmDefs.h" 00013 #include <vector> 00014 #include "lavd.h" 00015 00016 typedef double Real; 00017 typedef LaVectorDouble RealVector; 00018 typedef std::vector<Real> StdRealVector; 00019 00020 #ifdef SERIALIZATION 00021 #include <boost/archive/text_iarchive.hpp> 00022 #include <boost/archive/text_oarchive.hpp> 00023 #include <boost/serialization/base_object.hpp> 00024 #include <boost/serialization/split_member.hpp> 00025 #endif 00026 00035 namespace Accpm 00036 { 00037 00043 class AccpmVector : public RealVector { 00044 00045 #ifdef SERIALIZATION 00046 friend class boost::serialization::access; 00047 template<class Archive> 00048 void save(Archive &ar, const unsigned int file_version) const 00049 { 00050 int n = size(); 00051 ar & n; 00052 for (int i = 0; i < size(); ++i) { 00053 ar & *(addr() + i); 00054 } 00055 } 00056 00057 template<class Archive> 00058 void load(Archive &ar, const unsigned int file_version) 00059 { 00060 int n; 00061 ar & n; 00062 resize(n, 1); 00063 for (int i = 0; i < n; ++i) { 00064 ar & *(addr() + i); 00065 } 00066 } 00067 BOOST_SERIALIZATION_SPLIT_MEMBER() 00068 #endif 00069 00070 public: 00071 AccpmVector(); 00072 AccpmVector(int n); 00073 AccpmVector(double* v, int n); 00074 AccpmVector(const LaGenMatDouble &s); 00075 virtual ~AccpmVector() {}; 00076 00077 AccpmVector &operator=(double s); 00078 AccpmVector& operator=(const LaGenMatDouble &s); 00079 bool operator==(const AccpmVector &v) const; 00080 void copy(const StdRealVector &v1); 00081 void append(const AccpmVector &v); 00082 void append(const double entry); 00083 int deleteElem(int id); 00084 void negate(); 00085 void invert(); 00086 double min(int *index = 0) const; 00087 double max(int *index = 0) const; 00091 void times(const AccpmVector &v); 00095 void rdivide(const AccpmVector &v); 00096 double sum() const; 00097 }; 00098 00099 struct ltvector 00100 { 00101 bool findFirstSmallerIndex(const AccpmVector *v1, const AccpmVector *v2) const 00102 { 00103 for (int i = 0; i < v1->size(); ++i) { 00104 if (DBL_LT((*v1)(i), (*v2)(i))) { 00105 return true; 00106 } 00107 if (DBL_LT((*v2)(i), (*v1)(i))) { 00108 return false; 00109 } 00110 } 00111 return false; 00112 } 00113 00114 bool operator()(const AccpmVector *v1, const AccpmVector *v2) const 00115 { 00116 int v1s = v1->size(); 00117 int v2s = v2->size(); 00118 00119 if (v1s < v2s) { 00120 return true; 00121 } 00122 if (v1s > v2s) { 00123 return false; 00124 } 00125 /* 00126 double v1Value = v1->sum(); 00127 double v2Value = v2->sum(); 00128 if (DBL_LT(v1Value, v2Value)) { 00129 return true; 00130 } 00131 if (DBL_GT(v1Value, v2Value)) { 00132 return false; 00133 } 00134 */ 00135 return findFirstSmallerIndex(v1, v2); 00136 } 00137 }; 00138 } 00139 00140 #endif