Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef GAChromosomeH
00033 #define GAChromosomeH
00034
00035 #include <zeusmath/Intel/Interfaces/IGAChromosome.hpp>
00036 #include <zeusmath/Intel/GAGene.h>
00037 #include <zeusbase/System/ByteArray.hpp>
00038 #include <zeusbase/System/ZObject.h>
00039 #include <zeusbase/System/ZVariant.h>
00040
00041 BEGIN_NAMESPACE_Zeus
00042
00043 class TGAGene;
00044
00045
00048
00049 zeusmath_class TGAChromosome : public TZObject, public IGAChromosome
00050 {
00051 public:
00052
00055
00056 enum ECrossOverKind
00057 {
00058 etMultiPoint,
00059 etUniform,
00060 etInterIntRecombination,
00061 etLineIntRecombination,
00062 etInterFloatRecombination,
00063 etLineFloatRecombination,
00064 etCustom
00065 };
00066
00067 typedef Retval (*FCrossFunction)(IGAChromosome& rParent1,
00068 IGAChromosome& rParent2,
00069 TGAChromosome& rNewChrom1,
00070 TGAChromosome& rNewChrom2);
00071
00072 TGAChromosome(Uint uiID,
00073 Uint uiDNASize,
00074 Uint uiGeneSize);
00075
00076 ECrossOverKind getCrossOverKind() const;
00077 Int getMultiPointParameter() const;
00078 void setCrossOverKind(ECrossOverKind eKind, FCrossFunction pFunct = NULL);
00079 void setMultiPointParameter(Int iValue);
00080 void setMinMaxParameter(const Float& rfMin, const Float& rfMax);
00081
00082
00083 virtual Uint MQUALIFIER getChromosomeID() const;
00084 virtual IByteArray& MQUALIFIER getDNA();
00085 virtual const IByteArray& MQUALIFIER getDNAConst() const;
00086 virtual Int MQUALIFIER getGeneCount() const;
00087 virtual Int MQUALIFIER getGeneSize() const;
00088 virtual IGAGene& MQUALIFIER getGene(Int iIndex);
00089 virtual const IGAGene& MQUALIFIER getGeneConst(Int iIndex) const;
00090 virtual Retval MQUALIFIER crossOver(IGAChromosome& rChrom, IGAChromosome*& rpNewChrom1, IGAChromosome*& rpNewChrom2);
00091 virtual Retval MQUALIFIER clone(IGAChromosome*& rpNewChrom) const;
00092 virtual void MQUALIFIER mutate();
00093
00094
00095 MEMORY_MANAGER_DECL
00096
00097 protected:
00098 virtual ~TGAChromosome();
00099
00101 Uint m_uiDNASize;
00103 Uint m_uiGeneSize;
00104
00106 ECrossOverKind m_eCrossKind;
00108 TByteArray m_lstDNA;
00110 TArrayList<TGAGene*> m_lstGenes;
00112 Int m_iMultiPointParam;
00114 FCrossFunction m_Funct;
00116 Float m_fMinValue;
00118 Float m_fMaxValue;
00119
00120 private:
00121 void checkCrossingPoints();
00122 void doMultiCrossOver(IGAChromosome& rParent2, TGAChromosome& rChrom1, TGAChromosome& rChrom2);
00123 void doRecombinationInt(IGAChromosome& rParent2, TGAChromosome& rChrom1, TGAChromosome& rChrom2, bool bLinearOnly);
00124 void doRecombinationFloat(IGAChromosome& rParent2, TGAChromosome& rChrom1, TGAChromosome& rChrom2, bool bLinearOnly);
00125 };
00126
00127
00130
00131 inline TGAChromosome::ECrossOverKind TGAChromosome::getCrossOverKind() const
00132 {
00133 return m_eCrossKind;
00134 }
00135
00136
00139
00140 inline Int TGAChromosome::getMultiPointParameter() const
00141 {
00142 return m_iMultiPointParam;
00143 }
00144
00145
00148
00149 inline void TGAChromosome::setMinMaxParameter(const Float& rfMin, const Float& rfMax)
00150 {
00151 m_fMinValue = rfMin;
00152 m_fMaxValue = rfMax;
00153 }
00154
00155
00158
00159 inline Uint MQUALIFIER TGAChromosome::getChromosomeID() const
00160 {
00161 return m_uiID;
00162 }
00163
00164
00167
00168 inline IByteArray& MQUALIFIER TGAChromosome::getDNA()
00169 {
00170 return m_lstDNA;
00171 }
00172
00173
00176
00177 inline const IByteArray& MQUALIFIER TGAChromosome::getDNAConst() const
00178 {
00179 return m_lstDNA;
00180 }
00181
00182
00185
00186 inline Int MQUALIFIER TGAChromosome::getGeneCount() const
00187 {
00188 return m_lstGenes.getCount();
00189 }
00190
00191
00194
00195 inline Int MQUALIFIER TGAChromosome::getGeneSize() const
00196 {
00197 return m_uiGeneSize;
00198 }
00199
00200
00203
00204 inline IGAGene& MQUALIFIER TGAChromosome::getGene(Int iIndex)
00205 {
00206 return *m_lstGenes.getItem(iIndex);
00207 }
00208
00209
00212
00213 inline const IGAGene& MQUALIFIER TGAChromosome::getGeneConst(Int iIndex) const
00214 {
00215 return *m_lstGenes.getItemConst(iIndex);
00216 }
00217
00218
00219
00220 END_NAMESPACE_Zeus
00221
00222 #endif
00223