Ok, updated the Makefile.am again to use the

make check

Command I picked up in the automake documentation (RTFM, you know)

Tagged a lot of header functions in the GnuPlot files with 'inline',
so they can be used from more than one sourcefile.

Ok, now the interesting news. Started a new library libga (not to be confused
with Matthew's GaLib). Here I suggest we put a fairly complete and configurable
genetic algorithm. Just to see how far we can stretch ourselves and also to have
a GA-componenent that can be used in other applications without having to rebuild
the entire thing. test/t-eoGA.cpp tests this library
This commit is contained in:
maartenkeijzer 2001-02-12 13:58:51 +00:00
commit dea8a51f7e
12 changed files with 260 additions and 81 deletions

View file

@ -4,5 +4,11 @@
##
###############################################################################
INCLUDES = -I$(top_builddir)/src
lib_LIBRARIES = libga.a
libga_a_SOURCES = ga.cpp
CPPFLAGS = -O2 -Wall
libeoincdir = $(includedir)/eo/ga
libeoinc_HEADERS = eoBit.h eoBitOp.h eoBitOpFactory.h
libeoinc_HEADERS = eoBit.h eoBitOp.h eoBitOpFactory.h ga.h

91
eo/src/ga/ga.cpp Normal file
View file

@ -0,0 +1,91 @@
#include <eo>
#include <ga/ga.h>
eoValueParam<float> xoverRate(0.6f, "xoverrate", "The crossover rate", 'x');
eoValueParam<float> mutRate(1.0f, "mutationrate", "The mutation rate", 'm');
eoValueParam<unsigned> chromSize(unsigned(10), "chromosomeSize", "The length of the bitstrings", 'n');
eoValueParam<unsigned> popSize(unsigned(20), "PopSize", "Population Size", 'P');
template <class FitT>
eoAlgo<eoBit<FitT> >& do_make_ga(eoParameterLoader& _parser, eoEvalFunc<eoBit<FitT> >& _eval, eoCheckPoint<eoBit<FitT> >& _checkpoint, eoState& _state)
{
typedef eoBit<FitT> EOT;
_parser.processParam(xoverRate, "genetics");
_parser.processParam(mutRate, "genetics");
_parser.processParam(chromSize, "initialization");
eoBitMutation<EOT>* mutOp = new eoBitMutation<EOT>(1. / float(chromSize.value()));
_state.storeFunctor(mutOp);
eo1PtBitXover<EOT>* crossOp = new eo1PtBitXover<EOT>;
_state.storeFunctor(crossOp);
eoSelectOne<EOT>* select = new eoDetTournamentSelect<EOT>(2);
_state.storeFunctor(select);
eoSGA<eoBit<FitT> >* sga = new eoSGA<EOT>(*select, *crossOp, xoverRate.value(), *mutOp, mutRate.value(), _eval, _checkpoint);
_state.storeFunctor(sga);
return *sga;
}
template <class FitT>
eoPop<eoBit<FitT> >& do_init_ga(eoParameterLoader& _parser, eoState& _state, FitT)
{
typedef eoBit<FitT> EOT;
_parser.processParam(chromSize, "initialization");
_parser.processParam(popSize, "initialization");
eoInitFixedLength<EOT, boolean_generator> init(chromSize.value(), boolean_generator());
// Let the state handle the memory
eoPop<EOT>& pop = _state.takeOwnership(eoPop<EOT>());
_state.registerObject(pop);
// initialize the population
pop.append(popSize.value(), init);
return pop;
}
template <class FitT>
void do_run_ga(eoAlgo<eoBit<FitT> >& _ga, eoPop<eoBit<FitT> >& _pop)
{
_ga(_pop);
}
/// The following function merely call the templatized do_* functions above
eoAlgo<eoBit<double> >& make_ga(eoParameterLoader& _parser, eoEvalFunc<eoBit<double> >& _eval, eoCheckPoint<eoBit<double> >& _checkpoint, eoState& _state)
{
return do_make_ga(_parser, _eval, _checkpoint, _state);
}
eoAlgo<eoBit<eoMinimizingFitness> >& make_ga(eoParameterLoader& _parser, eoEvalFunc<eoBit<eoMinimizingFitness> >& _eval, eoCheckPoint<eoBit<eoMinimizingFitness> >& _checkpoint, eoState& _state)
{
return do_make_ga(_parser, _eval, _checkpoint, _state);
}
eoPop<eoBit<double> >& init_ga(eoParameterLoader& _parser, eoState& _state, double _d)
{
return do_init_ga(_parser, _state, _d);
}
eoPop<eoBit<eoMinimizingFitness> >& init_ga(eoParameterLoader& _parser, eoState& _state, eoMinimizingFitness _d)
{
return do_init_ga(_parser, _state, _d);
}
void run_ga(eoAlgo<eoBit<double> >& _ga, eoPop<eoBit<double> >& _pop)
{
do_run_ga(_ga, _pop);
}
void run_ga(eoAlgo<eoBit<eoMinimizingFitness> >& _ga, eoPop<eoBit<eoMinimizingFitness> >& _pop)
{
do_run_ga(_ga, _pop);
}

24
eo/src/ga/ga.h Normal file
View file

@ -0,0 +1,24 @@
#ifndef ga_h
#define ga_h
#include <eoAlgo.h>
#include <eoScalarFitness.h>
#include <utils/eoParser.h>
#include <eoEvalFunc.h>
#include <utils/eoCheckPoint.h>
#include <eoPop.h>
#include <ga/eoBit.h>
#include <ga/eoBitOp.h>
eoAlgo<eoBit<double> >& make_ga(eoParameterLoader& _parser, eoEvalFunc<eoBit<double> >& _eval, eoCheckPoint<eoBit<double> >& _checkpoint, eoState& state);
eoAlgo<eoBit<eoMinimizingFitness> >& make_ga(eoParameterLoader& _parser, eoEvalFunc<eoBit<eoMinimizingFitness> >& _eval, eoCheckPoint<eoBit<eoMinimizingFitness> >& _checkpoint, eoState& state);
eoPop<eoBit<double> >& init_ga(eoParameterLoader& _parser, eoState& _state, double);
eoPop<eoBit<eoMinimizingFitness> >& init_ga(eoParameterLoader& _parser, eoState& _state, eoMinimizingFitness);
void run_ga(eoAlgo<eoBit<double> >& _ga, eoPop<eoBit<double> >& _pop);
void run_ga(eoAlgo<eoBit<eoMinimizingFitness> >& _ga, eoPop<eoBit<eoMinimizingFitness> >& _pop);
#endif