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

Generated on Fri Jul 4 15:30:20 2008 for GPLIB++ by  doxygen 1.5.5