galibinitializer.cpp
1 /********************************************************************************
2  * FARSA Genetic Algorithm Library *
3  * Copyright (C) 2007-2008 Gianluca Massera <emmegian@yahoo.it> *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the Free Software *
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
18  ********************************************************************************/
19 
20 #include "gaconfig.h"
21 #include "crossovers/onepoint.h"
22 #include "evaluations/multitrials.h"
23 #include "gas/laralga.h"
24 #include "gas/simplega.h"
25 #include "gas/parallelga.h"
26 #include "gas/nsga2.h"
27 #include "gas/stefanosteadystatega.h"
28 #include "core/genome.h"
29 #include "genotypes/realgenotype.h"
30 #include "genotypes/signedrangegenotype.h"
31 #include "mutations/flipbit.h"
32 #include "mutations/randombit.h"
33 #include "mutations/randomfloat.h"
34 #include "mutations/gaussianfloat.h"
35 #include "reproductions/fixedsize.h"
36 #include "selections/deterministicrank.h"
37 #include "selections/roulettewheelselection.h"
38 
39 // Headers from the utilities library
40 #include "configurationparameters.h"
41 #include "parametersettable.h"
42 #include "factory.h"
43 #include "logger.h"
44 
45 namespace farsa {
46 
47 bool initGALib() {
48  static bool dummy = false;
49  if ( dummy ) return true;
50  //--- Init the Factory
51  Factory::getInstance().registerClass<Crossover>( "Crossover", "ParameterSettableWithConfigureFunction" );
52  Factory::getInstance().registerClass<OnePoint>( "OnePoint", "Crossover" );
53 
54  Factory::getInstance().registerClass<Evaluation>( "Evaluation", "ParameterSettableWithConfigureFunction" );
55  Factory::getInstance().registerClass<MultiTrials>( "MultiTrials", "Evaluation" );
56 
57  Factory::getInstance().registerClass<GeneticAlgo>( "GeneticAlgo", "ParameterSettableWithConfigureFunction" );
58  Factory::getInstance().registerClass<LaralGA>( "LaralGA", "GeneticAlgo" );
59  Factory::getInstance().registerClass<SimpleGA>( "SimpleGA", "GeneticAlgo" );
60  Factory::getInstance().registerClass<ParallelGA>( "ParallelGA", "GeneticAlgo" );
61  Factory::getInstance().registerClass<NSGA2>( "NSGA2", "GeneticAlgo" );
62  Factory::getInstance().registerClass<StefanoSteadyStateGA>( "StefanoSteadyStateGA", "GeneticAlgo" );
63 
64  Factory::getInstance().registerClass<Genotype>( "Genotype", "ParameterSettableWithConfigureFunction" );
65  Factory::getInstance().registerClass<DoubleGenotype>( "DoubleGenotype", "Genotype" );
66  Factory::getInstance().registerClass<RealGenotype>( "RealGenotype", "DoubleGenotype" );
67  Factory::getInstance().registerClass<SignedRangeGenotype>( "SignedRangeGenotype", "DoubleGenotype" );
68 
69  Factory::getInstance().registerClass<Genome>( "Genome", "ParameterSettableWithConfigureFunction" );
70 
71  Factory::getInstance().registerClass<Mutation>( "Mutation", "ParameterSettableWithConfigureFunction" );
72  Factory::getInstance().registerClass<FlipBit>( "FlipBit", "Mutation" );
73  Factory::getInstance().registerClass<RandomBit>( "RandomBit", "Mutation" );
74  Factory::getInstance().registerClass<RandomFloat>( "RandomFloat", "Mutation" );
75  Factory::getInstance().registerClass<GaussianFloat>( "GaussianFloat", "Mutation" );
76 
77  Factory::getInstance().registerClass<Reproduction>( "Reproduction", "ParameterSettableWithConfigureFunction" );
78  Factory::getInstance().registerClass<FixedSize>( "FixedSize", "Reproduction" );
79 
80  Factory::getInstance().registerClass<Selection>( "Selection", "ParameterSettableWithConfigureFunction" );
81  Factory::getInstance().registerClass<DeterministicRank>( "DeterministicRank", "Selection" );
82  Factory::getInstance().registerClass<RouletteWheelSelection>( "RouletteWheelSelection", "Selection" );
83 
84  dummy = true;
85  Logger::info( "Library GA initialized" );
86  return true;
87 }
88 
89 } // end namespace farsa