Go to the documentation of this file.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
00029
00030
00031
00032
00033
00034
00035 #ifndef _partunif_h_
00036 #define _partunif_h_
00037
00038 #include <vector>
00039 #include <string>
00040 #include "parttype.h"
00041
00042
00043 namespace unifexp {
00044
00045
00046
00047
00048
00049
00050
00051
00052 template <class numType>
00053 class partUniform: public partType<numType>
00054 {
00055 public:
00056
00057 std::string name () const;
00058
00059
00060
00061
00062 void create (const mapType<numType> &theMap, int partCount,
00063 const numType &delta);
00064
00065 private:
00066
00067
00068 void fillUniform (int first, int last);
00069
00070 };
00071
00072
00073
00074 template <class numType>
00075 std::string partUniform<numType>::name () const
00076 {
00077 return std::string ("uniform");
00078 }
00079
00080 template <class numType>
00081 void partUniform<numType>::fillUniform (int first, int last)
00082 {
00083 const numType &numFirst = (*this) [first];
00084 const numType &numLast = (*this) [last];
00085 const numType numDiff = (numLast - numFirst) / (last - first);
00086 for (int i = first + 1; i < last; ++ i)
00087 (*this) [i] = numFirst + (i - first) * numDiff;
00088 return;
00089 }
00090
00091 template <class numType>
00092 void partUniform<numType>::create (const mapType<numType> &theMap,
00093 int partCount, const numType &delta)
00094 {
00095 int nCrit = theMap. countCritical ();
00096 if (partCount < 2 * nCrit + 2)
00097 throw "Too small partition requested.";
00098 this -> allocate (partCount);
00099 (*this) [0] = theMap. leftBound ();
00100 (*this) [partCount] = theMap. rightBound ();
00101 numType width = (*this) [partCount] - (*this) [0] -
00102 2 * delta * nCrit;
00103 if (width <= 0)
00104 throw "Too wide critical neighborhood requested.";
00105 int prev = 0;
00106 for (int i = 0; i < nCrit; ++ i)
00107 {
00108 const numType crit = theMap. criticalPoint (i);
00109 const numType left = crit - delta;
00110 const numType right = crit + delta;
00111 if ((left <= (*this) [prev]) ||
00112 ((*this) [partCount] <= right))
00113 {
00114 throw "Too large critical neighborhood requested.";
00115 }
00116 int n = prev + static_cast<int> (partCount / width *
00117 (left - (*this) [prev]));
00118 if (n <= prev)
00119 n = prev + 1;
00120 if (partCount <= n + 1)
00121 throw "Too few partition intervals requested.";
00122 this -> addCritical (n);
00123 (*this) [n] = left;
00124 fillUniform (prev, n);
00125 (*this) [n + 1] = right;
00126 prev = n + 1;
00127 }
00128 fillUniform (prev, partCount);
00129 return;
00130 }
00131
00132
00133 }
00134
00135 #endif // _partunif_h_
00136
00137
00138