evolver/evolver.h
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     // defines the number of individuals in a population
00044     // and the size of the genome of each individual
00045     // read: The number of test functions and coefficients
00046     int nIndividuals;
00047     int nGenes;
00048     int nPopulations;
00049 
00050     // Keep track of the number of cycles
00051     int cycle;
00052 
00053     long *idum;
00054 
00055     // defines the scaling of the coefficients
00056     // and how this is limited. Could be coefficients from 1 to 1e6
00057     // or from 1e3 to 1e4 for example
00058     double scale;
00059     double lowScaleLimit;
00060     double highScaleLimit;
00061 
00062     double initialLowScaleLimit;
00063     double initialHighScaleLimit;
00064     // at what precision should we start calling for rescales?
00065     double rescalePrecisionLimit;
00066 
00067     // holds the populations, which each is a vector of genes
00068     // read: the functions, holding their coefficients
00069     vec **populations;
00070 
00071     // holds the scoreboard information
00072     // which individuals are the best within each population
00073     uvec *bestIndices;
00074     vec *values;
00075 
00076     double allBestValue;
00077     int allBestIndex;
00078     int allBestPopulationIndex;
00079 
00080     int rescaleCycles;
00081 
00082     // holds the number of cycles since last improvement
00083     int cyclesSinceLastImprovement;
00084     int cyclesSinceLastRescale;
00085 
00086     double lastWorkingScale;
00087 
00088     bool veryFirst;
00089 };
00090 
00091 #endif // EVOLVER_H
 All Classes Functions