Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | Related Pages | Search for

# 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
    00060 template <class EOT>
    00061 eoInit<EOT> & do_make_genotype(eoParser& _parser, eoState& _state, EOT)
    00062 {
    00063   // for bitstring, only thing needed is the size
    00064   // but it might have been already read in the definition fo the performance
    00065   unsigned theSize = _parser.getORcreateParam(unsigned(10), "chromSize", "The length of the bitstrings", 'n',"Problem").value();
    00066
    00067   // Then we can built a bitstring random initializer
    00068   // based on boolean_generator class (see utils/rnd_generator.h)
    00069   eoBooleanGenerator * gen = new eoBooleanGenerator;
    00070   _state.storeFunctor(gen);
    00071   eoInitFixedLength<EOT>* init = new eoInitFixedLength<EOT>(theSize, *gen);
    00072   // store in state
    00073   _state.storeFunctor(init);
    00074   return *init;
    00075 }
    00076
    00077 #endif