MTK++ Latest version: 0.2.0

gaIndividual.h
Go to the documentation of this file.
00001 
00035 #ifndef GAINDIVIDUAL_H
00036 #define GAINDIVIDUAL_H
00037 
00038 #include <iostream>
00039 #include <string>
00040 #include <vector>
00041 
00042 #include "Utils/constants.h"
00043 
00044 namespace MTKpp
00045 {
00046 
00047 class gaPopulation;
00048 class gaChromosome;
00049 
00050 // ============================================================
00051 // Class : gaIndividual()
00052 // ------------------------------------------------------------
00060 // ============================================================
00061 
00062 class gaIndividual
00063 {
00064 public:
00065 
00070     gaIndividual(gaPopulation *parent = 0);
00071 
00077     gaIndividual(gaIndividual* rhs, gaPopulation *parent);
00078 
00080     virtual ~gaIndividual();
00081 
00086     gaChromosome* addChromosome();
00087 
00093     gaChromosome* addChromosome(gaChromosome* chr);
00094 
00099     void delChromosome(gaChromosome* chr);
00100 
00108     gaChromosome* getChromosome(int n, bool id, bool index);
00109 
00113     void initialize();
00114 
00119     double getAbsValue();
00120 
00126     bool compare(gaIndividual* rhs);
00127 
00128     //bool operator<(const gaIndividual* rhs);
00129     //bool operator==(const gaIndividual* rhs);
00130 
00139     static bool less(const gaIndividual *lhs, const gaIndividual *rhs)
00140     {
00141         return lhs->itsFitness < rhs->itsFitness;
00142     }
00143 
00152     static bool greater(const gaIndividual *lhs, const gaIndividual *rhs)
00153     {
00154         return lhs->itsFitness > rhs->itsFitness;
00155     }
00156 
00160     void printToScreen();
00161 
00162     //---------------//
00163     // - GET / SET - //
00164     //---------------//
00165 
00170     void setId(int id);
00171 
00176     int getId();
00177 
00182     void setName(std::string name);
00183 
00188     std::string getName();
00189 
00194     void setFitness(double f);
00195 
00200     double getFitness();
00201 
00206     void setEvaluate(bool b);
00207 
00212     bool getEvaluate();
00213 
00218     gaPopulation* getParent();
00219 
00224     int getNumChromosomes();
00225 
00230     std::vector<double> getGeneticInformation();
00231 
00238     void setGene(int chr, int gen, gaIndividual* ind);
00239 
00245     void mutateGene(int chr, int gen);
00246 
00253     void averageGene(int chr, int gen, gaIndividual* ind);
00254 
00259     void addParent(std::string p);
00260 
00265     std::vector<std::string> getParents();
00266 
00271     void addPartner(std::string partnerName);
00272 
00277     std::vector<std::string> getPartners();
00278 
00283     int numPartners();
00284 
00290     int mated(std::string partnerName);
00291 
00292 protected:
00293 
00295     typedef std::vector<gaChromosome*>::iterator chromosomeIterator;
00296 
00298     std::vector<gaChromosome*>    itsChromosomeList;
00299 
00301     gaPopulation*                 pParent;
00302 
00304     gaChromosome*                 pGaChromosome;
00305 
00307     int                           itsId;
00308 
00310     std::string                   itsName;
00311 
00313     double                        abs_value;
00314 
00316     double                        itsFitness;
00317 
00319     bool                          bEvaluate;
00320 
00322     std::vector<std::string>      itsPartners;
00323 
00325     std::vector<std::string>      itsParents;
00326 
00327 };
00328 
00329 } // MTKpp namespace
00330 
00331 #endif // GAINDIVIDUAL_H

Generated on Fri Dec 23 2011 09:28:50 for MTK++ by Doxygen 1.7.5.1