MOGAL
|
00001 /* 00002 00003 This file is a part of MOGAL, a Multi-Objective Genetic Algorithm 00004 Library. 00005 00006 Copyright (C) 2008-2012 Jori Liesenborgs 00007 00008 Contact: jori.liesenborgs@gmail.com 00009 00010 This library is free software; you can redistribute it and/or 00011 modify it under the terms of the GNU Lesser General Public 00012 License as published by the Free Software Foundation; either 00013 version 2.1 of the License, or (at your option) any later version. 00014 00015 This library is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 Lesser General Public License for more details. 00019 00020 You should have received a copy of the GNU Lesser General Public 00021 License along with this library; if not, write to the Free Software 00022 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 00023 USA 00024 00025 */ 00026 00031 #ifndef MOGAL_GENOME_H 00032 00033 #define MOGAL_GENOME_H 00034 00035 #include "mogalconfig.h" 00036 #include <string> 00037 00038 namespace mogal 00039 { 00040 00042 class MOGAL_IMPORTEXPORT Genome 00043 { 00044 public: 00045 Genome() { } 00046 virtual ~Genome() { } 00047 00049 virtual bool calculateFitness() = 0; 00050 00055 virtual void setActiveFitnessComponent(int componentNumber) { } 00056 00060 virtual bool isFitterThan(const Genome *pGenome) const = 0; 00061 00063 virtual Genome *reproduce(const Genome *pGenome) const = 0; 00064 00065 // NOTE: Clone should also copy fitness info etc, since it is also used to store the 00066 // current best genome 00067 00071 virtual Genome *clone() const = 0; 00072 00074 virtual void mutate() = 0; 00075 00077 virtual std::string getFitnessDescription() const = 0; 00078 00079 // TODO 00080 virtual void copyFitnessValuesTo(float *pDestination, int amount) const { } 00081 }; 00082 00084 class GenomeWrapper 00085 { 00086 public: 00094 GenomeWrapper(Genome *pGenome = 0, int parent1 = -1, int parent2 = -1, int position = -1) { m_pGenome = pGenome; m_parent1 = parent1; m_parent2 = parent2; m_position = position; } 00095 00096 ~GenomeWrapper() { } 00097 00099 Genome *getGenome() const { return m_pGenome; } 00100 00102 int getParent1() const { return m_parent1; } 00103 00105 int getParent2() const { return m_parent2; } 00106 00108 int getPosition() const { return m_position; } 00109 private: 00110 Genome *m_pGenome; 00111 int m_parent1; 00112 int m_parent2; 00113 int m_position; 00114 }; 00115 00116 inline bool operator< (const GenomeWrapper &g1, const GenomeWrapper &g2) 00117 { 00118 return g1.getGenome()->isFitterThan(g2.getGenome()); 00119 } 00120 00121 } // end namespace 00122 00123 #endif // MOGAL_GENOME_H 00124