Extreme cleanup, see src/obsolete for details

This commit is contained in:
mac 2000-08-10 14:18:34 +00:00
commit 6d8e3a6504
141 changed files with 3937 additions and 1815 deletions

View file

@ -13,46 +13,7 @@ LDADDS = $(top_builddir)/src/libeo.a $(top_builddir)/src/obsolete/libeoobsolete.
###############################################################################
noinst_PROGRAMS = t-eobreeder t-eoinclusion t-eoinsertion t-eo t-eofitness \
t-eoproblem t-eobin t-eolottery t-eo2dVector t-eogeneration t-eoEasyEA\
t-eoNonUniform t-eoUniform t-eoRandom t-eoStateAndParser \
t-eoAtomOps t-selectOne t-eoGOpSel \
t-eoVector t-eoCheckpointing t-eoExternalEO t-eoESFull
###############################################################################
t_eoVector_SOURCES = t-eoVector.cpp
t_eoVector_DEPENDENCIES = $(DEPS)
t_eoVector_LDFLAGS = -lm
t_eoVector_LDADD = $(LDADDS)
###############################################################################
t_eoGOpSel_SOURCES = t-eoGOpSel.cpp
t_eoGOpSel_DEPENDENCIES = $(DEPS)
t_eoGOpSel_LDFLAGS = -lm
t_eoGOpSel_LDADD = $(LDADDS)
###############################################################################
t_selectOne_SOURCES = t-selectOne.cpp
t_selectOne_DEPENDENCIES = $(DEPS)
t_selectOne_LDFLAGS = -lm
t_selectOne_LDADD = $(LDADDS)
###############################################################################
t_eoAtomOps_SOURCES = t-eoAtomOps.cpp
t_eoAtomOps_DEPENDENCIES = $(DEPS)
t_eoAtomOps_LDFLAGS = -lm
t_eoAtomOps_LDADD = $(LDADDS)
###############################################################################
#disabled
#t_eoESOps_SOURCES = t-eoESOps.cpp
#t_eoESOps_DEPENDENCIES = $(DEPS)
#t_eoESOps_LDFLAGS = -lm
#t_eoESOps_LDADD = $(LDADDS)
noinst_PROGRAMS = t-eofitness t-eobin t-eoStateAndParser t-eoCheckpointing t-eoExternalEO t-eoESFull
###############################################################################
@ -63,99 +24,18 @@ t_eoESFull_LDADD = $(LDADDS)
###############################################################################
t_eoNonUniform_SOURCES = t-eoNonUniform.cpp
t_eoNonUniform_DEPENDENCIES = $(DEPS)
t_eoNonUniform_LDFLAGS = -lm
t_eoNonUniform_LDADD = $(LDADDS)
###############################################################################
t_eoUniform_SOURCES = t-eoUniform.cpp
t_eoUniform_DEPENDENCIES = $(DEPS)
t_eoUniform_LDFLAGS = -lm
t_eoUniform_LDADD = $(LDADDS)
###############################################################################
t_eoRandom_SOURCES = t-eoRandom.cpp
t_eoRandom_DEPENDENCIES = $(DEPS)
t_eoRandom_LDFLAGS = -lm
t_eoRandom_LDADD = $(LDADDS)
###############################################################################
t_eogeneration_SOURCES = t-eogeneration.cpp
t_eogeneration_DEPENDENCIES = $(DEPS)
t_eogeneration_LDFLAGS = -lm
t_eogeneration_LDADD = $(LDADDS)
###############################################################################
t_eoEasyEA_SOURCES = t-eoEasyEA.cpp binary_value.h
t_eoEasyEA_DEPENDENCIES = $(DEPS)
t_eoEasyEA_LDFLAGS = -lm
t_eoEasyEA_LDADD = $(LDADDS)
###############################################################################
t_eobreeder_SOURCES = t-eobreeder.cpp binary_value.h
t_eobreeder_DEPENDENCIES = $(DEPS)
t_eobreeder_LDFLAGS = -lm
t_eobreeder_LDADD = $(LDADDS)
###############################################################################
t_eoinclusion_SOURCES = t-eoinclusion.cpp
t_eoinclusion_DEPENDENCIES = $(DEPS)
t_eoinclusion_LDFLAGS = -lm
t_eoinclusion_LDADD = $(LDADDS)
###############################################################################
t_eoinsertion_SOURCES = t-eoinsertion.cpp
t_eoinsertion_DEPENDENCIES = $(DEPS)
t_eoinsertion_LDFLAGS = -lm
t_eoinsertion_LDADD = $(LDADDS)
###############################################################################
t_eo_SOURCES = t-eo.cpp
t_eo_DEPENDENCIES = $(DEPS)
t_eo_LDADD = $(LDADDS)
###############################################################################
t_eofitness_SOURCES = t-eofitness.cpp
t_eofitness_DEPENDENCIES = $(DEPS)
t_eofitness_LDADD = $(LDADDS)
###############################################################################
t_eoproblem_SOURCES = t-eoproblem.cpp
t_eoproblem_LDFLAGS = -lm
###############################################################################
t_eobin_SOURCES = t-eobin.cpp
t_eobin_DEPENDENCIES = $(DEPS)
t_eobin_LDADD = $(LDADDS)
###############################################################################
t_eolottery_SOURCES = t-eolottery.cpp
t_eolottery_DEPENDENCIES = $(DEPS)
t_eolottery_LDFLAGS = -lm
t_eolottery_LDADD = $(LDADDS)
###############################################################################
t_eo2dVector_SOURCES = t-eo2dVector.cc
t_eo2dVector_DEPENDENCIES = $(DEPS)
t_eo2dVector_LDFLAGS = -lm
t_eo2dVector_LDADD = $(LDADDS)
###############################################################################
t_eoStateAndParser_SOURCES = t-eoStateAndParser.cpp
t_eoStateAndParser_DEPENDENCIES = $(DEPS)
t_eoStateAndParser_LDFLAGS = -lm

View file

@ -1,4 +1,4 @@
#include <eoFixedLength.h>
#include <vector>
//-----------------------------------------------------------------------------
@ -7,7 +7,7 @@
@param _ind A floatingpoint vector
*/
double real_value(const eoFixedLength<double, double>& _ind)
double real_value(const std::vector<double>& _ind)
{
double sum = 0; /* compute in double format, even if return a float */
for (unsigned i = 0; i < _ind.size(); i++)

View file

@ -0,0 +1,26 @@
#include <eoBaseFunctions.h>
#include <iostream>
using namespace std;
struct eo1 : public eoProcedure<void>
{
void operator()(void) {}
};
struct eo2 : public eoProcedure<int>
{
int operator()(void) { return 1; }
};
int main()
{
eo1 _1; _1();
eo2 _2;
int i = _2();
cout << i << '\n';
return i;
}

View file

@ -18,12 +18,11 @@
#include <ga/eoBin.h>
#include <utils/eoParser.h>
#include <utils/eoState.h>
#include <eoGenContinue.h>
//-----------------------------------------------------------------------------
// include package checkpointing
#include <utils/checkpointing>
#include <eoGenTerm.h>
struct Dummy : public EO<double>
{
@ -74,7 +73,7 @@ int the_main(int argc, char **argv)
eoDummyPop pop;
eoGenTerm<EoType> genTerm(5); // run for 5 generations
eoGenContinue<EoType> genTerm(5); // run for 5 generations
eoCheckPoint<EoType> checkpoint(genTerm);
// The algorithm will now quit after five generations

View file

@ -9,20 +9,11 @@
#include <iostream>
#include <iterator>
#include <stdexcept>
#include <time.h>
using namespace std;
#include <utils/eoParser.h>
#include <utils/eoState.h>
#include <utils/eoStat.h>
#include <utils/eoFileMonitor.h>
// population
#include <eoPop.h>
// evaluation specific
#include <eoEvalFuncPtr.h>
#include <eo>
// representation specific
#include <es/evolution_strategies>
@ -31,7 +22,7 @@ using namespace std;
// Now the main
///////////////
typedef double FitT;
typedef eoMinimizingFitness FitT;
template <class EOT>
void runAlgorithm(EOT, eoParser& _parser, eoState& _state, eoEsObjectiveBounds& _bounds);
@ -45,9 +36,9 @@ main(int argc, char *argv[])
eoValueParam<uint32>& seed = parser.createParam(static_cast<uint32>(time(0)), "seed", "Random number seed");
eoValueParam<string>& load_name = parser.createParam(string(), "Load","Load a state file",'L');
eoValueParam<string>& save_name = parser.createParam(string(), "Save","Saves a state file",'S');
eoValueParam<bool>& stdevs = parser.createParam(true, "Stdev", "Use adaptive mutation rates", 's');
eoValueParam<bool>& corr = parser.createParam(true, "Correl", "Use correlated mutations", 'c');
eoValueParam<unsigned>& chromSize = parser.createParam(unsigned(1), "ChromSize", "Number of chromosomes", 'n');
eoValueParam<bool>& stdevs = parser.createParam(false, "Stdev", "Use adaptive mutation rates", 's');
eoValueParam<bool>& corr = parser.createParam(false, "Correl", "Use correlated mutations", 'c');
eoValueParam<unsigned>& chromSize = parser.createParam(unsigned(50), "ChromSize", "Number of chromosomes", 'n');
eoValueParam<double>& minimum = parser.createParam(-1.e5, "Min", "Minimum for Objective Variables", 'l');
eoValueParam<double>& maximum = parser.createParam(1.e5, "Max", "Maximum for Objective Variables", 'h');
@ -57,7 +48,9 @@ main(int argc, char *argv[])
if (!load_name.value().empty())
{ // load the parser. This is only neccessary when the user wants to
// be able to change the parameters in the state file by hand.
// be able to change the parameters in the state file by hand
// Note that only parameters inserted in the parser at this point
// will be loaded!.
state.load(load_name.value()); // load the parser
}
@ -94,15 +87,15 @@ template <class EOT>
void runAlgorithm(EOT, eoParser& _parser, eoState& _state, eoEsObjectiveBounds& _bounds)
{
// evaluation
eoEvalFuncPtr<eoFixedLength<FitT, double> > eval( real_value );
eoEvalFuncPtr<EOT, double, const vector<double>&> eval( real_value );
// population parameters, unfortunately these can not be altered in the state file
eoValueParam<unsigned> mu = _parser.createParam(unsigned(50), "mu","Size of the population");
eoValueParam<unsigned>lambda = _parser.createParam(unsigned(250), "lambda", "No. of children to produce");
eoValueParam<float>lambda_rate = _parser.createParam(float(7.0), "lambda_rate", "Factor of children to produce");
if (mu.value() > lambda.value())
if (lambda_rate.value() < 1.0f)
{
throw logic_error("Mu must be smaller than lambda in a comma strategy");
throw logic_error("lambda_rate must be larger than 1 in a comma strategy");
}
// Initialization
@ -112,7 +105,7 @@ void runAlgorithm(EOT, eoParser& _parser, eoState& _state, eoEsObjectiveBounds&
_state.registerObject(pop);
// evaluate initial population
eval.range(pop.begin(), pop.end());
apply<EOT>(eval, pop);
// Ok, time to set up the algorithm
// Proxy for the mutation parameters
@ -122,29 +115,20 @@ void runAlgorithm(EOT, eoParser& _parser, eoState& _state, eoEsObjectiveBounds&
// monitoring, statistics etc.
eoAverageStat<EOT> average;
eoFileMonitor monitor("test.csv");
eoStdoutMonitor monitor;
monitor.add(average);
// Okok, I'm lazy, here's the algorithm defined inline
eoGenContinue<EOT> cnt(2000);
eoCheckPoint<EOT> checkpoint(cnt);
checkpoint.add(monitor);
checkpoint.add(average);
for (unsigned i = 0; i < 20; ++i)
{
pop.resize(pop.size() + lambda.value());
for (unsigned j = mu.value(); j < pop.size(); ++j)
{
pop[j] = pop[rng.random(mu.value())];
mutate(pop[j]);
eval(pop[j]);
}
eoProportionalGOpSel<EOT> opSel;
opSel.addOp(mutate, 1.0);
// comma strategy
std::sort(pop.begin() + mu.value(), pop.end());
copy(pop.begin() + mu.value(), pop.begin() + 2 * mu.value(), pop.begin());
pop.resize(mu.value());
average(pop);
monitor();
}
eoEvolutionStrategy<EOT> es(checkpoint, eval, opSel, lambda_rate.value(), eoEvolutionStrategy<EOT>::comma_strategy());
es(pop);
}

View file

@ -55,7 +55,7 @@ UserDefStruct RandomStruct()
// reading and writing
void UserDefMutate(UserDefStruct& a)
bool UserDefMutate(UserDefStruct& a)
{
cout << "UserDefMutate\n";
a = RandomStruct(); // just for testing
@ -64,9 +64,10 @@ void UserDefMutate(UserDefStruct& a)
a.d = UserDefStruct::test;
else
a.d = UserDefStruct::another;
return true;
}
void UserDefBinCrossover(UserDefStruct& a, const UserDefStruct& b)
bool UserDefBinCrossover(UserDefStruct& a, const UserDefStruct& b)
{
cout << "UserDefBinCrossover\n";
@ -78,9 +79,10 @@ void UserDefBinCrossover(UserDefStruct& a, const UserDefStruct& b)
a.c = b.c;
if (rng.flip(0.5))
a.d = b.d;
return true;
}
void UserDefQuadCrossover(UserDefStruct& a, UserDefStruct& b)
bool UserDefQuadCrossover(UserDefStruct& a, UserDefStruct& b)
{
cout << "UserDefQuadCrossover\n";
if (rng.flip(0.5))
@ -91,6 +93,8 @@ void UserDefQuadCrossover(UserDefStruct& a, UserDefStruct& b)
swap(a.c, b.c);
if (rng.flip(0.5))
swap(a.d, b.d);
return true;
}
float UserDefEvalFunc(const UserDefStruct& a)
@ -112,8 +116,10 @@ int main()
// eoExternalEvalFunc<FitnessType, External> eval(UserDefEvalFunc);
EoType eo1 = init();
EoType eo2 = init();
EoType eo1;
init(eo1);
EoType eo2;
init(eo2);
cout << "before mutation " << eo1 << '\n';
mutate(eo1);

53
eo/test/t-eoFunctor.cpp Normal file
View file

@ -0,0 +1,53 @@
#include <eoInit.h>
#include <eoCounter.h>
void f(eoInit<int>& func)
{
int i;
func(i);
}
class Tester : public eoInit<int>
{
public :
void operator()(int& i)
{
i=1;
}
};
#include <iostream>
#include <eoTranspose.h>
#include <eoFixedLength.h>
#include <eoVariableLength.h>
using namespace std;
int main(void)
{
Tester test;
eoFunctorStore store;
/// make a counter and store it in 'store'
eoInit<int>& cntr = make_counter(functor_category(test), test, store);
eoUnaryFunctorCounter<eoInit<int> > cntr2(test);
f(cntr);
f(cntr2);
f(cntr2);
f(test);
typedef eoVariableLength<double, int> EoType;
EoType eo;
eo.push_back(1);
eo.push_back(2);
eoTranspose<EoType> transpose;
transpose(eo);
return 1;
}

View file

@ -23,7 +23,6 @@
// include package checkpointing
#include <utils/checkpointing>
#include <eoGenTerm.h>
struct Dummy : public EO<double>
{

View file

@ -27,13 +27,15 @@
#include <strstream> // ostrstream, istrstream
#include <eo> // eoBin
#include "binary_value.h"
//-----------------------------------------------------------------------------
typedef eoBin<float> Chrom;
//-----------------------------------------------------------------------------
main()
void main_function()
{
const unsigned SIZE = 8;
unsigned i, j;
@ -52,19 +54,22 @@ main()
cout << "chrom: " << chrom << endl
<< "chrom2: " << chrom2 << endl;
ostrstream os;
char buff[1024];
ostrstream os(buff, 1024);
os << chrom;
istrstream is(os.str());
is >> chrom2;
cout << "chrom: " << chrom << endl
<< "chrom2: " << chrom2 << endl;
cout << "\nTesting reading, writing\n";
cout << "chrom: " << chrom << "\nchrom2: " << chrom2 << '\n';
fill(chrom.begin(), chrom.end(), false);
cout << "--------------------------------------------------"
<< endl << "eoMonOp's aplied to .......... " << chrom << endl;
eoBinRandom<Chrom> random;
eoInitFixedLength<Chrom, boolean_generator>
random(chrom.size(), boolean_generator());
random(chrom);
cout << "after eoBinRandom ............ " << chrom << endl;
@ -120,16 +125,41 @@ main()
cout << "eoBinGxOver(" << i << ", " << j << ") ..... "
<< chrom << " " << chrom2 << endl;
}
for (double r = 0.1; r < 1.0; r += 0.1)
{
eoUniformXOver<Chrom> uxover(r);
fill(chrom.begin(), chrom.end(), false);
fill(chrom2.begin(), chrom2.end(), true);
uxover(chrom, chrom2);
cout << "eoBinUxOver(" << r << ") ...... "
<< chrom << " " << chrom2 << endl;
}
// test SGA algorithm
eoGenContinue<Chrom> continuator1(50);
eoFitContinue<Chrom> continuator2(65535.f);
eoCombinedContinue<Chrom> continuator(continuator1, continuator2);
eoCheckPoint<Chrom> checkpoint(continuator);
eoStdoutMonitor monitor;
checkpoint.add(monitor);
eoSecondMomentStats<Chrom> stats;
monitor.add(stats);
checkpoint.add(stats);
eoProportional<Chrom> select;
eoEvalFuncPtr<Chrom> eval(binary_value);
eoSGA<Chrom> sga(checkpoint, bitflip, 0.1f, xover, 0.8f, select, eval);
eoInitFixedLength<Chrom, boolean_generator>
init(16, boolean_generator());
eoPop<Chrom> pop(100, init);
apply<Chrom>(eval, pop);
//for_each(pop.begin(), pop.end(), eval);
sga(pop);
pop.sort();
cout << "\nBest: " << pop[0].fitness() << '\n';
/*
@ -149,8 +179,31 @@ main()
mbOp( chrom, chrom2 );
cout << "after multiBinOp .............. " << chrom << " " << chrom2 <<endl;
*/
return 0;
}
//-----------------------------------------------------------------------------
#ifdef _MSC_VER
#include <crtdbg.h>
#endif
int main()
{
#ifdef _MSC_VER
// rng.reseed(42);
int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);
flag |= _CRTDBG_LEAK_CHECK_DF;
_CrtSetDbgFlag(flag);
// _CrtSetBreakAlloc(100);
#endif
try
{
main_function();
}
catch(exception& e)
{
cout << "Exception: " << e.what() << '\n';
}
return 1;
}

View file

@ -75,7 +75,7 @@ main()
breeder(pop);
// reevaluation of fitness
for_each(pop.begin(), pop.end(), eval);
for_each(pop.begin(), pop.end(), BinaryValue());
cout << "new population:" << endl;
for (i = 0; i < pop.size(); ++i)

View file

@ -1,175 +1,91 @@
//-----------------------------------------------------------------------------
// t-eofitness.cpp
// (c) GeNeura Team 1998
//-----------------------------------------------------------------------------
#include <time.h> // time
#include <stdlib.h> // srand, rand
#include <iostream> // cout
#include <eo> // eoFitness
#include <eoScalarFitness.h>
using namespace std;
//-----------------------------------------------------------------------------
class eoFloat: public eoFitness
template <class Fitness>
int test_fitness(Fitness a, Fitness b)
{
// srand(time(0));
public:
eoFloat(const float x) { fitness = x; }
eoFloat(const int x) { fitness = static_cast<float>(x); }
bool operator<(const eoFitness& other) const
{
const eoFloat& x = (const eoFloat&) other;
return fitness < x.fitness;
}
operator float() const
{
return fitness;
}
void printOn(ostream& os) const
{
os << fitness;
}
void readFrom(istream& is)
{
is >> fitness;
}
private:
float fitness;
};
//-----------------------------------------------------------------------------
int main()
{
srand(time(0));
eoFloat a = static_cast<float>(rand()) / RAND_MAX,
b = static_cast<float>(rand()) / RAND_MAX;
// Fitness a = aval; //static_cast<double>(rand()) / RAND_MAX;
// Fitness b = bval; //static_cast<double>(rand()) / RAND_MAX;
cout.precision(2);
unsigned repeat = 2;
while (repeat--)
{
cout << "------------------------------------------------------" << endl;
cout << "testing < ";
if (a < b)
cout << a << " < " << b << " is true" << endl;
else
cout << a << " < " << b << " is false" <<endl;
cout << "testing > ";
if (a > b)
cout << a << " > " << b << " is true" << endl;
else
cout << a << " > " << b << " is false" <<endl;
cout << "testing == ";
if (a == b)
cout << a << " == " << b << " is true" << endl;
else
cout << a << " == " << b << " is false" <<endl;
cout << "testing != ";
if (a != b)
cout << a << " != " << b << " is true" << endl;
else
cout << a << " != " << b << " is false" <<endl;
a = b;
}
return 1;
}
int main()
{
cout << "Testing minimizing fitness with 1 and 2" << endl;
cout << "------------------------------------------------------" << endl;
eoMinimizingFitness a = 1;
eoMinimizingFitness b = 2;
test_fitness(a, b);
cout << "Testing minimizing fitness with 2 and 1" << endl;
cout << "------------------------------------------------------" << endl;
test_fitness(b, a);
cout << "Testing maximizing fitness with 1 and 2" << endl;
cout << "------------------------------------------------------" << endl;
eoMaximizingFitness a1 = 1;
eoMaximizingFitness b1 = 2;
test_fitness(a1,b1);
cout << "Testing maximizing fitness with 2 and 1" << endl;
cout << "------------------------------------------------------" << endl;
test_fitness(b1,a1);
return 1;
}
//-----------------------------------------------------------------------------