Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

individual.h

Go to the documentation of this file.
00001 
00002 #ifndef __INDIVIDUAL_H__
00003 #define __INDIVIDUAL_H__
00004 
00005 #include "nhp/genetics.h"
00006 #include <magic/mmath.h>
00007 #include <magic/mmap.h>
00008 
00009 //Externals
00010 class EAEnvironment;
00011 class SimplePopulation;
00012 class SelectionMatrix;
00013 class Selector;
00014 class SelectionPrms;
00015 
00016 
00017 
00019 //                                                                           //
00020 //               ---           | o       o     |             |               //
00021 //                |    _       |               |        ___  |               //
00022 //                |  |/ \   ---| | |   | |  ---| |   |  ___| |               //
00023 //                |  |   | (   | |  \ /  | (   | |   | (   | |               //
00024 //               _|_ |   |  ---| |   V   |  ---|  \__!  \__| |               //
00025 //                                                                           //
00027 
00033 class Individual : public Comparable {
00034     decl_dynamic (Individual);
00035   public:
00036 
00037                             Individual      ();
00038     explicit                Individual      (const Individual& prototype);
00039 
00042     explicit                Individual      (const Genome& prototype);
00043 
00044     virtual                 ~Individual     ();
00045     
00052     void                    incarnate       (bool init);
00053 
00055     // Passthroughs to feature map
00056     
00058     void                    set             (const String& key, Object* val) {
00059         mFeatures.set (key, val);
00060     }
00061 
00063     void                    remove          (const String& key) {mFeatures.remove(key);}
00064     
00066     Object&                 operator[]		(const String& key) {return mFeatures[key];}
00067 
00069     const Object&           operator[]		(const String& key) const {return mFeatures[key];}
00070 
00071     Object*                 getFeature      (const String& key) {return mFeatures.getvp(key);}
00072     const Object*           getFeature      (const String& key) const {return mFeatures.getp(key);}
00073 
00077     const Map<String,Object>&   features    () const {return mFeatures;}
00078     
00080     // Evaluation of the fitness
00081     
00082     double                  evaluate        (EAEnvironment& envr, bool force=false);
00083 
00084     // Lets the individual to give it's preference for the given individual
00085     //double                    select          (const RefArray<Individual>& opop, int j) const;
00086 
00087     // We want to be comparable by our fitness to allow sorting
00088     int                     compare         (const Comparable& other) const;
00089 
00090     // Returns the evaluated fitness of the phenotype
00091     double                  getfitness      () const {return fitness;}
00092 
00093     // Returns the number of evaluations the calculated fitness has
00094     // been averaged over
00095     int                     averaged_over   () const {return avg_over;}
00096 
00097     // Joins the fitness with a (practically) identical other phenotype
00098     void                    joinfitness     (const Individual& other);
00099 
00100     // Reset fitness and it's averaging
00101     void                    resetFitness    () {fitness=0; avg_over=0;}
00102     
00103     // Feature shortcuts
00104 
00108     int                     getage          () const {return age;}
00109 
00112     const Selector&         selector        () const {return *mpSelector;}
00113 
00119     void                    setSelector     (const SelectionPrms& templ);
00120     
00127     //double                    select          (const SelectionMatrix& selmat,
00128     //                                       int self_i, int other_j) const;
00129 
00130     // Passthroughs to Genome
00131 
00133     bool                execute             (const GeneticMsg& msg) const {return genome.execute(msg);}
00135     void                init                () {genome.init();}
00137     bool                pointMutate         (const MutationRate& k);
00139     const Genstruct*    getGene             (const GeneticID& n) const {return genome.getGene(n);}
00141     static void         addGenesTo          (Genome& g, const StringMap& params);
00143     void                addking             () {genome.addking();}
00145     int                 getkings            () const {return genome.getkings();}
00147     void                recombine           (const Individual& a, const Individual& b);
00149     double              equality            (const Individual& other) const {
00150         return genome.equality (other.genome);
00151     }
00152     
00154     void                    print           (TextOStream& out) const;
00155 
00157     virtual DataOStream&    operator>>		(DataOStream& out) const;
00158 
00160     virtual void            check           () const;
00161 
00162   private:
00164     int                     operator==      (const Comparable& other) const {FORBIDDEN}
00165 
00167     void                    grow_older      ();
00168 
00171     Map<String,Object>      mFeatures;
00172 
00174     mutable double          fitness;
00175 
00177     mutable int             avg_over;
00178 
00180     int                     age;
00181 
00183     Selector*               mpSelector;
00184 
00186     Genome                  genome;
00187 
00188     Individual& operator= (const Individual& other) {FORBIDDEN; return *this;} // Prevent copying
00189 };
00190 
00191 #endif
00192 

Generated on Thu Feb 10 20:12:00 2005 for NeHeP by doxygen1.2.18