MOGAL

gafactorymultiobjective.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_GAFACTORYMULTIOBJECTIVE_H
00032 
00033 #define MOGAL_GAFACTORYMULTIOBJECTIVE_H
00034 
00035 #include "mogalconfig.h"
00036 #include "gafactorydefaults.h"
00037 
00038 //#define MOGAL_DEBUGTIMING
00039 
00040 namespace mogal
00041 {
00042 
00052 class MOGAL_IMPORTEXPORT GAFactoryMultiObjective : public GAFactoryDefaults
00053 {
00054 protected:
00056         GAFactoryMultiObjective(size_t numComponents = 2);
00057 public:
00058         enum SortType { Basic, Optimized, CUDA };
00059 
00060         ~GAFactoryMultiObjective();
00061 
00063         void setNumberOfFitnessComponents(size_t n)                                                     { m_numComponents = n; }
00064 
00065         size_t getNumberOfFitnessComponents() const                                                     { return m_numComponents; }
00066         
00067         void introduceMutations(std::vector<GenomeWrapper> &newpopulation);
00068         void breed(const std::vector<GenomeWrapper> &population, std::vector<GenomeWrapper> &newPopulation);
00069         void sort(std::vector<GenomeWrapper> &population);
00070         
00071         void sortOld(std::vector<GenomeWrapper> &population);
00072         void sortNew(std::vector<GenomeWrapper> &population);
00073         void sortCuda(std::vector<GenomeWrapper> &population);
00074 
00075         void updateBestGenomes(std::vector<GenomeWrapper> &population);
00076 private:
00077         void initSort(int populationSize);
00078         void initSortCUDA(int populationSize);
00079 
00080         size_t m_numComponents;
00081         int m_offset;
00082         std::list<Genome *> m_populationNDS;
00083         std::vector<std::vector<GenomeWrapper> > m_orderedSets;
00084 
00085         // TODO: for debugging
00086 #ifdef MOGAL_DEBUGTIMING
00087         double m_totalOldTime;
00088         double m_totalNewTime;
00089         double m_totalCudaTime;
00090 #endif // MOGAL_DEBUGTIMING
00091         std::vector<int16_t> m_dominatesList;
00092 
00093         bool m_sortInit;
00094         bool m_hasCuda;
00095         SortType m_sortType;
00096 
00097         float *m_pDeviceFitnessArray;
00098         short *m_pDeviceDominationMap;
00099         int *m_pDeviceDominatedByCount;
00100         int *m_pDeviceDominatesCount;
00101 
00102         float *m_pHostFitnessArray;
00103         short *m_pHostDominationMap;
00104         int *m_pHostDominatedByCount;
00105         int *m_pHostDominatesCount;
00106         int *m_pOffsets;
00107 
00108         int m_blockSize1, m_blockSize2;
00109 };
00110 
00111 } // end namespace
00112 
00113 #endif // MOGAL_GAFACTORYMULTIOBJECTIVE_H
00114