00001 #include <NLstl_utils.h>
00002
00003 #include "GLBaseParameters.h"
00004 #include "GLBreederStandard.h"
00005 #include "GLConstants.h"
00006 #include "GLCrossoverOnePoint.h"
00007 #include "GLCrossoverTwoPoints.h"
00008 #include "GLCrossoverVectorKeepMatching.h"
00009 #include "GLFactory.h"
00010 #include "GLMutatorCombined.h"
00011 #include "GLMutatorGeneMove.h"
00012 #include "GLMutatorGenesSwapping.h"
00013 #include "GLMutatorShuffling.h"
00014 #include "GLPopulationStandard.h"
00015 #include "GLSelectionistMixer.h"
00016 #include "GLSelectionistStandard.h"
00017 #include "GLRankerStandardSO.h"
00018 #include "GLVariatorStandard.h"
00019
00020 #include "gl_utils.h"
00021
00022
00033 GLBaseBreeder* GLFactory::createBreeder(
00034 int breeder_type,
00035 GLBaseCrossover* crossover,
00036 GLBaseParameters* breeder_parameters,
00037 GLBaseGeneticAlgorithm* ga)
00038 {
00039 switch(breeder_type)
00040 {
00041 case (GLConstants::BREEDER_STANDARD):
00042 {
00043 GLBreederStandard::TParameters *params =
00044 nlutils::transform_pointer<GLBreederStandard::TParameters,
00045 GLBaseParameters>(breeder_parameters);
00046 return new GLBreederStandard(crossover,
00047 params, ga);
00048 }
00049 }
00050 return NULL;
00051 }
00052
00059 GLBaseCrossover* GLFactory::createCrossover(
00060 int crossover_type,
00061 GLBaseParameters* crossover_parameters,
00062 GLBaseGeneticAlgorithm* ga)
00063 {
00064 switch (crossover_type)
00065 {
00066 case (GLConstants::CROSSOVER_VECTOR_KEEP_MATCHING_INT):
00067 return new GLCrossoverVectorKeepMatching<int>();
00068 case (GLConstants::CROSSOVER_ONE_POINT):
00069 return new GLCrossoverOnePoint();
00070 case (GLConstants::CROSSOVER_TWO_POINTS):
00071 return new GLCrossoverTwoPoints();
00072 }
00073 return NULL;
00074 }
00075
00076
00086 GLBaseMutator* GLFactory::createMutator(int mutator_type,
00087 double mutation_rate,
00088 GLBaseParameters* mutator_parameters,
00089 GLBaseGeneticAlgorithm* ga)
00090 {
00091 switch (mutator_type)
00092 {
00093 case (GLConstants::MUTATOR_GENES_SWAPPING):
00094 {
00095 return new GLMutatorGenesSwapping(mutation_rate);
00096 }
00097 case (GLConstants::MUTATOR_GENES_SHUFFLING):
00098 {
00099 GLMutatorShuffling::TParameters *params =
00100 nlutils::transform_pointer<GLMutatorShuffling::TParameters,
00101 GLBaseParameters>(mutator_parameters,
00102 "GLFactory::createMutator\n"
00103 "Mutator parameters passed is NULL or not compatible with "
00104 "GLMutatorShuffling::TParameters\n");
00105 return new GLMutatorShuffling(mutation_rate, params);
00106 }
00107 case (GLConstants::MUTATOR_GENE_MOVING):
00108 {
00109 return new GLMutatorGeneMove(mutation_rate);
00110 }
00111 case (GLConstants::MUTATOR_COMBINED):
00112 {
00113 GLMutatorCombined::TParameters *params =
00114 nlutils::transform_pointer<GLMutatorCombined::TParameters,
00115 GLBaseParameters>(mutator_parameters,
00116 "GLFactory::createMutator\n"
00117 "Mutator parameters passed is NULL or not compatible with "
00118 "GLMutatorCombined::TParameters\n");
00119 return new GLMutatorCombined(mutation_rate, params);
00120 }
00121 }
00122 return NULL;
00123 }
00124
00131 GLBaseRanker* GLFactory::createRanker(int ranker_type,
00132 GLBaseParameters* ranker_parameters,
00133 GLBaseGeneticAlgorithm* ga)
00134 {
00135 switch (ranker_type)
00136 {
00137 case (GLConstants::RANKER_STANDARD_SO):
00138 return new GLRankerStandardSO();
00139 }
00140 return NULL;
00141 }
00142
00151 GLBaseSelectionist* GLFactory::createSelectionist(int selectionist_type,
00152 GLBaseRanker* ranker,
00153 GLBaseParameters* selectionist_parameters,
00154 GLBaseGeneticAlgorithm* ga)
00155 {
00156 switch (selectionist_type)
00157 {
00158 case (GLConstants::SELECTIONIST_ELITIST):
00159 {
00160 return new GLSelectionistStandard(ranker);
00161 }
00162 case (GLConstants::SELECTIONIST_MIXER):
00163 {
00164 GLSelectionistMixer::TParameters *params =
00165 nlutils::transform_pointer<GLSelectionistMixer::TParameters,
00166 GLBaseParameters>(selectionist_parameters,
00167 "GLFactory::createSelectionist\n"
00168 "Selectionist parameters passed is NULL or not "
00169 "compatible with GLSelectionist::TParameters\n");
00170 return new GLSelectionistMixer(ranker, params);
00171 }
00172 }
00173 return NULL;
00174 }
00175
00183 GLBaseVariator* GLFactory::createVariator(int variator_type,
00184 GLBaseMutator* mutator,
00185 GLBaseParameters* variator_parameters,
00186 GLBaseGeneticAlgorithm* ga)
00187 {
00188 switch(variator_type)
00189 {
00190 case(GLConstants::VARIATOR_STANDARD):
00191 return new GLVariatorStandard(mutator);
00192 }
00193 return NULL;
00194 }