ga/include/core/genome.h

00001 /********************************************************************************
00002  *  FARSA Genetic Algorithm Library                                             *
00003  *  Copyright (C) 2007-2008 Gianluca Massera <emmegian@yahoo.it>                *
00004  *                                                                              *
00005  *  This program is free software; you can redistribute it and/or modify        *
00006  *  it under the terms of the GNU General Public License as published by        *
00007  *  the Free Software Foundation; either version 2 of the License, or           *
00008  *  (at your option) any later version.                                         *
00009  *                                                                              *
00010  *  This program is distributed in the hope that it will be useful,             *
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of              *
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               *
00013  *  GNU General Public License for more details.                                *
00014  *                                                                              *
00015  *  You should have received a copy of the GNU General Public License           *
00016  *  along with this program; if not, write to the Free Software                 *
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA  *
00018  ********************************************************************************/
00019 
00020 #ifndef GENOME_H
00021 #define GENOME_H
00022 
00023 #include "gaconfig.h"
00024 #include "parametersettable.h"
00025 #include "core/genotype.h"
00026 #include <QVector>
00027 
00028 namespace farsa {
00029 
00040 class FARSA_GA_API Genome : public ParameterSettableWithConfigureFunction {
00041 public:
00043     Genome();
00048     Genome( unsigned int numGenotype, unsigned int numBits );
00055     Genome( unsigned int numGenotype, const Genotype* prototype );
00057     Genome( const Genome& genome );
00062     ~Genome();
00064     Genome& operator=( const Genome& right );
00071     virtual void configure( ConfigurationParameters& params, QString prefix );
00078     virtual void save( ConfigurationParameters& params, QString prefix );
00080     static void describe( QString type );
00081 
00083     unsigned int size() const;
00087     void clearAll();
00089     void append( const Genotype* );
00091     Genotype* at( unsigned int i );
00093     const Genotype* at( unsigned int i ) const;
00095     Genotype* last();
00097     const Genotype* last() const;
00101     unsigned int find( const Genotype* g );
00103     void set( unsigned int i, Genotype* g );
00105     const Genotype* operator[]( unsigned int i ) const;
00107     Genotype* operator[]( unsigned int i );
00109     Genotype* prototypeGenotype() {
00110         return prototype;
00111     };
00113     void randomize();
00115     QVector<Genotype*>::iterator begin() {
00116         return data.begin();
00117     };
00119     QVector<Genotype*>::const_iterator begin() const {
00120         return data.begin();
00121     };
00123     QVector<Genotype*>::iterator end() {
00124         return data.end();
00125     };
00127     QVector<Genotype*>::const_iterator end() const {
00128         return data.end();
00129     };
00130 
00131 private:
00133     QVector<Genotype*> data;
00135     Genotype* prototype;
00136 };
00137 
00138 } // end namespace farsa
00139 
00140 #endif