Test for a ssga added.
This commit is contained in:
parent
4388faec2e
commit
a27aa7112a
3 changed files with 122 additions and 7 deletions
|
|
@ -9,13 +9,13 @@ DEPS = $(top_builddir)/src/utils/libeoutils.a $(top_builddir)/src/libeo.a
|
|||
###############################################################################
|
||||
|
||||
INCLUDES = -I$(top_builddir)/src
|
||||
LDADDS = $(top_builddir)/src/utils/libeoutils.a $(top_builddir)/src/libeo.a
|
||||
CXXFLAGS = -g
|
||||
LDADDS = $(top_builddir)/src/utils/libeoutils.a $(top_builddir)/src/libeo.a
|
||||
CXXFLAGS = -g -Wall -pg
|
||||
###############################################################################
|
||||
|
||||
check_PROGRAMS = t-eofitness t-eoRandom t-eobin t-eoStateAndParser t-eoCheckpointing \
|
||||
check_PROGRAMS = t-eofitness t-eoRandom t-eobin t-eoStateAndParser t-eoCheckpointing t-eoSSGA \
|
||||
t-eoExternalEO t-eoSymreg t-eo t-eoReplacement t-eoSelect t-eoGenOp t-eoGA t-eoVector
|
||||
TESTS=run_tests t-eoVector t-eoRandom
|
||||
TESTS=run_tests t-eoVector t-eoRandom t-eoSSGA
|
||||
# removing temporarily t-eoESFull
|
||||
#noinst_PROGRAMS = t-eofitness t-eobin t-eoStateAndParser t-eoCheckpointing t-eoExternalEO t-eoESFull t-eoSymreg t-eo t-eoReplacement t-eoSelect t-eoGenOp t-eoGA
|
||||
|
||||
|
|
@ -114,3 +114,10 @@ t_eoGA_LDFLAGS = -lm
|
|||
t_eoGA_LDADD = $(top_builddir)/src/ga/libga.a $(LDADDS)
|
||||
|
||||
###############################################################################
|
||||
|
||||
t_eoSSGA_SOURCES = t-eoSSGA.cpp binary_value.h
|
||||
t_eoSSGA_DEPENDENCIES = $(DEPS) $(top_builddir)/src/ga/libga.a
|
||||
t_eoSSGA_LDFLAGS = -lm
|
||||
t_eoSSGA_LDADD = $(LDADDS)
|
||||
|
||||
###############################################################################
|
||||
|
|
|
|||
|
|
@ -132,10 +132,8 @@ class two2oneOp : public eoGenOp<EOT> // :-)
|
|||
void apply(eoPopulator<EOT>& _plop)
|
||||
{
|
||||
EOT& eo = *_plop; // select the guy
|
||||
++_plop; // advance
|
||||
EOT& eo2 = *_plop;
|
||||
const EOT& eo2 = _plop.select();
|
||||
eo.s = "221(" + eo.s + ", " + eo2.s + ")";
|
||||
_plop.erase();
|
||||
// oh right, and invalidate fitnesses
|
||||
}
|
||||
virtual string className() {return "two2oneOp";}
|
||||
|
|
|
|||
110
eo/test/t-eoSSGA.cpp
Normal file
110
eo/test/t-eoSSGA.cpp
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
#include <eo>
|
||||
|
||||
|
||||
template <class EOT>
|
||||
class eoBreedOne : public eoBreed<EOT>
|
||||
{
|
||||
public :
|
||||
eoBreedOne(eoSelectOne<EOT>& _select, eoGenOp<EOT>& _op) : select(_select), op(_op) {}
|
||||
|
||||
void operator()(const eoPop<EOT>& _src, eoPop<EOT>& _dest)
|
||||
{
|
||||
eoSelectivePopulator<EOT> pop(_src, select);
|
||||
op(pop);
|
||||
_dest = pop;
|
||||
}
|
||||
|
||||
private :
|
||||
eoSelectOne<EOT>& select;
|
||||
eoGenOp<EOT>& op;
|
||||
};
|
||||
|
||||
typedef eoMinimizingFitness FitnessType;
|
||||
typedef eoVector<FitnessType, unsigned> EoType;
|
||||
|
||||
template <class EOT>
|
||||
class eoMyEval : public eoEvalFunc<EOT>
|
||||
{
|
||||
public :
|
||||
|
||||
void operator()(EOT& _eo)
|
||||
{
|
||||
_eo.fitness(*max_element(_eo.begin(), _eo.end()));
|
||||
}
|
||||
};
|
||||
|
||||
template <class EOT>
|
||||
class Xover : public eoBinOp<EOT>
|
||||
{
|
||||
bool operator()(EOT& _eo, const EOT& _eo2)
|
||||
{
|
||||
unsigned point = rng.random(_eo.size());
|
||||
copy(_eo2.begin() + point, _eo2.end(), _eo.begin() + point);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template <class EOT>
|
||||
class Mutate : public eoMonOp<EOT>
|
||||
{
|
||||
bool operator()(EOT& _eo)
|
||||
{
|
||||
unsigned point = rng.random(_eo.size());
|
||||
_eo[point] = rng.random(1024);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
int pop_size = 10;
|
||||
|
||||
eoGenContinue<EoType> cnt(10);
|
||||
eoCheckPoint<EoType> cp(cnt);
|
||||
|
||||
|
||||
Xover<EoType> xover;
|
||||
Mutate<EoType> mutate;
|
||||
|
||||
eoProportionalOp<EoType> opsel;
|
||||
|
||||
opsel.add(xover, 0.8);
|
||||
opsel.add(mutate, 0.2);
|
||||
|
||||
/*
|
||||
eoDetTournamentSelect<EoType> selector(3);
|
||||
eoBreedOne<EoType> breed(selector, opsel);
|
||||
eoSSGAWorseReplacement<EoType> replace;
|
||||
*/
|
||||
|
||||
eoRandomSelect<EoType> selector;
|
||||
eoGeneralBreeder<EoType> breed(selector, opsel);
|
||||
eoPlusReplacement<EoType> replace;
|
||||
|
||||
|
||||
eoMyEval<EoType> eval;
|
||||
|
||||
eoEasyEA<EoType> algo(cp, eval, breed, replace);
|
||||
|
||||
eoUniformGenerator<unsigned> unif(0,1024);
|
||||
eoInitFixedLength<EoType> init(20, unif);
|
||||
|
||||
eoPop<EoType> pop(pop_size, init);
|
||||
|
||||
apply<EoType>(eval, pop);
|
||||
|
||||
eoBestFitnessStat<EoType> best("Best_Fitness");
|
||||
eoAverageStat<EoType> avg("Avg_Fitness");
|
||||
eoStdoutMonitor mon;
|
||||
|
||||
cp.add(best);
|
||||
cp.add(avg);
|
||||
cp.add(mon);
|
||||
|
||||
mon.add(best);
|
||||
mon.add(avg);
|
||||
|
||||
algo(pop);
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue