00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef GENOTYPE_H
00021 #define GENOTYPE_H
00022
00023 #include "gaconfig.h"
00024 #include "parametersettable.h"
00025 #include <QString>
00026 #include <QVector>
00027
00028 namespace farsa {
00029
00038 class FARSA_GA_API Genotype : public ParameterSettableWithConfigureFunction {
00039 public:
00043 Genotype( unsigned int size = 0 );
00045 virtual ~Genotype();
00047 Genotype( QString, bool compressed=false );
00049 Genotype( const Genotype& genotype );
00055 virtual Genotype& operator=( const Genotype& genotype );
00057 void assign( const Genotype* genotype );
00059 virtual Genotype* clone() const;
00061 unsigned int size() const;
00065 void setFitness( double value );
00069 double fitness() const;
00076 void setObjective( int i, double value );
00080 double objective( int i ) const;
00084 int numOfObjectives() const;
00093 bool dominatedBy( const Genotype* genotype );
00103 void setRank( double rank );
00105 double rank() const;
00107 bool bit( unsigned int i ) const;
00109 void set( unsigned int i );
00111 void unset( unsigned int i );
00113 void toggle( unsigned int i );
00115 QString notes() const;
00117 void setNotes( QString notes );
00119 int hammingDistance( const Genotype* );
00121 virtual void randomize();
00123 QString toString() const;
00125 void fromString( QString );
00127 QString toCompressedString() const;
00131 bool fromCompressedString( QString str );
00144 unsigned int extractUInt( unsigned int startPos, unsigned int stopPos );
00151 void insertUInt( unsigned int value, unsigned int startPos, unsigned int stopPos );
00152
00157 virtual unsigned int geneToBitIndex( unsigned int gene ) const;
00162 virtual unsigned int bitToGeneIndex( unsigned int bit ) const;
00163
00170 virtual void configure( ConfigurationParameters& params, QString prefix );
00177 virtual void save( ConfigurationParameters& params, QString prefix );
00179 static void describe( QString type );
00180
00182 static bool rankGreaterThanComparator( const Genotype *g1, const Genotype *g2 ) {
00183 return (g1->rank() > g2->rank());
00184 };
00186 class nObjectiveGreaterThanComparator {
00187 public:
00191 bool operator()( const Genotype* g1, const Genotype* g2 ) {
00192 return g1->objective( objectiveToCompare ) > g2->objective( objectiveToCompare );
00193 };
00194 int objectiveToCompare;
00195 };
00196
00197 protected:
00199 unsigned char* data;
00201 unsigned int sizev;
00203 unsigned int allocated;
00205 QVector<double> fitnessv;
00207 double rankv;
00209 QString notesv;
00211 void copyDataFrom( Genotype* source );
00212
00218 void resize( unsigned int newsize );
00219 };
00220
00221 }
00222
00223 #endif