00001
00002
00008
00009
00010 #if !defined(__numerical_Simplex_h__)
00011 #define __numerical_Simplex_h__
00012
00013
00014 #if defined(DEBUG_numerical) && !defined(DEBUG_Simplex)
00015 #define DEBUG_Simplex
00016 #endif
00017
00018 #ifdef DEBUG_Simplex
00019
00020 #ifndef DEBUG_Opt
00021 #define DEBUG_Opt
00022 #endif
00023 #endif
00024
00025 #include "Opt.h"
00026
00027 #include "../../geom/mesh/simplex/Simplex.h"
00028
00029 BEGIN_NAMESPACE_NUMERICAL
00030
00032
00038 template<int N, class Function, typename T = typename Function::result_type,
00039 typename Point = typename Function::argument_type>
00040 class Simplex :
00041 public Opt<N,Function,T,Point> {
00042 private:
00043
00044
00045
00046
00047
00048 typedef Opt<N,Function,T,Point> Base;
00049
00050 public:
00051
00052
00053
00054
00055
00057 typedef typename Base::function_type function_type;
00058
00060 typedef typename Base::number_type number_type;
00061
00063 typedef typename Base::point_type point_type;
00064
00065 private:
00066
00067
00068
00069
00070
00072 typedef ads::FixedArray<N+1,point_type> point_container;
00073
00075 typedef typename point_container::const_iterator point_const_iterator;
00076
00077
00078
00079
00080
00081
00082 number_type _tolerance;
00083
00084
00085 number_type _offset;
00086
00087
00088
00089
00090
00091
00092 ads::FixedArray<N+1,point_type> _vertices;
00093
00094
00095 ads::FixedArray<N+1,number_type> _values;
00096
00097
00098 point_type _coordinate_sums;
00099
00100
00101 number_type _diameter;
00102
00103
00104
00105
00106
00107
00108 Simplex();
00109
00110
00111 Simplex(const Simplex&);
00112
00113
00114 Simplex&
00115 operator=(const Simplex&);
00116
00117 public:
00118
00119
00124
00125
00127 Simplex(const function_type& function,
00128 const number_type tolerance =
00129 std::sqrt(std::numeric_limits<number_type>::epsilon()),
00130 const number_type offset =
00131 std::pow(std::numeric_limits<number_type>::epsilon(), 0.25),
00132 const int max_function_calls = 10000);
00133
00135 virtual
00136 ~Simplex()
00137 {}
00138
00139
00140
00142
00143
00144
00145
00146
00147
00148 #if 0
00150 static
00151 int
00152 dimension() {
00153 return Base::dimension();
00154 }
00155 #endif
00156
00158 using Base::dimension;
00159
00161 using Base::function;
00162
00164 using Base::max_function_calls;
00165
00167 using Base::num_function_calls;
00168
00169
00170
00172
00173
00175 bool
00176 find_minimum(const point_type& starting_point);
00177
00179 bool
00180 find_minimum(const ads::FixedArray<N + 1,point_type>& vertices);
00181
00183 point_type
00184 minimum_point() const {
00185 return _vertices[0];
00186 }
00187
00189 number_type
00190 minimum_value() const {
00191 return _values[0];
00192 }
00193
00195 number_type
00196 diameter() const {
00197 return _diameter;
00198 }
00199
00200
00201
00203
00204
00205
00206
00207
00208
00210 using Base::set_max_function_calls;
00211
00213 using Base::reset_num_function_calls;
00214
00216 using Base::set_are_checking_function_calls;
00217
00218
00219
00220
00221
00223 void
00224 set_tolerance(const number_type tolerance) {
00225 _tolerance = tolerance;
00226 }
00227
00229 void
00230 set_offset(const number_type offset) {
00231 _offset = offset;
00232 }
00233
00234
00235
00236 private:
00237
00238
00239 void
00240 initialize(const point_type& starting_point, const number_type offset);
00241
00242
00243 void
00244 initialize(const ads::FixedArray<N + 1,point_type>& vertices);
00245
00246
00247 void
00248 initialize_given_vertices();
00249
00250
00251 void
00252 sum_coordinates();
00253
00254 bool
00255 find_minimum();
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265 number_type
00266 move_high_point(const int ihi, const number_type factor);
00267
00268
00269 void
00270 compute_diameter();
00271
00272 protected:
00273
00274
00278
00279
00281
00284 using Base::evaluate_function;
00285
00286
00287
00288 };
00289
00290 END_NAMESPACE_NUMERICAL
00291
00292 #define __Simplex_ipp__
00293 #include "Simplex.ipp"
00294 #undef __Simplex_ipp__
00295
00296 #endif