Adding PBIL
This commit is contained in:
parent
0816b742d9
commit
e0ae220420
2 changed files with 123 additions and 1 deletions
|
|
@ -15,7 +15,7 @@ CXXFLAGS = -g -Wall
|
||||||
|
|
||||||
check_PROGRAMS = t-eoParetoFitness t-eoPareto t-eofitness t-eoRandom t-eobin t-eoVirus\
|
check_PROGRAMS = t-eoParetoFitness t-eoPareto t-eofitness t-eoRandom t-eobin t-eoVirus\
|
||||||
t-MGE t-MGE1bit t-MGE-control t-eoStateAndParser t-eoCheckpointing t-eoSSGA \
|
t-MGE t-MGE1bit t-MGE-control t-eoStateAndParser t-eoCheckpointing t-eoSSGA \
|
||||||
t-eoExternalEO t-eoSymreg t-eo t-eoReplacement t-eoSelect t-eoGenOp t-eoGA t-eoReal t-eoVector t-eoESAll
|
t-eoExternalEO t-eoSymreg t-eo t-eoReplacement t-eoSelect t-eoGenOp t-eoGA t-eoReal t-eoVector t-eoESAll t-eoPBIL
|
||||||
|
|
||||||
|
|
||||||
TESTS=$(check_PROGRAMS) run_tests
|
TESTS=$(check_PROGRAMS) run_tests
|
||||||
|
|
@ -151,6 +151,7 @@ t_eoESAll_SOURCES = t-eoESAll.cpp real_value.h
|
||||||
t_eoESAll_DEPENDENCIES = $(DEPS) $(top_builddir)/src/es/libes.a
|
t_eoESAll_DEPENDENCIES = $(DEPS) $(top_builddir)/src/es/libes.a
|
||||||
t_eoESAll_LDFLAGS = -lm
|
t_eoESAll_LDFLAGS = -lm
|
||||||
t_eoESAll_LDADD = $(top_builddir)/src/es/libes.a $(LDADDS)
|
t_eoESAll_LDADD = $(top_builddir)/src/es/libes.a $(LDADDS)
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
t_eoSSGA_SOURCES = t-eoSSGA.cpp binary_value.h
|
t_eoSSGA_SOURCES = t-eoSSGA.cpp binary_value.h
|
||||||
|
|
@ -164,10 +165,19 @@ t_eoPareto_SOURCES = t-eoPareto.cpp
|
||||||
t_eoPareto_DEPENDENCIES = $(DEPS) $(top_builddir)/src/ga/libga.a
|
t_eoPareto_DEPENDENCIES = $(DEPS) $(top_builddir)/src/ga/libga.a
|
||||||
t_eoPareto_LDFLAGS = -lm
|
t_eoPareto_LDFLAGS = -lm
|
||||||
t_eoPareto_LDADD = $(LDADDS)
|
t_eoPareto_LDADD = $(LDADDS)
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
t_eoParetoFitness_SOURCES = t-eoParetoFitness.cpp
|
t_eoParetoFitness_SOURCES = t-eoParetoFitness.cpp
|
||||||
t_eoParetoFitness_DEPENDENCIES = $(DEPS) $(top_builddir)/src/ga/libga.a
|
t_eoParetoFitness_DEPENDENCIES = $(DEPS) $(top_builddir)/src/ga/libga.a
|
||||||
t_eoParetoFitness_LDFLAGS = -lm
|
t_eoParetoFitness_LDFLAGS = -lm
|
||||||
t_eoParetoFitness_LDADD = $(LDADDS)
|
t_eoParetoFitness_LDADD = $(LDADDS)
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
t_eoPBIL_SOURCES = t-eoPBIL.cpp
|
||||||
|
t_eoPBIL_DEPENDENCIES = $(DEPS) $(top_builddir)/src/ga/libga.a
|
||||||
|
t_eoPBIL_LDFLAGS = -lm
|
||||||
|
t_eoPBIL_LDADD = $(top_builddir)/src/ga/libga.a $(LDADDS)
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
|
||||||
112
eo/test/t-eoPBIL.cpp
Normal file
112
eo/test/t-eoPBIL.cpp
Normal file
|
|
@ -0,0 +1,112 @@
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <eo>
|
||||||
|
#include <ga/make_ga.h>
|
||||||
|
#include "binary_value.h"
|
||||||
|
#include <apply.h>
|
||||||
|
#include <ga/eoPBILDistrib.h>
|
||||||
|
#include <ga/eoPBILOrg.h>
|
||||||
|
#include <ga/eoPBILAdditive.h>
|
||||||
|
#include <eoSimpleDEA.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
typedef eoBit<double> Indi;
|
||||||
|
|
||||||
|
// instanciating the outside subroutine that creates the distribution
|
||||||
|
#include "ga/make_PBILdistrib.h"
|
||||||
|
eoPBILDistrib<Indi> & make_PBILdistrib(eoParser& _parser, eoState&_state, Indi _eo)
|
||||||
|
{
|
||||||
|
return do_make_PBILdistrib(_parser, _state, _eo);
|
||||||
|
}
|
||||||
|
|
||||||
|
// instanciating the outside subroutine that creates the update rule
|
||||||
|
#include "ga/make_PBILupdate.h"
|
||||||
|
eoDistribUpdater<Indi> & make_PBILupdate(eoParser& _parser, eoState&_state, Indi _eo)
|
||||||
|
{
|
||||||
|
return do_make_PBILupdate(_parser, _state, _eo);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
eoParser parser(argc, argv); // for user-parameter reading
|
||||||
|
|
||||||
|
eoState state; // keeps all things allocated
|
||||||
|
|
||||||
|
///// FIRST, problem or representation dependent stuff
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// The evaluation fn - encapsulated into an eval counter for output
|
||||||
|
eoEvalFuncPtr<Indi, float> mainEval( binary_value<Indi>);
|
||||||
|
eoEvalFuncCounter<Indi> eval(mainEval);
|
||||||
|
|
||||||
|
// COnstruction of the distribution
|
||||||
|
eoPBILDistrib<Indi> & distrib = make_PBILdistrib(parser, state, Indi());
|
||||||
|
// and the update rule
|
||||||
|
eoDistribUpdater<Indi> & update = make_PBILupdate(parser, state, Indi());
|
||||||
|
|
||||||
|
//// Now the representation-independent things
|
||||||
|
//////////////////////////////////////////////
|
||||||
|
|
||||||
|
// stopping criteria
|
||||||
|
eoContinue<Indi> & term = make_continue(parser, state, eval);
|
||||||
|
// output
|
||||||
|
eoCheckPoint<Indi> & checkpoint = make_checkpoint(parser, state, eval, term);
|
||||||
|
|
||||||
|
// add a graphical output for the distribution
|
||||||
|
// first, get the direname from the parser
|
||||||
|
// it has been enetered in make_checkoint
|
||||||
|
|
||||||
|
eoParam* ptParam = parser.getParamWithLongName(string("resDir"));
|
||||||
|
eoValueParam<string>* ptDirNameParam = dynamic_cast<eoValueParam<string>*>(ptParam);
|
||||||
|
if (!ptDirNameParam) // not found
|
||||||
|
throw runtime_error("Parameter resDir not found where it was supposed to be");
|
||||||
|
|
||||||
|
// now create the snapshot monitor
|
||||||
|
eoValueParam<bool>& plotDistribParam = parser.createParam(false, "plotDistrib", "Plot Distribution", '\0', "Output - Graphical");
|
||||||
|
if (plotDistribParam.value())
|
||||||
|
{
|
||||||
|
unsigned frequency=1; // frequency of plots updates
|
||||||
|
eoGnuplot1DSnapshot *distribSnapshot = new eoGnuplot1DSnapshot(ptDirNameParam->value(), frequency, "distrib");
|
||||||
|
state.storeFunctor(distribSnapshot);
|
||||||
|
// add the distribution (it is an eoValueParam<vector<double> >)
|
||||||
|
distribSnapshot->add(distrib);
|
||||||
|
// and of course add it to the checkpoint
|
||||||
|
checkpoint.add(*distribSnapshot);
|
||||||
|
}
|
||||||
|
|
||||||
|
// the algorithm: DEA
|
||||||
|
// don't know where else to put the population size!
|
||||||
|
unsigned popSize = parser.createParam(unsigned(100), "popSize", "Population Size", 'P', "Algorithm").value();
|
||||||
|
eoSimpleDEA<Indi> dea(update, eval, popSize, checkpoint);
|
||||||
|
|
||||||
|
///// End of construction of the algorith
|
||||||
|
/////////////////////////////////////////
|
||||||
|
// to be called AFTER all parameters have been read!!!
|
||||||
|
make_help(parser);
|
||||||
|
|
||||||
|
//// GO
|
||||||
|
///////
|
||||||
|
|
||||||
|
dea(distrib); // run the dea
|
||||||
|
|
||||||
|
cout << "Final Distribution\n";
|
||||||
|
distrib.printOn(cout);
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
|
// wait - for graphical output
|
||||||
|
if (plotDistribParam.value())
|
||||||
|
{
|
||||||
|
string foo;
|
||||||
|
cin >> foo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(exception& e)
|
||||||
|
{
|
||||||
|
cout << e.what() << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in a new issue