00001 00175 #ifndef _NelderMead_h 00176 #define _NelderMead_h 00177 00178 // SYSTEM INCLUDES 00179 // 00180 00181 // PROJECT INCLUDES 00182 // 00183 00184 // LOCAL INCLUDES 00185 // 00186 #include "../DoubleParameter.h" 00187 #include "../Error.h" 00188 #include "../Logger.h" 00189 #include "../Method.h" 00190 #include "../NMStopCondition.h" 00191 #include "../PointWithValue.h" 00192 #include "../ProblemBase.h" 00193 #include "NelderMeadIteration.h" 00194 00195 // FORWARD REFERENCES 00196 // 00197 00198 00199 class NelderMead 00200 : public Method 00201 { 00202 public: 00203 00204 friend class NelderMeadPanel; 00205 friend class NelderMeadIteration; 00206 00207 // LIFECYCLE 00208 00211 ~NelderMead(void); 00212 00213 // OPERATORS 00214 // OPERATIONS 00215 00225 /*NelderMead::Simplex CreateSimplex(const ColumnVector& baseVertex, 00226 double sideLength = 1.0 00227 const FunctionBase& function); 00228 */ 00231 virtual std::auto_ptr<Method> Clone() const; 00232 00233 virtual void UpdateStartingConditions 00234 (const Result* result) const; 00235 00236 virtual void ResetStartingConditions() const; 00237 00238 // ACCESS 00239 00242 virtual const wxString& Name() const; 00243 00246 virtual MethodIdType Id() const; 00247 00250 static MethodIdType ClassId(); 00251 00252 virtual wxString ToString(bool standalone = true) const; 00253 00254 // INQUIRY 00255 00258 virtual bool CanHandle(const ProblemBase* pProblem) 00259 const; 00260 00261 virtual StopConditions AllowedStopConditions() const; 00262 00263 virtual wxString& rName(); 00264 protected: 00265 00270 class Simplex 00271 { 00272 public: 00273 //LIFECYCLE 00274 // 00275 00278 Simplex(); 00279 00284 Simplex(const FunctionBase* function); 00285 00289 Simplex(const ColumnVector& centralPoint, 00290 const DoubleParameter& sideLength, 00291 const FunctionBase* pFunction); 00292 00300 Simplex(const vector<ColumnVector>& startingPoints, 00301 const FunctionBase* function); 00302 00307 Simplex(const NelderMead::Simplex& from); 00308 00311 ~Simplex(){}; 00312 00313 //OPERATORS 00314 // 00315 00316 NelderMead::Simplex& operator=(const NelderMead::Simplex& from); 00317 00318 //OPERATIONS 00319 // 00320 00331 static double Delta1(const DoubleParameter& sideLength, 00332 size_t dimensions); 00333 00334 00345 static double Delta2(const DoubleParameter& sideLength, 00346 size_t dimensions); 00347 00348 00361 const PointWithValue Centroid(size_t firstIndex, 00362 size_t lastIndex) const; 00363 00372 void ShrinkTowardBest(double shrinkageCoefficient); 00373 00381 void SubstituteNewForWorst(const PointWithValue& newPoint); 00382 00383 //ACCESS 00384 // 00392 const PointWithValue& rBest() const; 00393 00401 const PointWithValue& rWorst() const; 00402 00410 const PointWithValue& rNextToWorst() const; 00411 00419 const vector<PointWithValue>& rPoints() const; 00420 00421 //INQUIRY 00422 // 00427 double Circumference() const; 00428 00438 double ValueSpan() const; 00439 00444 size_t Size() const; 00445 00446 protected: 00447 00453 void GenerateVertices(const ColumnVector centralPoint, 00454 const DoubleParameter& sideLength); 00455 00462 void Sort(); 00463 00466 vector<PointWithValue> mPoints; 00469 const FunctionBase* mpFunction; 00470 00471 private: 00472 00473 }; 00474 00477 NelderMead(); 00478 00483 NelderMead(const NelderMead& from); 00484 00485 protected: 00486 00489 DoubleParameter mReflectionCoefficient; 00492 DoubleParameter mExpansionCoefficient; 00495 DoubleParameter mContractionCoefficient; 00498 DoubleParameter mShrinkageCoefficient; 00501 //NelderMead::Simplex mInitialSimplex; 00504 mutable ColumnVector mStartingPoint; 00505 ColumnVector mInitialStartingPoint; 00508 DoubleParameter mSideLength; 00511 double mSimplexRange; 00514 CountedPtr<const NMStopCondition> mcpStopCondition; 00515 00516 private: 00517 00518 virtual std::auto_ptr<Result> Optimize(const ProblemBase& problem) const 00519 throw(OptimizationError); 00520 00523 static wxString mName; 00526 static NelderMead mNelderMead; 00527 00528 }; 00529 00530 // INLINE METHODS 00531 // 00532 00533 // EXTERNAL REFERENCES 00534 // 00535 00536 #endif // _NelderMead_h