EvolvingObjects
make_genotype_ga.h
00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00002 
00003 //-----------------------------------------------------------------------------
00004 // make_genotype.h
00005 // (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2001
00006 /*
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Lesser General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public
00018     License along with this library; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 
00021     Contact: todos@geneura.ugr.es, http://geneura.ugr.es
00022              Marc.Schoenauer@polytechnique.fr
00023              mkeijzer@dhi.dk
00024  */
00025 //-----------------------------------------------------------------------------
00026 
00027 #ifndef _make_genotype_h
00028 #define _make_genotype_h
00029 
00030 #include <ga/eoBit.h>
00031 #include <eoInit.h>
00032   // also need the parser and param includes
00033 #include <utils/eoParser.h>
00034 #include <utils/eoState.h>
00035 
00036 
00038 /*
00039  * This fuction does the initialization of what's needed for a particular
00040  * genotype (here, bitstrings).
00041  * It could be here tempatied only on the fitness, as it can be used to evolve
00042  * bitstrings with any fitness.
00043  * However, for consistency reasons, it was finally chosen, as in
00044  * the rest of EO, to templatize by the full EOT, as this eventually
00045  * allows to choose the type of genotype at run time (see in es dir)
00046  *
00047  * It is instanciated in ga/ga.cpp - and incorporated in the ga/libga.a
00048  *
00049  * It returns an eoInit<eoBit<FitT> > tha can later be used to initialize
00050  * the population (see make_pop.h).
00051  *
00052  * It uses a parser (to get user parameters) and a state (to store the memory)
00053  * the last argument is to disambiguate the call upon different instanciations.
00054  *
00055  * WARNING: that last argument will generally be the result of calling
00056  *          the default ctor of EOT, resulting in most cases in an EOT
00057  *          that is ***not properly initialized***
00058  *
00059  * @ingroup bitstring
00060  * @ingroup Builders
00061 */
00062 template <class EOT>
00063 eoInit<EOT> & do_make_genotype(eoParser& _parser, eoState& _state, EOT, float _bias=0.5)
00064 {
00065   // for bitstring, only thing needed is the size
00066   // but it might have been already read in the definition fo the performance
00067   unsigned theSize = _parser.getORcreateParam(unsigned(10), "chromSize", "The length of the bitstrings", 'n',"Problem").value();
00068 
00069   // Then we can built a bitstring random initializer
00070   // based on boolean_generator class (see utils/rnd_generator.h)
00071   eoBooleanGenerator * gen = new eoBooleanGenerator(_bias);
00072   _state.storeFunctor(gen);
00073   eoInitFixedLength<EOT>* init = new eoInitFixedLength<EOT>(theSize, *gen);
00074   // store in state
00075   _state.storeFunctor(init);
00076   return *init;
00077 }
00078 
00079 #endif
 All Classes Namespaces Files Functions Variables Typedefs Friends