Make sure uint32_t is defined correctly in eoRNG.h and use it where
appropriate.
This commit is contained in:
parent
462fbaad66
commit
6e0c4a7264
13 changed files with 238 additions and 220 deletions
|
|
@ -5,10 +5,10 @@
|
|||
#pragma warning(disable:4786)
|
||||
#endif
|
||||
|
||||
#include <stdexcept> // runtime_error
|
||||
#include <stdexcept> // runtime_error
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// tt.cpp:
|
||||
// tt.cpp:
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
|
@ -40,18 +40,18 @@ public :
|
|||
|
||||
int the_main(int argc, char **argv)
|
||||
{ // ok, we have a command line parser and a state
|
||||
|
||||
|
||||
typedef eoBit<float> Chrom;
|
||||
|
||||
eoParser parser(argc, argv);
|
||||
|
||||
|
||||
// Define Parameters
|
||||
eoValueParam<double> rate(0.01, "mutationRatePerBit", "Initial value for mutation rate per bit");
|
||||
eoValueParam<double> rate(0.01, "mutationRatePerBit", "Initial value for mutation rate per bit");
|
||||
eoValueParam<double> factor(0.99, "mutationFactor", "Decrease factor for mutation rate");
|
||||
eoValueParam<uint32> seed(time(0), "seed", "Random number seed");
|
||||
eoValueParam<uint32_t> seed(time(0), "seed", "Random number seed");
|
||||
eoValueParam<std::string> load_name("", "Load","Load",'L');
|
||||
eoValueParam<std::string> save_name("", "Save","Save",'S');
|
||||
|
||||
|
||||
// Register them
|
||||
parser.processParam(rate, "Genetic Operators");
|
||||
parser.processParam(factor, "Genetic Operators");
|
||||
|
|
@ -61,27 +61,27 @@ int the_main(int argc, char **argv)
|
|||
|
||||
eoState state;
|
||||
state.registerObject(parser);
|
||||
|
||||
|
||||
if (load_name.value() != "")
|
||||
{ // load the parser. This is only neccessary when the user wants to
|
||||
{ // load the parser. This is only neccessary when the user wants to
|
||||
// be able to change the parameters in the state file by hand.
|
||||
state.load(load_name.value()); // load the parser
|
||||
}
|
||||
|
||||
|
||||
// Create the algorithm here
|
||||
typedef Dummy EoType;
|
||||
|
||||
eoDummyPop pop;
|
||||
|
||||
|
||||
eoGenContinue<EoType> genTerm(5); // run for 5 generations
|
||||
|
||||
eoCheckPoint<EoType> checkpoint(genTerm);
|
||||
eoCheckPoint<EoType> checkpoint(genTerm);
|
||||
// The algorithm will now quit after five generations
|
||||
|
||||
// Create a counter parameter
|
||||
eoValueParam<unsigned> generationCounter(0, "Generation");
|
||||
|
||||
// Create an incrementor (wich is an eoUpdater). Note that the
|
||||
|
||||
// Create an incrementor (wich is an eoUpdater). Note that the
|
||||
// Parameter's value is passed by reference, so every time the incrementer increments,
|
||||
// the data in generationCounter will change.
|
||||
eoIncrementor<unsigned> increment(generationCounter.value());
|
||||
|
|
@ -91,7 +91,7 @@ int the_main(int argc, char **argv)
|
|||
|
||||
// The file monitor will print parameters to a comma seperated file
|
||||
eoFileMonitor monitor("monitor.csv");
|
||||
|
||||
|
||||
// the checkpoint mechanism can handle multiple monitors
|
||||
checkpoint.add(monitor);
|
||||
|
||||
|
|
@ -108,9 +108,9 @@ int the_main(int argc, char **argv)
|
|||
monitor.add(stats);
|
||||
|
||||
// save state every third generation
|
||||
eoCountedStateSaver stateSaver1(3, state, "generation");
|
||||
// save state every 2 seconds
|
||||
eoTimedStateSaver stateSaver2(2, state, "time");
|
||||
eoCountedStateSaver stateSaver1(3, state, "generation");
|
||||
// save state every 2 seconds
|
||||
eoTimedStateSaver stateSaver2(2, state, "time");
|
||||
|
||||
// And add the two savers to the checkpoint
|
||||
checkpoint.add(stateSaver1);
|
||||
|
|
@ -138,7 +138,7 @@ int the_main(int argc, char **argv)
|
|||
// initialize rng and population
|
||||
|
||||
rng.reseed(seed.value());
|
||||
|
||||
|
||||
pop.resize(2);
|
||||
|
||||
pop[0].fitness(1);
|
||||
|
|
@ -148,7 +148,7 @@ int the_main(int argc, char **argv)
|
|||
while(checkpoint(pop))
|
||||
{
|
||||
pop[0].fitness(pop[0].fitness() + 1);
|
||||
|
||||
|
||||
time_t now = time(0);
|
||||
|
||||
while (time(0) == now) {} // wait a second to test timed saver
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable:4786)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
|
@ -20,20 +20,21 @@ using namespace std;
|
|||
|
||||
#include "real_value.h" // the sphere fitness
|
||||
|
||||
// Now the main
|
||||
///////////////
|
||||
// Now the main
|
||||
///////////////
|
||||
typedef eoMinimizingFitness FitT;
|
||||
|
||||
template <class EOT>
|
||||
void runAlgorithm(EOT, eoParser& _parser, eoState& _state, eoRealVectorBounds& _bounds, eoValueParam<string> _load_name);
|
||||
|
||||
int main_function(int argc, char *argv[])
|
||||
|
||||
int main_function(int argc, char *argv[])
|
||||
{
|
||||
// Create the command-line parser
|
||||
eoParser parser( argc, argv, "Basic EA for vector<float> with adaptive mutations");
|
||||
|
||||
// Define Parameters and load them
|
||||
eoValueParam<uint32>& seed = parser.createParam(static_cast<uint32>(time(0)), "seed", "Random number seed");
|
||||
eoValueParam<uint32_t>& seed = parser.createParam(static_cast<uint32_t>(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(false, "Stdev", "Use adaptive mutation rates", 's');
|
||||
|
|
@ -47,7 +48,7 @@ int main_function(int argc, char *argv[])
|
|||
rng.reseed(seed.value());
|
||||
|
||||
if (!load_name.value().empty())
|
||||
{ // load the parser. This is only neccessary when the user wants to
|
||||
{ // load the parser. This is only neccessary when the user wants to
|
||||
// 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!.
|
||||
|
|
@ -57,7 +58,7 @@ int main_function(int argc, char *argv[])
|
|||
state.registerObject(rng);
|
||||
|
||||
eoRealVectorBounds bounds(chromSize.value(), minimum.value(), maximum.value());
|
||||
|
||||
|
||||
// Run the appropriate algorithm
|
||||
if (stdevs.value() == false && corr.value() == false)
|
||||
{
|
||||
|
|
@ -67,7 +68,7 @@ int main_function(int argc, char *argv[])
|
|||
{
|
||||
runAlgorithm(eoEsFull<FitT>(),parser, state, bounds, load_name);
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
runAlgorithm(eoEsStdev<FitT>(), parser, state, bounds, load_name);
|
||||
}
|
||||
|
|
@ -80,11 +81,11 @@ int main_function(int argc, char *argv[])
|
|||
state.save(file_name);
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// A main that catches the exceptions
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
|
|
@ -94,7 +95,7 @@ int main(int argc, char **argv)
|
|||
_CrtSetDbgFlag(flag);
|
||||
// _CrtSetBreakAlloc(100);
|
||||
#endif
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
main_function(argc, argv);
|
||||
|
|
@ -103,7 +104,7 @@ int main(int argc, char **argv)
|
|||
{
|
||||
std::cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -124,7 +125,7 @@ void runAlgorithm(EOT, eoParser& _parser, eoState& _state, eoRealVectorBounds& _
|
|||
|
||||
// Initialization
|
||||
eoEsChromInit<EOT> init(_bounds);
|
||||
|
||||
|
||||
// State takes ownership of pop because it needs to save it in caller
|
||||
eoPop<EOT>& pop = _state.takeOwnership(eoPop<EOT>(mu.value(), init));
|
||||
|
||||
|
|
@ -158,8 +159,8 @@ void runAlgorithm(EOT, eoParser& _parser, eoState& _state, eoRealVectorBounds& _
|
|||
checkpoint.add(average);
|
||||
|
||||
// only mutation (== with rate 1.0)
|
||||
eoMonGenOp<EOT> op(mutate);
|
||||
|
||||
eoMonGenOp<EOT> op(mutate);
|
||||
|
||||
// the selection: sequential selection
|
||||
eoSequentialSelect<EOT> select;
|
||||
// the general breeder (lambda is a rate -> true)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// eoGenOp.cpp
|
||||
// (c) Maarten Keijzer and Marc Schoenauer, 2001
|
||||
/*
|
||||
/*
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
|
|
@ -126,7 +126,7 @@ class one2threeOp : public eoGenOp<EOT> // :-)
|
|||
|
||||
class two2oneOp : public eoGenOp<EOT> // :-)
|
||||
{
|
||||
public:
|
||||
public:
|
||||
unsigned max_production(void) { return 1; }
|
||||
|
||||
void apply(eoPopulator<EOT>& _plop)
|
||||
|
|
@ -141,7 +141,7 @@ class two2oneOp : public eoGenOp<EOT> // :-)
|
|||
|
||||
class three2threeOp : public eoGenOp<EOT> // :-)
|
||||
{
|
||||
public:
|
||||
public:
|
||||
unsigned max_production(void) { return 3; }
|
||||
|
||||
void apply(eoPopulator<EOT>& _plop)
|
||||
|
|
@ -182,7 +182,7 @@ void init(eoPop<Dummy> & _pop, unsigned _pSize)
|
|||
char s[255];
|
||||
std::ostrstream os(s, 254);
|
||||
#endif
|
||||
|
||||
|
||||
os << i << std::ends;
|
||||
_pop[i] = Dummy(os.str());
|
||||
_pop[i].fitness(i);
|
||||
|
|
@ -197,7 +197,7 @@ int the_main(int argc, char **argv)
|
|||
eoValueParam<unsigned int> parentSizeParam = parser.createParam(unsigned(10), "parentSize", "Parent size",'P');
|
||||
pSize = parentSizeParam.value(); // global variable
|
||||
|
||||
eoValueParam<uint32> seedParam(time(0), "seed", "Random number seed", 'S');
|
||||
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
|
||||
parser.processParam( seedParam );
|
||||
eo::rng.reseed(seedParam.value());
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
#pragma warning(disable:4786)
|
||||
#endif
|
||||
|
||||
#include <stdexcept> // runtime_error
|
||||
#include <stdexcept> // runtime_error
|
||||
|
||||
// general
|
||||
#include <eo>
|
||||
|
|
@ -52,7 +52,7 @@ void testSelectMany(eoSelect<EOT> & _select, std::string _name)
|
|||
{
|
||||
unsigned i;
|
||||
std::cout << "\n\n" << fitnessType + _name << std::endl;
|
||||
std::cout << "===============\n";
|
||||
std::cout << "===============\n";
|
||||
|
||||
eoDummyPop parents(parentsOrg);
|
||||
eoDummyPop offspring(0);
|
||||
|
|
@ -93,7 +93,7 @@ void testSelectOne(eoSelectOne<EOT> & _select, eoHowMany & _offspringRate,
|
|||
//-----------------------------------------------------------------------------
|
||||
|
||||
int the_main(int argc, char **argv)
|
||||
{
|
||||
{
|
||||
eoParser parser(argc, argv);
|
||||
eoValueParam<unsigned> parentSizeParam = parser.createParam(unsigned(10), "parentSize", "Parent size",'P');
|
||||
pSize = parentSizeParam.value(); // global variable
|
||||
|
|
@ -129,7 +129,7 @@ eoValueParam<unsigned> tournamentSizeParam = parser.createParam(unsigned(2), "to
|
|||
|
||||
// hard-coded directory name ...
|
||||
system("mkdir ResSelect");
|
||||
std::cout << "Testing the Selections\nParents size = " << pSize
|
||||
std::cout << "Testing the Selections\nParents size = " << pSize
|
||||
<< ", offspring rate = " << oRate;
|
||||
std::cout << " and putting rsulting files in dir ResSelect" << std::endl;
|
||||
|
||||
|
|
@ -150,13 +150,14 @@ eoValueParam<unsigned> tournamentSizeParam = parser.createParam(unsigned(2), "to
|
|||
parentsOrg[i].fitness(i);
|
||||
parentsOrg[pSize-1].fitness(10*pSize);
|
||||
}
|
||||
else
|
||||
else
|
||||
throw std::runtime_error("Invalid fitness Type"+fitnessType);
|
||||
|
||||
std::cout << "Initial parents (odd)\n" << parentsOrg << std::endl;
|
||||
|
||||
// random seed
|
||||
eoValueParam<uint32>& seedParam = parser.createParam(uint32(0), "seed", "Random number seed", 'S');
|
||||
eoValueParam<uint32_t>& seedParam = parser.createParam(uint32_t(0), "seed",
|
||||
"Random number seed", 'S');
|
||||
if (seedParam.value() == 0)
|
||||
seedParam.value() = time(0);
|
||||
rng.reseed(seedParam.value());
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ void testSelectMany(eoSelect<EOT> & _select, std::string _name)
|
|||
{
|
||||
unsigned i;
|
||||
std::cout << "\n\n" << fitnessType + _name << std::endl;
|
||||
std::cout << "===============\n";
|
||||
std::cout << "===============\n";
|
||||
|
||||
eoDummyPop parents(parentsOrg);
|
||||
eoDummyPop offspring(0);
|
||||
|
|
@ -117,11 +117,11 @@ void testSelectOne(eoSelectOne<EOT> & _select, eoHowMany & _offspringRate,
|
|||
//-----------------------------------------------------------------------------
|
||||
|
||||
int the_main(int argc, char **argv)
|
||||
{
|
||||
{
|
||||
eoParser parser(argc, argv);
|
||||
|
||||
// random seed
|
||||
eoValueParam<uint32>& seedParam = parser.createParam(uint32(0), "seed", "Random number seed", 'S');
|
||||
eoValueParam<uint32_t>& seedParam = parser.createParam(uint32_t(0), "seed", "Random number seed", 'S');
|
||||
if (seedParam.value() == 0)
|
||||
seedParam.value() = time(0);
|
||||
rng.reseed(seedParam.value());
|
||||
|
|
@ -158,7 +158,7 @@ int the_main(int argc, char **argv)
|
|||
for (i=0; i<peakNumber; i++)
|
||||
nbIndiPerPeak[i] = pSize/peakNumber;
|
||||
}
|
||||
else // parameters passed by user
|
||||
else // parameters passed by user
|
||||
if (peakParam.second.size() != peakNumber)
|
||||
{
|
||||
std::cerr << "ERROR, not enough nb of indis per peaks" << std::endl;
|
||||
|
|
@ -174,7 +174,7 @@ int the_main(int argc, char **argv)
|
|||
}
|
||||
|
||||
// compute exact total
|
||||
sum = 0;
|
||||
sum = 0;
|
||||
for (i=0; i<peakNumber; i++)
|
||||
sum += nbIndiPerPeak[i];
|
||||
if (sum != pSize)
|
||||
|
|
@ -182,8 +182,8 @@ int the_main(int argc, char **argv)
|
|||
pSize = pSizeParam.value() = sum;
|
||||
std::cerr << "WARNING, adjusting pSize to " << pSize << std::endl;
|
||||
}
|
||||
|
||||
make_help(parser);
|
||||
|
||||
make_help(parser);
|
||||
|
||||
// hard-coded directory name ...
|
||||
std::cout << "Testing the Sharing\n";
|
||||
|
|
|
|||
|
|
@ -5,10 +5,10 @@
|
|||
#pragma warning(disable:4786)
|
||||
#endif
|
||||
|
||||
#include <stdexcept> // runtime_error
|
||||
#include <stdexcept> // runtime_error
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// tt.cpp:
|
||||
// tt.cpp:
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
|
@ -36,16 +36,16 @@ struct Dummy : public EO<double>
|
|||
|
||||
int the_main(int argc, char **argv)
|
||||
{ // ok, we have a command line parser and a state
|
||||
|
||||
|
||||
typedef eoBit<float> Chrom;
|
||||
|
||||
eoParser parser(argc, argv);
|
||||
|
||||
|
||||
// Define Parameters
|
||||
eoValueParam<unsigned int> dimParam((unsigned int)(5), "dimension", "dimension");
|
||||
eoValueParam<double> rate(0.01, "mutationRatePerBit", "Initial value for mutation rate per bit");
|
||||
eoValueParam<unsigned int> dimParam((unsigned int)(5), "dimension", "dimension");
|
||||
eoValueParam<double> rate(0.01, "mutationRatePerBit", "Initial value for mutation rate per bit");
|
||||
eoValueParam<double> factor(0.99, "mutationFactor", "Decrease factor for mutation rate");
|
||||
eoValueParam<uint32> seed(time(0), "seed", "Random number seed");
|
||||
eoValueParam<uint32_t> seed(time(0), "seed", "Random number seed");
|
||||
// test if user entered or if default value used
|
||||
if (parser.isItThere(seed))
|
||||
std::cout << "YES\n";
|
||||
|
|
@ -55,7 +55,7 @@ int the_main(int argc, char **argv)
|
|||
eoValueParam<std::string> load_name("", "Load","Load",'L');
|
||||
eoValueParam<std::string> save_name("", "Save","Save",'S');
|
||||
|
||||
|
||||
|
||||
// Register them
|
||||
parser.processParam(dimParam, "Genetic Operators");
|
||||
parser.processParam(rate, "Genetic Operators");
|
||||
|
|
@ -73,16 +73,16 @@ int the_main(int argc, char **argv)
|
|||
|
||||
eoState state;
|
||||
state.registerObject(parser);
|
||||
|
||||
|
||||
|
||||
if (load_name.value() != "")
|
||||
{ // load the parser. This is only neccessary when the user wants to
|
||||
{ // load the parser. This is only neccessary when the user wants to
|
||||
// be able to change the parameters in the state file by hand.
|
||||
state.load(load_name.value()); // load the parser
|
||||
}
|
||||
|
||||
|
||||
// Create the algorithm here
|
||||
|
||||
|
||||
// Register the algorithm
|
||||
state.registerObject(rng);
|
||||
//state.registerObject(pop);
|
||||
|
|
|
|||
Reference in a new issue