MOGAL

gafactorydefaults.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_GAFACTORYDEFAULTS_H
00032 
00033 #define MOGAL_GAFACTORYDEFAULTS_H
00034 
00035 #include "mogalconfig.h"
00036 #include "gafactory.h"
00037 #include <stdlib.h>
00038 #include <cmath>
00039 
00040 namespace mogal
00041 {
00042 
00043 // NOTE: the virtual inheritance is of extreme importance here!
00044 
00046 class MOGAL_IMPORTEXPORT GAFactoryDefaults : public virtual GAFactory
00047 {
00048 public:
00049         ~GAFactoryDefaults()                                                                            { }
00050 
00051 protected:
00052         GAFactoryDefaults();
00053 
00054 
00055 
00056         void commonBreed(int startOffset, const std::vector<GenomeWrapper> &population, 
00057                          std::vector<GenomeWrapper> &newPopulation);
00058 
00059         int pickGenome(int num) const
00060         {
00061                 double x = pickDouble();
00062                 double val = x*(double)num; 
00063                 return (int)val;
00064         }
00065 
00066         int pickGenome(double beta, size_t populationSize) const
00067         {
00068                 double x = pickDouble();
00069                 double val = (1.0-std::pow(x, 1.0/(1.0+beta)))*((double)populationSize);
00070                 return (int)val;
00071         }
00072 
00073         double pickDouble() const { return getRandomNumberGenerator()->pickRandomNumber(); }
00074 };
00075 
00076 } // end namespace
00077 
00078 #endif // MOGAL_GAFACTORYDEFAULTS_H
00079