vtf-logo

Simplex.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00008 // CONTINUE: Write tests for the diameter functionality.
00009 
00010 #if !defined(__numerical_Simplex_h__)
00011 #define __numerical_Simplex_h__
00012 
00013 // If we are debugging the whole numerical package.
00014 #if defined(DEBUG_numerical) && !defined(DEBUG_Simplex)
00015 #define DEBUG_Simplex
00016 #endif
00017 
00018 #ifdef DEBUG_Simplex
00019 // Debug the base class.
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   // Private types
00046   //
00047 
00048   typedef Opt<N,Function,T,Point> Base;
00049 
00050 public:
00051 
00052   //
00053   // Public types.
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   // Private types.
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   // Member data that the user can set.
00079   //
00080 
00081   // The fractional error tolerance.
00082   number_type _tolerance;
00083 
00084   // The initial offset size used to generate the simplex.
00085   number_type _offset;
00086 
00087   //
00088   // Other member data.
00089   //
00090 
00091   // The vertices of the simplex.
00092   ads::FixedArray<N+1,point_type> _vertices;
00093 
00094   // The objective function values at the vertices.
00095   ads::FixedArray<N+1,number_type> _values;
00096 
00097   // The sums of the coordinates of the vertices in the simplex.
00098   point_type _coordinate_sums;
00099 
00100   // The diameter of a hypercube that has the same volume as the simplex.
00101   number_type _diameter;
00102 
00103   //
00104   // Not implemented.
00105   //
00106   
00107   // Default constructor not implemented.
00108   Simplex();
00109 
00110   // Copy constructor not implemented.
00111   Simplex(const Simplex&);
00112 
00113   // Assignment operator not implemented.
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   // Inherited from Opt.
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   // Inherited from Opt
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   // New.
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   // Initialize the simplex.
00239   void 
00240   initialize(const point_type& starting_point, const number_type offset);
00241 
00242   // Initialize the simplex.
00243   void 
00244   initialize(const ads::FixedArray<N + 1,point_type>& vertices);
00245 
00246   // Initialize given the vertices of the simplex.
00247   void 
00248   initialize_given_vertices();
00249 
00250   // Sum the coordinates of the vertices.
00251   void
00252   sum_coordinates();
00253 
00254   bool
00255   find_minimum();
00256 
00257   // Move the high point.
00258   /*
00259     Extrapolate by the given factor through the face of the simplex across
00260     from the high point.  Replace the high point if the new point is better.
00261     \param ihi is the index of the high point.
00262     \param factor is the scaling factor on where to move the point.
00263     For example, -1 reflects the point and 0.5 contracts the point.
00264   */
00265   number_type
00266   move_high_point(const int ihi, const number_type factor);
00267 
00268   // Compute the diameter
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

Generated on Fri Aug 24 12:56:05 2007 for Numerical Algorithms Package by  doxygen 1.4.7