00001
00007 #ifndef _Population_h
00008 #define _Population_h
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "FunctionBase.h"
00019 #include "PointWithValue.h"
00020
00021
00022
00023
00024 #define NOT_CHOSEN -1
00025
00026 class Population
00027 {
00028 public:
00029
00030
00031 typedef std::vector<PointWithValue> ChromosomeContainer;
00032 typedef PointWithValue ChromosomeType;
00033
00038 Population(const FunctionBase& rFunction,
00039 unsigned numberOfChromosomes,
00040 const ColumnVector& rangeMinBounds,
00041 const ColumnVector& rangeMaxBounds);
00042
00047 Population(const Population& from);
00048
00051 ~Population(void);
00052
00053
00054
00055 PointWithValue& operator[](size_t index);
00056
00057
00058
00059 void Generate( size_t numberOfChromosomes,
00060 const ColumnVector& rangeMinBounds,
00061 const ColumnVector& rangeMaxBounds);
00062
00063 void CalculateGenerationFitness();
00064
00065 void ReevaluateChromosome(size_t index);
00066
00067 void GatherInfo(bool findBest = true);
00068
00069
00070
00071 const PointWithValue& Best() const;
00072
00073 size_t BestIndex() const;
00074
00075 size_t Size() const;
00076
00077 size_t DesiredSize() const;
00078
00079 void AddChromosome(const ColumnVector& newChromosome);
00080
00081 void Erase(size_t index);
00082
00083
00084
00085 ColumnVector AverageChromosome() const;
00086 double AverageValue() const;
00087
00088 double ChromosomeStandardDeviation() const;
00089 double ValueStandardDeviation() const;
00090
00091 protected:
00092 private:
00093
00094 void FindBest();
00095 void CalculateAverages();
00096 void CalculateDeviations();
00097
00098
00099
00100 const FunctionBase& mFunction;
00101
00102 ChromosomeContainer mChromosomes;
00103 size_t mDesiredSize;
00104 int mBestIndex;
00105
00106 ColumnVector mAverageChromosome;
00107 double mAverageValue;
00108 double mChromosomeStandardDeviation;
00109 double mValueStandardDeviation;
00110
00111 };
00112
00113
00114
00115
00116
00117
00118
00119 #endif // _Population_h