MOGAL

mpigeneticalgorithm.h

Go to the documentation of this file.
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_MPIGENETICALGORITHM_H
00032 
00033 #define MOGAL_MPIGENETICALGORITHM_H
00034 
00035 #include "mogalconfig.h"
00036 #include "geneticalgorithm.h"
00037 
00038 namespace mogal
00039 {
00040 
00048 class MOGAL_IMPORTEXPORT MPIGeneticAlgorithm : public GeneticAlgorithm
00049 {
00050 public:
00051         MPIGeneticAlgorithm();
00052         ~MPIGeneticAlgorithm();
00053 
00061         bool runMPI(GAFactory &factory, size_t populationSize, const GeneticAlgorithmParams *pParams = 0);
00062 
00072         bool runMPIHelper(GAFactory &factory);
00073 protected:
00074         virtual void writeLog(int level, const char *fmt, ...)                                                  { }
00075         bool onAlgorithmLoop(GAFactory &factory, bool generationInfoChanged);
00076 private:
00077         bool calculateFitness(std::vector<GenomeWrapper> &population);
00078         
00079         int m_numProcesses;
00080         int m_generationInfoCount, m_lastSentGenInfo;
00081         bool m_firstPopulation;
00082         std::vector<int> m_genomesPerNode;
00083         std::vector<int> m_genomeOffset;
00084         std::vector<uint8_t> m_genomeBuffer;
00085         std::vector<uint8_t> m_fitnessBuffer;
00086         GAFactory *m_pFactory;
00087 };
00088         
00089 } // end namespace
00090 
00091 #endif // MOGAL_GENETICALGORITHM_H
00092