LCFIVertex  0.7.2
Genome.h
1 #ifndef GENOME_H
2 #define GENOME_H
3 
4 #include "NeuralNetConfig.h"
5 
6 #include <vector>
7 
8 //namespace nnet added 15/08/06 by Mark Grimes (mark.grimes@bristol.ac.uk) for the LCFI vertex package
9 namespace nnet
10 {
11 
12 class
13 #ifndef __CINT__
14 NEURALNETDLL
15 #endif
16 Genome
17 {
18 public:
19  Genome(const int numberOfGenes,const bool setInitialRandomValues=true);
20  Genome(const std::vector<double> &chromosome);
21  Genome(const std::vector<double> &chromosome,const double fitness);
22  ~Genome(void);
23  double fitness() const {return _fitness;}
24  void setFitness(double fitness) {_fitness = fitness;}
25  std::vector<double> chromosome() const {return _chromosome;}
26  void setChromosome(const std::vector<double> &newChromosome);
27  void sex(const Genome &with,Genome &baby1,Genome &baby2);
28  int numberOfGenes() {return _numberOfGenes;}
29 
30 protected:
31  void crossover(const Genome &with,Genome &baby1,Genome &baby2);
32  void mutate(Genome &theGenome);
33 
34 private:
35  std::vector<double> _chromosome;
36  double _fitness;
37  int _numberOfGenes;
38 
39 public:
40  friend
41 #ifndef __CINT__
42 NEURALNETDLL
43 #endif
44  bool operator<(const Genome &lhs,const Genome &rhs)
45  { return lhs.fitness() < rhs.fitness();}
46  friend
47 #ifndef __CINT__
48 NEURALNETDLL
49 #endif
50  bool operator>(const Genome &lhs,const Genome &rhs)
51  { return lhs.fitness() > rhs.fitness();}
52  friend
53 #ifndef __CINT__
54 NEURALNETDLL
55 #endif
56  bool operator==(const Genome &lhs,const Genome &rhs)
57  { return lhs.chromosome() == rhs.chromosome();}
58 
59 public:
60  static double MutationRate;
61  static double CrossoverRate;
62  static double MaxMutationPerturbation;
63 };
64 
65 }//namespace nnet
66 
67 #endif