cleanup, prepare vecSigmaInit change

This commit is contained in:
kuepper 2005-10-10 21:42:31 +00:00
commit 4510b6d712
4 changed files with 126 additions and 118 deletions

View file

@ -4,7 +4,7 @@
clean up the code considerably. Assume availability of sstream and limits.
* releases 0.9.3... (latest release is 0.9.3zz, 1. Oct. 2005)
* release 0.9.3z.1 (1. Oct. 2005)
- Support gcc-3.4 and gcc.4.x.
- Provide full automake/autoconf/configure support.

View file

@ -1,33 +1,27 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
/* (c) Marc Schoenauer, Maarten Keijzer and GeNeura Team, 2000
//-----------------------------------------------------------------------------
// eoParser.h
// (c) Marc Schoenauer, Maarten Keijzer and GeNeura Team, 2000
/*
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
version 2 of the License, or (at your option) any later version.
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 version 2 of the License, or (at your option) any
later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
This library is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
You should have received a copy of the GNU Lesser General Public License along
with this library; if not, write to the Free Software Foundation, Inc., 59
Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
Marc.Schoenauer@polytechnique.fr
mkeijzer@dhi.dk
*/
//-----------------------------------------------------------------------------
/**
CVS Info: $Date: 2005-09-28 21:49:26 $ $Version$ $Author: kuepper $
Contact: http://eodev.sourceforge.net
todos@geneura.ugr.es, http://geneura.ugr.es
Marc.Schoenauer@polytechnique.fr
mkeijzer@dhi.dk
*/
#ifndef eoParser_h
#define eoParser_h
#ifndef EO_PARSER_H
#define EO_PARSER_H
#include <map>
#include <sstream>
@ -37,10 +31,11 @@ CVS Info: $Date: 2005-09-28 21:49:26 $ $Version$ $Author: kuepper $
#include "eoObject.h"
#include "eoPersistent.h"
/**
eoParameterLoader is an abstract class that can be used as a base for your own
parameter loading and saving. The command line parser eoParser is derived from
this class.
/** Parameter saving and loading
eoParameterLoader is an abstract class that can be used as a base for your own
parameter loading and saving. The command line parser eoParser is derived from
this class.
*/
class eoParameterLoader
{
@ -49,11 +44,10 @@ public :
/** Need a virtual destructor */
virtual ~eoParameterLoader();
/**
* processParam is used to register a parameter and set its value if it is known
*
* @param param the parameter to process
* @param section the section where this parameter belongs
/** Register a parameter and set its value if it is known
@param param the parameter to process
@param section the section where this parameter belongs
*/
virtual void processParam(eoParam& param, std::string section = "") = 0;
@ -147,11 +141,12 @@ public:
std::string ProgramName() { return programName; }
/**
* checks if _param has been actually entered by the user
*/
virtual bool isItThere(eoParam& _param) const
{ return getValue(_param).first; }
/** Has param been entered by user?
Checks if _param has been actually entered by the user
*/
virtual bool isItThere(eoParam& _param) const
{ return getValue(_param).first; }
/**
* get a handle on a param from its longName
@ -278,4 +273,15 @@ private:
};
#endif
#endif // EO_PARSER_H
// Local Variables:
// coding: iso-8859-1
// mode:C++
// c-file-style: "Stroustrup"
// comment-column: 35
// fill-column: 80
// End:

View file

@ -54,6 +54,9 @@ EXTRA_DIST = run_tests
# extra flags for specific targets
t_eoVirus_CXXFLAGS = $(AM_CXXFLAGS) -I$(top_srcdir)/contrib
t_MGE_CXXFLAGS = -I$(top_srcdir)/contrib/MGE
t_MGE1bit_CXXFLAGS = -I$(top_srcdir)/contrib/MGE
t_MGE_control_CXXFLAGS = -I$(top_srcdir)/contrib/MGE
# Specify source-files,
# otherwise automake/make looks for C sources
@ -63,11 +66,8 @@ t_eofitness_SOURCES = t-eofitness.cpp
t_eoFitnessAssembledEA_SOURCES = t-eoFitnessAssembledEA.cpp
t_eobin_SOURCES = t-eobin.cpp
t_eoVirus_SOURCES = t-eoVirus.cpp
t_MGE1bit_CXXFLAGS = -I$(top_srcdir)/contrib/MGE
t_MGE1bit_SOURCES = t-MGE1bit.cpp
t_MGE_CXXFLAGS = -I$(top_srcdir)/contrib/MGE
t_MGE_SOURCES = t-MGE.cpp
t_MGE_control_CXXFLAGS = -I$(top_srcdir)/contrib/MGE
t_MGE_control_SOURCES = t-MGE-control.cpp
t_eoStateAndParser_SOURCES = t-eoStateAndParser.cpp
t_eoCheckpointing_SOURCES = t-eoCheckpointing.cpp

View file

@ -24,62 +24,63 @@ 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);
int main_function(int argc, char *argv[])
int main_function(int argc, char *argv[])
{
// Create the command-line parser
eoParser parser(argc, argv); // for user-parameter reading
eoState state; // keeps all things allocated
eoValueParam<bool>& simpleParam = parser.createParam(true, "Isotropic", "Isotropic self-adaptive mutation", 'i', "ES mutation");
eoValueParam<bool>& stdevsParam = parser.createParam(false, "Stdev", "One self-adaptive stDev per variable", 's', "ES mutation");
eoValueParam<bool>& corrParam = parser.createParam(false, "Correl", "Use correlated mutations", 'c', "ES mutation");
// Create the command-line parser
eoParser parser(argc, argv); // for user-parameter reading
eoState state; // keeps all things allocated
eoValueParam<bool>& simpleParam = parser.getORcreateParam(true, "Isotropic",
"Isotropic self-adaptive mutation",
'i', "ES mutation");
eoValueParam<bool>& stdevsParam = parser.getORcreateParam(false, "Stdev",
"One self-adaptive stDev per variable",
's', "ES mutation");
eoValueParam<bool>& corrParam = parser.getORcreateParam(false, "Correl",
"Use correlated mutations",
'c', "ES mutation");
// Run the appropriate algorithm
if (simpleParam.value() == false)
{
std::cout << "Using eoReal" << std::endl;
runAlgorithm(eoReal<FitT>(), parser, state);
std::cout << "Using eoReal" << std::endl;
runAlgorithm(eoReal<FitT>(), parser, state);
}
else if (stdevsParam.value() == false)
{
std::cout << "Using eoEsSimple" << std::endl;
runAlgorithm(eoEsSimple<FitT>(), parser, state);
std::cout << "Using eoEsSimple" << std::endl;
runAlgorithm(eoEsSimple<FitT>(), parser, state);
}
else if (corrParam.value() == false)
{
std::cout << "Using eoEsStdev" << std::endl;
runAlgorithm(eoEsStdev<FitT>(), parser, state);
std::cout << "Using eoEsStdev" << std::endl;
runAlgorithm(eoEsStdev<FitT>(), parser, state);
}
else
else
{
std::cout << "Using eoEsFull" << std::endl;
runAlgorithm(eoEsFull<FitT>(), parser, state);
std::cout << "Using eoEsFull" << std::endl;
runAlgorithm(eoEsFull<FitT>(), parser, state);
}
return 0;
return 0;
}
// A main that catches the exceptions
int main(int argc, char **argv)
{
#ifdef _MSC_VER
// rng.reseed(42);
// rng.reseed(42);
int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);
flag |= _CRTDBG_LEAK_CHECK_DF;
flag |= _CRTDBG_LEAK_CHECK_DF;
_CrtSetDbgFlag(flag);
// _CrtSetBreakAlloc(100);
// _CrtSetBreakAlloc(100);
#endif
try
{
main_function(argc, argv);
@ -88,61 +89,62 @@ int main(int argc, char **argv)
{
std::cout << "Exception: " << e.what() << '\n';
}
}
/** The templatized main (sort of)
* quite similar to the main of other genotypes
* (e.g. t-eoReal and t-eoGA in test dir)
*/
quite similar to the main of other genotypes (e.g. t-eoReal and t-eoGA
in test dir)
*/
template <class EOT>
void runAlgorithm(EOT, eoParser& _parser, eoState& _state)
{
typedef typename EOT::Fitness FitT;
typedef typename EOT::Fitness FitT;
///// FIRST, problem or representation dependent stuff
//////////////////////////////////////////////////////
///// FIRST, problem or representation dependent stuff
//////////////////////////////////////////////////////
// The evaluation fn - encapsulated into an eval counter for output
eoEvalFuncPtr<EOT, double, const std::vector<double>&>
mainEval( real_value );
eoEvalFuncCounter<EOT> eval(mainEval);
// The evaluation fn - encapsulated into an eval counter for output
eoEvalFuncPtr<EOT, double, const std::vector<double>&> mainEval( real_value );
eoEvalFuncCounter<EOT> eval(mainEval);
// the genotype - through a genotype initializer
eoRealInitBounded<EOT>& init = make_genotype(_parser, _state, EOT());
// the genotype - through a genotype initializer
eoRealInitBounded<EOT>& init = make_genotype(_parser, _state, EOT());
// Build the variation operator (any seq/prop construct)
eoGenOp<EOT>& op = make_op(_parser, _state, init);
// Build the variation operator (any seq/prop construct)
eoGenOp<EOT>& op = make_op(_parser, _state, init);
//// Now the representation-independent things
//////////////////////////////////////////////
//// Now the representation-independent things
//////////////////////////////////////////////
// initialize the population - and evaluate
// yes, this is representation indepedent once you have an eoInit
eoPop<EOT>& pop = make_pop(_parser, _state, init);
apply<EOT>(eval, pop);
// initialize the population - and evaluate
// yes, this is representation indepedent once you have an eoInit
eoPop<EOT>& pop = make_pop(_parser, _state, init);
apply<EOT>(eval, pop);
// stopping criteria
eoContinue<EOT> & term = make_continue(_parser, _state, eval);
// output
eoCheckPoint<EOT> & checkpoint = make_checkpoint(_parser, _state, eval, term);
// algorithm (need the operator!)
eoAlgo<EOT>& ga = make_algo_scalar(_parser, _state, eval, checkpoint, op);
// stopping criteria
eoContinue<EOT> & term = make_continue(_parser, _state, eval);
// output
eoCheckPoint<EOT> & checkpoint = make_checkpoint(_parser, _state, eval, term);
// algorithm (need the operator!)
eoAlgo<EOT>& ga = make_algo_scalar(_parser, _state, eval, checkpoint, op);
///// End of construction of the algorith
/////////////////////////////////////////
// to be called AFTER all parameters have been read!!!
make_help(_parser);
///// End of construction of the algorith
/////////////////////////////////////////
// to be called AFTER all parameters have been read!!!
make_help(_parser);
//// GO
///////
std::cout << "Initial Population\n";
pop.sortedPrintOn(std::cout);
std::cout << std::endl;
//// GO
///////
std::cout << "Initial Population\n";
pop.sortedPrintOn(std::cout);
std::cout << std::endl;
run_ea(ga, pop); // run the ga
run_ea(ga, pop); // run the ga
std::cout << "Final Population\n";
pop.sortedPrintOn(std::cout);
std::cout << std::endl;
std::cout << "Final Population\n";
pop.sortedPrintOn(std::cout);
std::cout << std::endl;
}