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
00010 class EAEnvironment;
00011 class SimplePopulation;
00012 class SelectionMatrix;
00013 class Selector;
00014 class SelectionPrms;
00015
00016
00017
00019
00020
00021
00022
00023
00024
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
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
00081
00082 double evaluate (EAEnvironment& envr, bool force=false);
00083
00084
00085
00086
00087
00088 int compare (const Comparable& other) const;
00089
00090
00091 double getfitness () const {return fitness;}
00092
00093
00094
00095 int averaged_over () const {return avg_over;}
00096
00097
00098 void joinfitness (const Individual& other);
00099
00100
00101 void resetFitness () {fitness=0; avg_over=0;}
00102
00103
00104
00108 int getage () const {return age;}
00109
00112 const Selector& selector () const {return *mpSelector;}
00113
00119 void setSelector (const SelectionPrms& templ);
00120
00127
00128
00129
00130
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;}
00189 };
00190
00191 #endif
00192