00001 #ifndef EVOLVER_H
00002 #define EVOLVER_H
00003
00004 #include <armadillo>
00005
00006 using namespace arma;
00007
00013 class Evolver
00014 {
00015 public:
00016 Evolver();
00017 Evolver(int nGenes, int nIndividuals, int nPopulations);
00018
00019 void setPopulationData(int nGenes, int nIndividuals, int nPopulations);
00020
00021 void evolve(int nSteps, int populationMatchingPeriod);
00022
00023 void setRescaleLimits(double low, double high) {
00024 lowScaleLimit = low;
00025 highScaleLimit = high;
00026 initialLowScaleLimit = low;
00027 initialHighScaleLimit = high;
00028 rescale();
00029 }
00030
00031 void setRescaleCycles(int rescaleCycles) {
00032 this->rescaleCycles = rescaleCycles;
00033 }
00034
00035 vec allBestGenes;
00036
00037 ~Evolver();
00038 void rescale();
00039 protected:
00040 virtual double fitness(vec &coefficients, int population, int individual) = 0;
00041 void updateBest();
00042
00043
00044
00045
00046 int nIndividuals;
00047 int nGenes;
00048 int nPopulations;
00049
00050
00051 int cycle;
00052
00053 long *idum;
00054
00055
00056
00057
00058 double scale;
00059 double lowScaleLimit;
00060 double highScaleLimit;
00061
00062 double initialLowScaleLimit;
00063 double initialHighScaleLimit;
00064
00065 double rescalePrecisionLimit;
00066
00067
00068
00069 vec **populations;
00070
00071
00072
00073 uvec *bestIndices;
00074 vec *values;
00075
00076 double allBestValue;
00077 int allBestIndex;
00078 int allBestPopulationIndex;
00079
00080 int rescaleCycles;
00081
00082
00083 int cyclesSinceLastImprovement;
00084 int cyclesSinceLastRescale;
00085
00086 double lastWorkingScale;
00087
00088 bool veryFirst;
00089 };
00090
00091 #endif // EVOLVER_H