home *** CD-ROM | disk | FTP | other *** search
/ AI Game Programming Wisdom / AIGameProgrammingWisdom.iso / SourceCode / 11 Learning / 01 Manslow / GPExample / CGP.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-10  |  1.6 KB  |  65 lines

  1. //GPExample
  2. //Copyright John Manslow
  3. //29/09/2001
  4.  
  5. #ifndef _CGP_
  6. #define _CGP_
  7.  
  8. //Forward declaration of base class for GP program node
  9. class CGPNode;
  10.  
  11. class CGP
  12. {
  13. public:
  14.  
  15.     CGP(unsigned long);            //Population size
  16.     ~CGP();
  17.  
  18.     //Returns a pointer to a new randomly created program
  19.     CGPNode *pGetRandomSubtree(void);
  20.  
  21.     //Mutates the program passed in the function's parameter list
  22.     CGPNode* pMutate(CGPNode *);
  23.  
  24.     //Creates a new program by applying a crossover operator to the two program specified (by their locations
  25.     //in the population) in the parameter list
  26.     CGPNode *pCross(unsigned long,unsigned long);
  27.  
  28.     //Returns a pointer to a progarm so that its fitness can be evaluated
  29.     CGPNode *pGetChromosomeForEvaluation(void);
  30.  
  31.     //Sets the fitness of the working program to the fitness provided
  32.     void SetFitness(double);
  33.  
  34.     //Returns a pointer to the best program found so far
  35.     CGPNode *pGetBestChromosome(void);
  36.  
  37.     //Returns the performance of the best program discovered so far
  38.     double dGetBestPerformance(void);
  39.  
  40. private:
  41.  
  42.     //The population size
  43.     unsigned long ulPopulationSize;
  44.  
  45.     //The number of fitness evaluations made so far
  46.     unsigned long ulIteration;
  47.  
  48.     //The program whos fitness is currently being evaluated
  49.     unsigned long ulWorkingTree;
  50.  
  51.     //The population of programs
  52.     CGPNode **pProgram;
  53.     //And their fitnesses
  54.     double *pdFitnesses;
  55.  
  56.     //Search parameters
  57.     double dMutationProbability;
  58.     double dCrossoverProbability;
  59.  
  60.     //A copy of the best program discovered so far and its performance
  61.     CGPNode *pFittestTree;
  62.     double dBestFitness;
  63. };
  64.  
  65. #endif