genome.h
1 /********************************************************************************
2  * FARSA Genetic Algorithm Library *
3  * Copyright (C) 2007-2008 Gianluca Massera <emmegian@yahoo.it> *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the Free Software *
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
18  ********************************************************************************/
19 
20 #ifndef GENOME_H
21 #define GENOME_H
22 
23 #include "gaconfig.h"
24 #include "parametersettable.h"
25 #include "core/genotype.h"
26 #include <QVector>
27 
28 namespace farsa {
29 
40 class FARSA_GA_API Genome : public ParameterSettableWithConfigureFunction {
41 public:
43  Genome();
48  Genome( unsigned int numGenotype, unsigned int numBits );
55  Genome( unsigned int numGenotype, const Genotype* prototype );
57  Genome( const Genome& genome );
62  ~Genome();
64  Genome& operator=( const Genome& right );
71  virtual void configure( ConfigurationParameters& params, QString prefix );
78  virtual void save( ConfigurationParameters& params, QString prefix );
80  static void describe( QString type );
81 
83  unsigned int size() const;
87  void clearAll();
89  void append( const Genotype* );
91  Genotype* at( unsigned int i );
93  const Genotype* at( unsigned int i ) const;
95  Genotype* last();
97  const Genotype* last() const;
101  unsigned int find( const Genotype* g );
103  void set( unsigned int i, Genotype* g );
105  const Genotype* operator[]( unsigned int i ) const;
107  Genotype* operator[]( unsigned int i );
110  return prototype;
111  };
113  void randomize();
115  QVector<Genotype*>::iterator begin() {
116  return data.begin();
117  };
119  QVector<Genotype*>::const_iterator begin() const {
120  return data.begin();
121  };
123  QVector<Genotype*>::iterator end() {
124  return data.end();
125  };
127  QVector<Genotype*>::const_iterator end() const {
128  return data.end();
129  };
130 
131 private:
133  QVector<Genotype*> data;
135  Genotype* prototype;
136 };
137 
138 } // end namespace farsa
139 
140 #endif