GeneralObjective.h

Go to the documentation of this file.
00001 #ifndef CGENERALOBJECTIVE_H
00002 #define CGENERALOBJECTIVE_H
00003 #include "gentypes.h"
00004 #include <string>
00005 
00006 namespace gplib
00007   {
00008     /** \addtogroup gainv Genetic algorithm optimization */
00009     /* @{ */
00010     //! The basic object for any objective function, mainly an interface class and some storage
00011     /*! All objective functions should be derived from this class to be usable with the genetic algorithms.
00012      * Also the linearized classes use this base class to access objective functions.
00013      * The main functionality is implemented in the three functions PreParallel, SafeParallel and PostParallel.
00014      * This division is ncessary to account for various types of computations in a parallel environment.
00015      * In addition derived classes have to implement the clone function and a copy constructor and operator.
00016      */
00017     class GeneralObjective
00018       {
00019     private:
00020       //! when calculating the misfit the difference is taken to the power of this exponent (d_i - s_i)^FitExponent
00021       int FitExponent;
00022       //! the single RMS value
00023       double RMS;
00024       //! The levmar library wants the whole misfit vector
00025       tmisfit Misfit;
00026       //! The current synthetic data for the levmar algorithm
00027       tdata SynthData;
00028       //! Some forward calculations involve writing files, we use ParallelId as a unique identifier for parallel calculations
00029       std::string ParallelId;
00030     protected:
00031       double CalcMisfit(const double measured, const double predicted,
00032           const double measerror, const double errorlevel, const int index);
00033       void SetRMS(const double x)
00034         {
00035           RMS = x;
00036         }
00037       //! Only derived classes can write access the Misfit
00038       tmisfit &SetMisfit()
00039         {
00040           return Misfit;
00041         }
00042       void SetMisfit(const tmisfit &LocalMisfit)
00043         {
00044           Misfit = LocalMisfit;
00045         }
00046       //! Only derived classes can write access the Synthetic data
00047       tdata &SetSynthData()
00048         {
00049           return SynthData;
00050         }
00051       ;
00052       void SetSynthData(const tdata &LocalSynthData)
00053         {
00054           SynthData = LocalSynthData;
00055         }
00056     public:
00057       //! Set the Fit exponent
00058       void SetFitExponent(const int x)
00059         {
00060           FitExponent = x;
00061         }
00062       //! Get the Fit exponent
00063       int GetFitExponent()
00064         {
00065           return FitExponent;
00066         }
00067       //! Get the current RMS
00068       double GetRMS()
00069         {
00070           return RMS;
00071         }
00072       //! Derived classes need to read the ParallelId for their forward calculations
00073       const std::string &GetParallelID()
00074         {
00075           return ParallelId;
00076         }
00077       //! We need to set the parallel ID outside the Objective function object
00078       void SetParallelID(const std::string &s)
00079         {
00080           ParallelId = s;
00081         }
00082       //! Return the misfit vector
00083       const tmisfit &GetMisfit()
00084         {
00085           return Misfit;
00086         }
00087       //! Return the current synthetic data
00088       const tdata &GetSynthData()
00089         {
00090           return SynthData;
00091         }
00092       //! We need clone and create for building an array of derived objects, see FAQ lite 20.8, the return type depends on the derived class
00093       virtual GeneralObjective *clone() const = 0;
00094       //! Some operations cannot be done in parallel, these are done before
00095       virtual void PreParallel(const ttranscribed &member);
00096       //! Some operations cannot be done in parallel, these are done after, returns the misfit value
00097       virtual double PostParallel(const ttranscribed &member) = 0;
00098       //! The core performance calculation, has to be safe to be done in parallel
00099       virtual void SafeParallel(const ttranscribed &member);
00100       //! For serial execution CalcPerformance calls the three Parallel functions for more convenient use
00101       double CalcPerformance(const ttranscribed &member);
00102       GeneralObjective();
00103       GeneralObjective(const GeneralObjective &Old);
00104       GeneralObjective &operator=(const GeneralObjective &source);
00105       virtual ~GeneralObjective();
00106       };
00107   /* @} */
00108   }
00109 #endif // CGENERALOBJECTIVE_H

Generated on Tue May 4 16:52:14 2010 for GPLIB++ by  doxygen 1.5.8