MOGAL

doublevectorgafactory.h

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 
00027 #ifndef MOGAL_DOUBLEVECTORGAFACTORY_H
00028 
00029 #define MOGAL_DOUBLEVECTORGAFACTORY_H
00030 
00031 #include "mogalconfig.h"
00032 #include "gafactorydefaults.h"
00033 #include "doublevectorgafactoryparams.h"
00034 
00035 namespace mogal
00036 {
00037 
00038 class RandomNumberGenerator;
00039 
00040 class MOGAL_IMPORTEXPORT DoubleVectorGAFactory : public GAFactoryDefaults
00041 {
00042 public:
00043         DoubleVectorGAFactory();
00044         ~DoubleVectorGAFactory();
00045 
00046         // Can only be implemented in a derived class, the class returned should be derived from DoubleVectorGAFactoryParams
00047         //mogal::GAFactoryParams *createParamsInstance() const;
00048 
00049         bool init(const GAFactoryParams *pParams);
00050         const GAFactoryParams *getCurrentParameters() const;
00051 
00052         size_t getNumberOfParameters() const                                                            { return (size_t)m_numGenomeParameters; }
00053 
00054         // Can only be implemented in a derived class, the class returned should be derived from DoubleVectorGenome
00055         //Genome *createNewGenome() const;
00056         size_t getMaximalGenomeSize() const;
00057         size_t getMaximalFitnessSize() const;
00058         bool writeGenome(serut::SerializationInterface &si, const mogal::Genome *pGenome) const;
00059         bool writeGenomeFitness(serut::SerializationInterface &si, const mogal::Genome *pGenome) const;
00060         bool writeCommonGenerationInfo(serut::SerializationInterface &si) const;
00061         bool readGenome(serut::SerializationInterface &si, mogal::Genome **pGenome) const;
00062         bool readGenomeFitness(serut::SerializationInterface &si, mogal::Genome *pGenome) const;
00063         bool readCommonGenerationInfo(serut::SerializationInterface &si);
00064 
00065         void onGeneticAlgorithmStep(int generation, bool *generationInfoChanged, bool *stopAlgorithm);
00066         void onGeneticAlgorithmStart();
00067         void onGeneticAlgorithmStop();
00068         void onSortedPopulation(const std::vector<mogal::GenomeWrapper> &population);
00069 protected:
00070         virtual bool subInit(const DoubleVectorGAFactoryParams *pParams)                                        { return true; }
00071 private:
00072         DoubleVectorGAFactoryParams *m_pFactoryParams;
00073         int m_numGenomeParameters;
00074         int m_numFitnessValues;
00075         bool m_init;
00076 };
00077 
00078 } // end namespace
00079 
00080 #endif // MOGAL_DOUBLEVECTORGAFACTORY_H
00081