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 _partsegm_h_
00036 #define _partsegm_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 partSegmented: 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 partSegmented<numType>::name () const
00076 {
00077 return std::string ("segmented");
00078 }
00079
00080 template <class numType>
00081 void partSegmented<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 partSegmented<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 int prev = 0;
00102 for (int i = 0; i < nCrit; ++ i)
00103 {
00104 int n = partCount / (nCrit + 1) * (i + 1);
00105 this -> addCritical (n);
00106 const numType crit = theMap. criticalPoint (i);
00107 const numType left = crit - delta;
00108 const numType right = crit + delta;
00109 if ((left <= (*this) [prev]) ||
00110 ((*this) [partCount] <= right))
00111 {
00112 throw "Too large critical neighborhood requested.";
00113 }
00114 (*this) [n] = left;
00115 fillUniform (prev, n);
00116 (*this) [n + 1] = right;
00117 prev = n + 1;
00118 }
00119 fillUniform (prev, partCount);
00120 return;
00121 }
00122
00123
00124 }
00125
00126 #endif // _partsegm_h_
00127
00128
00129