Paradiseo-eo sources added
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@40 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
bc1f453978
commit
c3aec878e5
55 changed files with 342772 additions and 0 deletions
29
trunk/paradiseo-eo/test/.cvsignore
Normal file
29
trunk/paradiseo-eo/test/.cvsignore
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
*.o
|
||||
*.csv
|
||||
*.sav
|
||||
.deps
|
||||
Makefile
|
||||
Makefile.in
|
||||
t-eo
|
||||
t-eobin
|
||||
t-eobreeder
|
||||
t-eofitness
|
||||
t-eoinclusion
|
||||
t-eoinsertion
|
||||
t-eolottery
|
||||
t-eoproblem
|
||||
t-eogeneration
|
||||
t-eoNonUniform
|
||||
t-eo2dVector
|
||||
t-eoEasyEA
|
||||
t-eoUniform
|
||||
t-eoRandom
|
||||
t-eoCheckpointing
|
||||
t-eoVector
|
||||
t-eoAtomOps
|
||||
t-selectOne
|
||||
t-eoStateAndParser
|
||||
t-eoGOpSel
|
||||
t-eoExternalEO
|
||||
t-eoESFull
|
||||
t-eoSymreg
|
||||
53
trunk/paradiseo-eo/test/CVS/Entries
Normal file
53
trunk/paradiseo-eo/test/CVS/Entries
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/.cvsignore/1.13/Mon Nov 6 12:37:58 2000//
|
||||
/Makefile.am/1.70/Wed Dec 7 15:51:32 2005//
|
||||
/RoyalRoad.h/1.3/Thu Jun 21 12:03:17 2001//
|
||||
/binary_value.h/1.5/Sat Nov 17 07:54:12 2001//
|
||||
/fitness_traits.cpp/1.4/Thu Feb 27 19:20:30 2003//
|
||||
/real_value.h/1.8/Mon May 21 04:10:55 2001//
|
||||
/run_tests/1.5/Wed Nov 7 15:23:24 2001//
|
||||
/t-MGE-control.cpp/1.7/Thu Oct 6 17:22:40 2005//
|
||||
/t-MGE.cpp/1.8/Thu Oct 6 17:22:40 2005//
|
||||
/t-MGE1bit.cpp/1.8/Thu Oct 6 17:22:40 2005//
|
||||
/t-eo.cpp/1.4/Thu Feb 27 19:20:29 2003//
|
||||
/t-eo2dVector.cc/1.1/Fri Oct 1 16:36:04 1999//
|
||||
/t-eoAtomOps.cpp/1.4/Thu Feb 27 19:20:29 2003//
|
||||
/t-eoBaseFunctions.cpp/1.3/Thu Feb 27 19:20:29 2003//
|
||||
/t-eoCMAES.cpp/1.2/Sun Mar 26 13:33:25 2006//
|
||||
/t-eoCheckpointing.cpp/1.8/Mon Sep 26 10:18:15 2005//
|
||||
/t-eoESAll.cpp/1.7/Mon Oct 10 21:42:31 2005//
|
||||
/t-eoESFull.cpp/1.14/Mon Sep 26 10:18:15 2005//
|
||||
/t-eoESOps.cpp/1.3/Thu Feb 27 19:20:28 2003//
|
||||
/t-eoEasyEA.cpp/1.6/Thu Feb 27 19:20:28 2003//
|
||||
/t-eoExternalEO.cpp/1.6/Thu Feb 27 19:20:28 2003//
|
||||
/t-eoFitnessAssembled.cpp/1.1/Wed Apr 2 21:10:26 2003//
|
||||
/t-eoFitnessAssembledEA.cpp/1.2/Mon Sep 20 14:11:23 2004//
|
||||
/t-eoFunctor.cpp/1.2/Wed Aug 23 12:03:01 2000//
|
||||
/t-eoGA.cpp/1.8/Thu Feb 27 19:20:28 2003//
|
||||
/t-eoGOpSel.cpp/1.8/Thu Feb 27 19:20:27 2003//
|
||||
/t-eoGenOp.cpp/1.12/Wed Sep 28 21:49:26 2005//
|
||||
/t-eoNonUniform.cpp/1.3/Thu Feb 27 19:20:26 2003//
|
||||
/t-eoPBIL.cpp/1.7/Wed Oct 5 21:34:19 2005//
|
||||
/t-eoPareto.cpp/1.15/Wed Oct 5 21:34:19 2005//
|
||||
/t-eoParetoFitness.cpp/1.8/Wed Sep 29 18:37:20 2004//
|
||||
/t-eoRandom.cpp/1.13/Thu Feb 27 19:20:24 2003//
|
||||
/t-eoReal.cpp/1.6/Thu Feb 27 19:20:24 2003//
|
||||
/t-eoReplacement.cpp/1.6/Thu Feb 27 19:20:23 2003//
|
||||
/t-eoRoulette.cpp/1.1/Wed Jun 4 09:34:26 2003//
|
||||
/t-eoSSGA.cpp/1.4/Thu Feb 27 19:20:22 2003//
|
||||
/t-eoSelect.cpp/1.12/Mon Sep 26 10:18:15 2005//
|
||||
/t-eoSharing.cpp/1.4/Wed Sep 28 21:49:26 2005//
|
||||
/t-eoStateAndParser.cpp/1.9/Mon Sep 26 10:18:15 2005//
|
||||
/t-eoSymreg.cpp/1.15/Thu Feb 27 19:20:22 2003//
|
||||
/t-eoUniform.cpp/1.3/Thu Feb 27 19:20:22 2003//
|
||||
/t-eoVector.cpp/1.7/Wed Sep 28 21:49:26 2005//
|
||||
/t-eoVirus.cpp/1.5/Tue Sep 21 10:23:32 2004//
|
||||
/t-eobin.cpp/1.21/Wed Sep 28 21:49:26 2005//
|
||||
/t-eobreeder.cpp/1.13/Thu Feb 27 19:20:29 2003//
|
||||
/t-eofitness.cpp/1.7/Thu Feb 27 19:20:28 2003//
|
||||
/t-eogeneration.cpp/1.7/Thu Feb 27 19:20:27 2003//
|
||||
/t-eoinclusion.cpp/1.8/Thu Feb 27 19:20:27 2003//
|
||||
/t-eoinsertion.cpp/1.6/Thu Feb 27 19:20:26 2003//
|
||||
/t-eolottery.cpp/1.5/Thu Feb 27 19:20:26 2003//
|
||||
/t-eoproblem.cpp/1.4/Thu Feb 27 19:20:25 2003//
|
||||
/t-selectOne.cpp/1.6/Thu Feb 27 19:20:20 2003//
|
||||
D
|
||||
1
trunk/paradiseo-eo/test/CVS/Repository
Normal file
1
trunk/paradiseo-eo/test/CVS/Repository
Normal file
|
|
@ -0,0 +1 @@
|
|||
eo/test
|
||||
1
trunk/paradiseo-eo/test/CVS/Root
Normal file
1
trunk/paradiseo-eo/test/CVS/Root
Normal file
|
|
@ -0,0 +1 @@
|
|||
:ext:evomarc@eodev.cvs.sourceforge.net:/cvsroot/eodev
|
||||
93
trunk/paradiseo-eo/test/Makefile.am
Normal file
93
trunk/paradiseo-eo/test/Makefile.am
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
###############################################################################
|
||||
##
|
||||
## Makefile.am for eo/test
|
||||
##
|
||||
###############################################################################
|
||||
|
||||
LIBEO = $(top_builddir)/src/libeo.a
|
||||
LIBEOUTILS = $(top_builddir)/src/utils/libeoutils.a
|
||||
LIBES = $(top_builddir)/src/es/libes.a
|
||||
LIBGA = $(top_builddir)/src/ga/libga.a
|
||||
LIBCMA = $(top_builddir)/src/es/libcma.a
|
||||
|
||||
# PLEASE don't break the line (see create_batch.sh)
|
||||
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-eoExternalEO \
|
||||
t-eoSymreg \
|
||||
t-eo \
|
||||
t-eoReplacement \
|
||||
t-eoSelect \
|
||||
t-eoGenOp \
|
||||
t-eoGA \
|
||||
t-eoReal \
|
||||
t-eoVector \
|
||||
t-eoESAll \
|
||||
t-eoPBIL \
|
||||
t-eoFitnessAssembled \
|
||||
t-eoFitnessAssembledEA \
|
||||
t-eoRoulette \
|
||||
t-eoSharing \
|
||||
t-eoCMAES
|
||||
|
||||
|
||||
TESTS = $(check_PROGRAMS) \
|
||||
run_tests # This script can be used to check command-line arguments
|
||||
|
||||
noinst_HEADERS = binary_value.h real_value.h RoyalRoad.h
|
||||
|
||||
|
||||
DEPS = $(LIBGA) $(LIBES) $(LIBCMA) $(LIBEOUTILS) $(LIBEO)
|
||||
INCLUDES = -I$(top_srcdir)/src -I$(srcdir)/../src
|
||||
LIBS = $(DEPS)
|
||||
|
||||
CLEANFILES = monitor.csv t-eoRandom.out
|
||||
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
|
||||
#
|
||||
t_eoRandom_SOURCES = t-eoRandom.cpp
|
||||
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_SOURCES = t-MGE1bit.cpp
|
||||
t_MGE_SOURCES = t-MGE.cpp
|
||||
t_MGE_control_SOURCES = t-MGE-control.cpp
|
||||
t_eoStateAndParser_SOURCES = t-eoStateAndParser.cpp
|
||||
t_eoCheckpointing_SOURCES = t-eoCheckpointing.cpp
|
||||
t_eoReplacement_SOURCES = t-eoReplacement.cpp
|
||||
t_eoSelect_SOURCES = t-eoSelect.cpp
|
||||
t_eoExternalEO_SOURCES = t-eoExternalEO.cpp
|
||||
t_eoSymreg_SOURCES = t-eoSymreg.cpp
|
||||
t_eo_SOURCES = t-eo.cpp
|
||||
t_eoGenOp_SOURCES = t-eoGenOp.cpp
|
||||
t_eoVector_SOURCES = t-eoVector.cpp
|
||||
t_eoGA_SOURCES = t-eoGA.cpp
|
||||
t_eoReal_SOURCES = t-eoReal.cpp
|
||||
t_eoESAll_SOURCES = t-eoESAll.cpp
|
||||
t_eoSSGA_SOURCES = t-eoSSGA.cpp
|
||||
t_eoPareto_SOURCES = t-eoPareto.cpp
|
||||
t_eoParetoFitness_SOURCES = t-eoParetoFitness.cpp
|
||||
t_eoPBIL_SOURCES = t-eoPBIL.cpp
|
||||
t_eoFitnessAssembled_SOURCES = t-eoFitnessAssembled.cpp
|
||||
t_eoRoulette_SOURCES = t-eoRoulette.cpp
|
||||
t_eoSharing_SOURCES = t-eoSharing.cpp
|
||||
t_eoCMAES_SOURCES = t-eoCMAES.cpp
|
||||
60
trunk/paradiseo-eo/test/RoyalRoad.h
Normal file
60
trunk/paradiseo-eo/test/RoyalRoad.h
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
RoyalRoad.h
|
||||
-- Implementation of the Royal Road function for any length and block size
|
||||
(c) GeNeura Team 2001, Marc Schoenauer 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 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
|
||||
|
||||
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
||||
Marc.Schoenauer@polytechnique.fr
|
||||
CVS Info: $Date: 2001/06/21 12:03:17 $ $Header: /cvsroot/eodev/eo/test/RoyalRoad.h,v 1.3 2001/06/21 12:03:17 jmerelo Exp $ $Author: jmerelo $
|
||||
*/
|
||||
|
||||
#ifndef RoyalRoad_h
|
||||
#define RoyalRoad_h
|
||||
|
||||
template<class EOT>
|
||||
class RoyalRoad: public eoEvalFunc<EOT> {
|
||||
|
||||
public:
|
||||
|
||||
typedef typename EOT::Fitness FitT;
|
||||
|
||||
/// Ctor: takes a length, and divides that length in equal parts
|
||||
RoyalRoad( unsigned _div ): eoEvalFunc<EOT >(), div( _div ) {};
|
||||
|
||||
// Applies the function
|
||||
virtual void operator() ( EOT & _eo ) {
|
||||
FitT fitness = 0;
|
||||
if (_eo.invalid()) {
|
||||
for ( unsigned i = 0; i < _eo.size()/div; i ++ ) {
|
||||
bool block = true;
|
||||
for ( unsigned j = 0; j < div; j ++ ) {
|
||||
block &= _eo[i*div+j];
|
||||
}
|
||||
if (block) {
|
||||
fitness += div;
|
||||
}
|
||||
}
|
||||
_eo.fitness( fitness );
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
unsigned div;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
16
trunk/paradiseo-eo/test/binary_value.h
Normal file
16
trunk/paradiseo-eo/test/binary_value.h
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#include <algorithm>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/** Just the simple function that takes binary value of a chromosome and sets
|
||||
the fitnes.
|
||||
@param _chrom A binary chromosome
|
||||
*/
|
||||
|
||||
template <class Chrom> double binary_value(const Chrom& _chrom)
|
||||
{
|
||||
double sum = 0.0;
|
||||
for (unsigned i=0; i<_chrom.size(); i++)
|
||||
sum += _chrom[i];
|
||||
return sum;
|
||||
}
|
||||
433
trunk/paradiseo-eo/test/fitness_traits.cpp
Normal file
433
trunk/paradiseo-eo/test/fitness_traits.cpp
Normal file
|
|
@ -0,0 +1,433 @@
|
|||
#include <map> // for pair
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <math.h> // for exp
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* fitness_traits.h */
|
||||
|
||||
// default traits: defaults to a double that needs to be maximized
|
||||
template <class T = double>
|
||||
struct fitness_traits
|
||||
{
|
||||
// Needs mapping can be used to figure out whether you need to do fitness scaling (or not)
|
||||
const static bool needs_mapping = false;
|
||||
|
||||
// storage_type: what to store next to the genotype
|
||||
typedef T storage_type;
|
||||
|
||||
// performance_type: what the eoEvalFunc calculates
|
||||
typedef T performance_type;
|
||||
|
||||
// worth_type: what the scaling function does
|
||||
typedef T worth_type;
|
||||
|
||||
// access_performance: how to get from what is stored to a mutable performance
|
||||
static performance_type& access_performance(storage_type& a) { return a; }
|
||||
|
||||
// access_worth: how to get from what is stored to a mutable worth
|
||||
static worth_type& access_worth(storage_type& a) { return a; }
|
||||
|
||||
// get_performance: from storage_type to a performance figure
|
||||
static performance_type get_performance(storage_type a) { return a; }
|
||||
|
||||
// get_worth: from storage_type to a worth figure
|
||||
static worth_type get_worth(storage_type a) { return a; }
|
||||
|
||||
// get the fitness out of the individual
|
||||
template <class EOT>
|
||||
static worth_type get_fitness(const EOT& _eo) { return _eo.performance(); }
|
||||
|
||||
// compare the two individuals
|
||||
template <class EOT>
|
||||
static bool is_better(const EOT& _eo1, const EOT& _eo2)
|
||||
{
|
||||
return _eo1.performance() > _eo2.performance();
|
||||
}
|
||||
};
|
||||
|
||||
struct minimization {};
|
||||
struct maximization {};
|
||||
|
||||
struct fitness_traits<minimization> : public fitness_traits<double>
|
||||
{
|
||||
// for minimization, invert the is_better
|
||||
template <class EOT>
|
||||
static bool is_better(const EOT& _eo1, const EOT& _eo2)
|
||||
{
|
||||
return _eo1.performance() < _eo2.performance();
|
||||
}
|
||||
};
|
||||
|
||||
// for maximization, just take the default behaviour
|
||||
struct fitness_traits<maximization> : public fitness_traits<double> {};
|
||||
|
||||
// forward declaration
|
||||
//template <class EOT> class eoPop;
|
||||
//template <class Fitness, class Traits> class EO;
|
||||
|
||||
// unfortunately, partial template specialization is not approved by Microsoft (though ANSI says it's ok)
|
||||
// Probably need some macro-magic to make this work (MicroSoft == MacroHard)
|
||||
// A pair class: first == performance, second == worth, redefine all types, data and functions
|
||||
template <class Performance, class Worth>
|
||||
struct fitness_traits< pair<Performance, Worth> >
|
||||
{
|
||||
typedef pair<Performance, Worth> storage_type;
|
||||
typedef Performance performance_type;
|
||||
typedef Worth worth_type;
|
||||
|
||||
const static bool needs_mapping = true;
|
||||
|
||||
static performance_type& access_performance(storage_type& a) { return a.first; }
|
||||
static worth_type& access_worth(storage_type& a) { return a.second; }
|
||||
|
||||
static performance_type get_performance(const storage_type& a) { return a.first; }
|
||||
static worth_type get_worth(const storage_type& a) { return a.second; }
|
||||
|
||||
// This function calls _eo.worth() which in turn checks the fitness flag and calls get_worth above
|
||||
// The compiler should be able to inline all these calls and come up with a very compact solution
|
||||
template <class EOT>
|
||||
static worth_type get_fitness(const EOT& _eo) { return _eo.worth(); }
|
||||
|
||||
template <class EOT>
|
||||
static bool is_better(const EOT& _eo1, const EOT& _eo2)
|
||||
{
|
||||
return _eo1.worth() > _eo2.worth();
|
||||
}
|
||||
};
|
||||
|
||||
/* end fitness_traits.h */
|
||||
|
||||
/* EO.h
|
||||
|
||||
The Fitness template argument is there for backward compatibility reasons
|
||||
|
||||
*/
|
||||
|
||||
template <class Fitness, class Traits = fitness_traits<Fitness> >
|
||||
class EO
|
||||
{
|
||||
public :
|
||||
|
||||
typedef Traits fitness_traits;
|
||||
typedef typename Traits::storage_type storage_type;
|
||||
typedef typename Traits::performance_type performance_type;
|
||||
typedef typename Traits::worth_type worth_type;
|
||||
|
||||
EO() : valid_performance(false), valid_worth(false), rep_fitness() {}
|
||||
|
||||
// for backwards compatibility
|
||||
void fitness(performance_type perf)
|
||||
{
|
||||
performance(perf);
|
||||
}
|
||||
|
||||
void performance(performance_type perf)
|
||||
{
|
||||
valid_performance = true;
|
||||
Traits::access_performance(rep_fitness) = perf;
|
||||
}
|
||||
|
||||
performance_type performance(void) const
|
||||
{
|
||||
if(!valid_performance) throw runtime_error("no performance");
|
||||
return Traits::get_performance(rep_fitness);
|
||||
}
|
||||
|
||||
void worth(worth_type worth)
|
||||
{
|
||||
valid_worth = true;
|
||||
Traits::access_worth(rep_fitness) = worth;
|
||||
}
|
||||
|
||||
worth_type worth(void) const
|
||||
{
|
||||
if(!valid_worth) throw runtime_error("no worth");
|
||||
if(!Traits::needs_mapping) throw runtime_error("no mapping");
|
||||
return Traits::get_worth(rep_fitness);
|
||||
}
|
||||
|
||||
worth_type fitness(void) const
|
||||
{
|
||||
return Traits::get_fitness(*this);
|
||||
}
|
||||
|
||||
void invalidate(void)
|
||||
{
|
||||
valid_performance = false;
|
||||
valid_worth = false;
|
||||
}
|
||||
|
||||
void invalidate_worth(void)
|
||||
{
|
||||
valid_worth = false;
|
||||
}
|
||||
|
||||
bool operator<(const EO<Fitness, Traits>& other) const
|
||||
{
|
||||
return !Traits::is_better(other, *this);
|
||||
}
|
||||
|
||||
bool operator>(const EO<Fitness, Traits>& other) const
|
||||
{
|
||||
return Traits::is_better(other, *this);
|
||||
}
|
||||
|
||||
private :
|
||||
|
||||
bool valid_performance;
|
||||
bool valid_worth;
|
||||
storage_type rep_fitness;
|
||||
};
|
||||
|
||||
/* end EO.h */
|
||||
|
||||
/* eoPerf2Worth.h */
|
||||
|
||||
// get the name known
|
||||
template <class EOT> class eoPop;
|
||||
|
||||
template <class EOT>
|
||||
void exponential_scaling(eoPop<EOT>& _pop)
|
||||
{
|
||||
for (unsigned i = 0; i < _pop.size(); ++i)
|
||||
{ // change minimimization into maximization
|
||||
_pop[i].worth(exp(-_pop[i].performance()));
|
||||
}
|
||||
}
|
||||
|
||||
template <class EOT>
|
||||
class eoPerf2Worth /* : public eoUF<eoPop<EOT>&, void> */
|
||||
{
|
||||
public :
|
||||
virtual void operator()(eoPop<EOT>& _pop)
|
||||
{
|
||||
return exponential_scaling(_pop);
|
||||
}
|
||||
};
|
||||
|
||||
/* end eoPerf2Worth.h */
|
||||
|
||||
|
||||
/* eoPop.h */
|
||||
|
||||
template <class EOT>
|
||||
class eoPop : public vector<EOT>
|
||||
{
|
||||
public :
|
||||
|
||||
typedef typename EOT::fitness_traits fitness_traits;
|
||||
|
||||
eoPop(void) : p2w(0) {}
|
||||
|
||||
void sort()
|
||||
{
|
||||
scale(); // get the worths up to date
|
||||
|
||||
std::sort(begin(), end(), greater<EOT>());
|
||||
}
|
||||
|
||||
void scale()
|
||||
{
|
||||
if (p2w)
|
||||
{
|
||||
if (!fitness_traits::needs_mapping)
|
||||
{
|
||||
throw runtime_error("eoPop: no scaling needed, yet a scaling function is defined");
|
||||
}
|
||||
|
||||
(*p2w)(*this);
|
||||
}
|
||||
else if (fitness_traits::needs_mapping)
|
||||
{
|
||||
throw runtime_error("eoPop: no scaling function attached to the population, while one was certainly called for");
|
||||
}
|
||||
}
|
||||
|
||||
void setPerf2Worth(eoPerf2Worth<EOT>& _p2w)
|
||||
{
|
||||
p2w = &_p2w;
|
||||
}
|
||||
|
||||
void setPerf2Worth(eoPerf2Worth<EOT>* _p2w)
|
||||
{
|
||||
p2w = _p2w;
|
||||
}
|
||||
|
||||
eoPerf2Worth<EOT>* getPerf2Worth() { return p2w; }
|
||||
|
||||
void swap(eoPop<EOT>& other)
|
||||
{
|
||||
vector<EOT>::swap(other);
|
||||
eoPerf2Worth<EOT>* tmp = p2w;
|
||||
p2w = other.p2w;
|
||||
other.p2w = tmp;
|
||||
}
|
||||
|
||||
private :
|
||||
|
||||
// a pointer as it can be emtpy
|
||||
eoPerf2Worth<EOT>* p2w;
|
||||
};
|
||||
|
||||
// need this one to be able to swap the members as well...
|
||||
template <class EOT>
|
||||
void swap(eoPop<EOT>& _p1, eoPop<EOT>& _p2)
|
||||
{
|
||||
_p1.swap(_p2);
|
||||
}
|
||||
|
||||
/* end eoPop.h */
|
||||
|
||||
/* main and test */
|
||||
|
||||
template <class EOT>
|
||||
void algo(eoPop<EOT>& _pop)
|
||||
{
|
||||
eoPop<EOT> offspring; // how to get the scaling info into this guy??
|
||||
offspring.setPerf2Worth(_pop.getPerf2Worth()); // like this!
|
||||
|
||||
std::copy(_pop.begin(), _pop.end(), back_inserter(offspring));
|
||||
|
||||
offspring.sort(); // should call scale
|
||||
|
||||
swap(_pop, offspring);
|
||||
}
|
||||
|
||||
void minimization_test()
|
||||
{
|
||||
typedef EO<minimization> eo_type;
|
||||
|
||||
eo_type eo1;
|
||||
eo_type eo2;
|
||||
|
||||
eo1.performance(1.0);
|
||||
eo2.performance(2.0);
|
||||
|
||||
std::cout << "With minimizing fitness" << std::endl;
|
||||
std::cout << eo1.fitness() << " < " << eo2.fitness() << " returns " << (eo1 < eo2) << std::endl;
|
||||
std::cout << eo2.fitness() << " < " << eo1.fitness() << " returns " << (eo2 < eo1) << std::endl;
|
||||
}
|
||||
|
||||
void the_main()
|
||||
{
|
||||
typedef EO<double> simple_eo;
|
||||
typedef EO<pair<double, double> > scaled_eo;
|
||||
|
||||
simple_eo eo1;
|
||||
simple_eo eo3;
|
||||
|
||||
/* First test some simple comparisons */
|
||||
|
||||
eo1.fitness(10); // could also use performance()
|
||||
eo3.fitness(5);
|
||||
|
||||
std::cout << eo1.fitness() << std::endl;
|
||||
std::cout << eo3.fitness() << std::endl;
|
||||
|
||||
std::cout << "eo1 < eo3 = " << (eo1 < eo3) << std::endl;
|
||||
|
||||
|
||||
scaled_eo eo2;
|
||||
scaled_eo eo4;
|
||||
eo2.performance(10);
|
||||
eo4.performance(8);
|
||||
|
||||
/* Now test if the worth gets accessed and if the flag protects it */
|
||||
|
||||
try
|
||||
{
|
||||
std::cout << eo2.fitness() << std::endl;
|
||||
std::cout << "did not throw" << std::endl;
|
||||
assert(false); // should throw
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
std::cout << "Fitness threw exception, as it should" << std::endl;
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
|
||||
/* Set the worth and all is well (this is normally done by some perf2worth functor */
|
||||
|
||||
eo2.worth(3);
|
||||
eo4.worth(5);
|
||||
|
||||
std::cout << "with maximization " << std::endl;
|
||||
std::cout << eo2.fitness() << std::endl;
|
||||
std::cout << eo4.fitness() << std::endl;
|
||||
std::cout << eo2.fitness() << " < " << eo4.fitness() << " returns " << (eo2 < eo4) << std::endl;
|
||||
|
||||
/* Test the minimization of fitness */
|
||||
minimization_test();
|
||||
|
||||
|
||||
/* Populations */
|
||||
|
||||
// test pop without scaling, should have no overhead save for a single empty pointer in pop
|
||||
eoPop<simple_eo> pop0;
|
||||
pop0.resize(1);
|
||||
pop0[0].fitness(1);
|
||||
|
||||
algo(pop0);
|
||||
|
||||
std::cout << pop0[0].fitness() << std::endl;
|
||||
|
||||
assert(pop0[0].fitness() == 1);
|
||||
|
||||
/* test pop with scaling */
|
||||
|
||||
eoPerf2Worth<scaled_eo> perf2worth;
|
||||
eoPop<scaled_eo> pop1;
|
||||
|
||||
pop1.resize(1);
|
||||
|
||||
pop1[0].fitness(1.0); // emulate evaluation
|
||||
|
||||
// at this point getting the fitness should throw
|
||||
try
|
||||
{
|
||||
std::cout << pop1[0].fitness() << std::endl;
|
||||
std::cout << "did not throw" << std::endl;
|
||||
assert(false); // should throw
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
std::cout << "Fitness threw exception, as it should" << std::endl;
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
|
||||
// at this point trying to scale should throw
|
||||
try
|
||||
{
|
||||
algo(pop1); // should complain that it cannot scale
|
||||
assert(false); // so it would never get here
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{ // but rather ends here
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
|
||||
// ok, now set the scaling
|
||||
pop1.setPerf2Worth(perf2worth);
|
||||
|
||||
algo(pop1);
|
||||
|
||||
std::cout << "the fitness has been transformed from " << pop1[0].performance() << " to exp(-1) = " << pop1[0].fitness() << std::endl;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
try
|
||||
{
|
||||
the_main();
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
19
trunk/paradiseo-eo/test/real_value.h
Normal file
19
trunk/paradiseo-eo/test/real_value.h
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#include <vector>
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
/** Just a simple function that takes an eoEsBase<double> and sets the fitnes
|
||||
to sphere
|
||||
@param _ind vector<double>
|
||||
*/
|
||||
|
||||
double real_value(const std::vector<double>& _ind)
|
||||
{
|
||||
double sum = 0;
|
||||
for (unsigned i = 0; i < _ind.size(); i++)
|
||||
sum += _ind[i] * _ind[i];
|
||||
return sum/_ind.size();
|
||||
}
|
||||
|
||||
|
||||
|
||||
9
trunk/paradiseo-eo/test/run_tests
Executable file
9
trunk/paradiseo-eo/test/run_tests
Executable file
|
|
@ -0,0 +1,9 @@
|
|||
#!/bin/sh
|
||||
|
||||
echo "Testing -h"
|
||||
./t-eoCheckpointing -h
|
||||
|
||||
echo "Finished"
|
||||
|
||||
#TODO test if an error occured
|
||||
echo "Ok"
|
||||
104
trunk/paradiseo-eo/test/t-MGE-control.cpp
Normal file
104
trunk/paradiseo-eo/test/t-MGE-control.cpp
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// t-eoMGE.cpp
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#ifndef __GNUG__
|
||||
// to avoid long name warnings
|
||||
#pragma warning(disable:4786)
|
||||
#endif // __GNUG__
|
||||
|
||||
#include "eo"
|
||||
#include "ga/eoBitOp.h"
|
||||
|
||||
#include "RoyalRoad.h"
|
||||
|
||||
// Viri
|
||||
#include "VirusOp.h"
|
||||
#include "eoVirus.h"
|
||||
#include "eoInitVirus.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
typedef eoVirus<float> Chrom;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
int main()
|
||||
{
|
||||
const unsigned POP_SIZE = 10, CHROM_SIZE = 12;
|
||||
unsigned i;
|
||||
eoBooleanGenerator gen;
|
||||
|
||||
// the populations:
|
||||
eoPop<Chrom> pop;
|
||||
|
||||
// Evaluation
|
||||
RoyalRoad<Chrom> rr( 8 );
|
||||
eoEvalFuncCounter<Chrom> eval( rr );
|
||||
|
||||
eoInitVirus<float> random(CHROM_SIZE, gen);
|
||||
for (i = 0; i < POP_SIZE; ++i) {
|
||||
Chrom chrom;
|
||||
random(chrom);
|
||||
eval(chrom);
|
||||
pop.push_back(chrom);
|
||||
}
|
||||
|
||||
std::cout << "population:" << std::endl;
|
||||
for (i = 0; i < pop.size(); ++i)
|
||||
std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl;
|
||||
|
||||
// selection
|
||||
eoStochTournamentSelect<Chrom> lottery(0.9 );
|
||||
|
||||
// breeder
|
||||
eoOneBitFlip<Chrom> vm;
|
||||
eoUBitXover<Chrom> xover;
|
||||
eoProportionalOp<Chrom> propSel;
|
||||
eoGeneralBreeder<Chrom> breeder( lottery, propSel );
|
||||
propSel.add(vm, 0.2);
|
||||
propSel.add(xover, 0.8);
|
||||
|
||||
// Replace a single one
|
||||
eoCommaReplacement<Chrom> replace;
|
||||
|
||||
// Terminators
|
||||
eoGenContinue<Chrom> continuator1(10);
|
||||
eoFitContinue<Chrom> continuator2(CHROM_SIZE);
|
||||
eoCombinedContinue<Chrom> continuator(continuator1, continuator2);
|
||||
eoCheckPoint<Chrom> checkpoint(continuator);
|
||||
eoStdoutMonitor monitor;
|
||||
checkpoint.add(monitor);
|
||||
eoSecondMomentStats<Chrom> stats;
|
||||
eoPopStat<Chrom> dumper( 10 );
|
||||
monitor.add(stats);
|
||||
checkpoint.add(dumper);
|
||||
checkpoint.add(stats);
|
||||
|
||||
// GA generation
|
||||
eoEasyEA<Chrom> ea(checkpoint, eval, breeder, replace );
|
||||
|
||||
// evolution
|
||||
try
|
||||
{
|
||||
ea(pop);
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
std::cout << "exception: " << e.what() << std::endl;;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
std::cout << "pop" << std::endl;
|
||||
for (i = 0; i < pop.size(); ++i)
|
||||
std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl;
|
||||
|
||||
std::cout << "\n --> Number of Evaluations = " << eval.getValue() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
108
trunk/paradiseo-eo/test/t-MGE.cpp
Normal file
108
trunk/paradiseo-eo/test/t-MGE.cpp
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// t-eoMGE.cpp
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#ifndef __GNUG__
|
||||
// to avoid long name warnings
|
||||
#pragma warning(disable:4786)
|
||||
#endif // __GNUG__
|
||||
|
||||
#include <eo>
|
||||
#include <ga/eoBitOp.h>
|
||||
|
||||
#include "RoyalRoad.h"
|
||||
|
||||
// Viri
|
||||
#include "VirusOp.h"
|
||||
#include "eoVirus.h"
|
||||
#include "eoInitVirus.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
typedef eoVirus<float> Chrom;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
int main()
|
||||
{
|
||||
const unsigned POP_SIZE = 10, CHROM_SIZE = 12;
|
||||
unsigned i;
|
||||
eoBooleanGenerator gen;
|
||||
|
||||
// the populations:
|
||||
eoPop<Chrom> pop;
|
||||
|
||||
// Evaluation
|
||||
RoyalRoad<Chrom> rr( 8 );
|
||||
eoEvalFuncCounter<Chrom> eval( rr );
|
||||
|
||||
eoInitVirus<float> random(CHROM_SIZE, gen);
|
||||
for (i = 0; i < POP_SIZE; ++i) {
|
||||
Chrom chrom;
|
||||
random(chrom);
|
||||
eval(chrom);
|
||||
pop.push_back(chrom);
|
||||
}
|
||||
|
||||
std::cout << "population:" << std::endl;
|
||||
for (i = 0; i < pop.size(); ++i)
|
||||
std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl;
|
||||
|
||||
// selection
|
||||
eoStochTournamentSelect<Chrom> lottery(0.9 );
|
||||
|
||||
// breeder
|
||||
VirusMutation<float> vm;
|
||||
VirusTransmission<float> vt;
|
||||
VirusBitFlip<float> vf;
|
||||
eoUBitXover<Chrom> xover;
|
||||
eoProportionalOp<Chrom> propSel;
|
||||
eoGeneralBreeder<Chrom> breeder( lottery, propSel );
|
||||
propSel.add(vm, 0.1);
|
||||
propSel.add(vf, 0.05);
|
||||
propSel.add(vt, 0.05);
|
||||
propSel.add(xover, 0.8);
|
||||
|
||||
// Replace a single one
|
||||
eoCommaReplacement<Chrom> replace;
|
||||
|
||||
// Terminators
|
||||
eoGenContinue<Chrom> continuator1(10);
|
||||
eoFitContinue<Chrom> continuator2(CHROM_SIZE);
|
||||
eoCombinedContinue<Chrom> continuator(continuator1, continuator2);
|
||||
eoCheckPoint<Chrom> checkpoint(continuator);
|
||||
eoStdoutMonitor monitor;
|
||||
checkpoint.add(monitor);
|
||||
eoSecondMomentStats<Chrom> stats;
|
||||
eoPopStat<Chrom> dumper( 10 );
|
||||
monitor.add(stats);
|
||||
checkpoint.add(dumper);
|
||||
checkpoint.add(stats);
|
||||
|
||||
// GA generation
|
||||
eoEasyEA<Chrom> ea(checkpoint, eval, breeder, replace );
|
||||
|
||||
// evolution
|
||||
try
|
||||
{
|
||||
ea(pop);
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
std::cout << "exception: " << e.what() << std::endl;;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
std::cout << "pop" << std::endl;
|
||||
for (i = 0; i < pop.size(); ++i)
|
||||
std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl;
|
||||
|
||||
std::cout << "\n --> Number of Evaluations = " << eval.getValue() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
111
trunk/paradiseo-eo/test/t-MGE1bit.cpp
Normal file
111
trunk/paradiseo-eo/test/t-MGE1bit.cpp
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// t-eoMGE.cpp
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#ifndef __GNUG__
|
||||
// to avoid long name warnings
|
||||
#pragma warning(disable:4786)
|
||||
#endif // __GNUG__
|
||||
|
||||
#include "eo"
|
||||
#include "ga/eoBitOp.h"
|
||||
#include "RoyalRoad.h"
|
||||
|
||||
// Viri
|
||||
#include "VirusOp.h"
|
||||
#include "eoVirus.h"
|
||||
#include "eoInitVirus.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
typedef eoVirus<float> Chrom;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
int main()
|
||||
{
|
||||
const unsigned POP_SIZE = 10, CHROM_SIZE = 12;
|
||||
unsigned i;
|
||||
eoBooleanGenerator gen;
|
||||
|
||||
// the populations:
|
||||
eoPop<Chrom> pop;
|
||||
|
||||
// Evaluation
|
||||
RoyalRoad<Chrom> rr( 8 );
|
||||
eoEvalFuncCounter<Chrom> eval( rr );
|
||||
|
||||
eoInitVirus1bit<float> random(CHROM_SIZE, gen);
|
||||
for (i = 0; i < POP_SIZE; ++i) {
|
||||
Chrom chrom;
|
||||
random(chrom);
|
||||
eval(chrom);
|
||||
pop.push_back(chrom);
|
||||
}
|
||||
|
||||
std::cout << "population:" << std::endl;
|
||||
for (i = 0; i < pop.size(); ++i)
|
||||
std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl;
|
||||
|
||||
// selection
|
||||
eoStochTournamentSelect<Chrom> lottery(0.9 );
|
||||
|
||||
// breeder
|
||||
VirusShiftMutation<float> vm;
|
||||
VirusTransmission<float> vt;
|
||||
VirusBitFlip<float> vf;
|
||||
eoUBitXover<Chrom> xover;
|
||||
eoProportionalOp<Chrom> propSel;
|
||||
eoGeneralBreeder<Chrom> breeder( lottery, propSel );
|
||||
propSel.add(vm, 0.8);
|
||||
propSel.add(vf, 0.05);
|
||||
propSel.add(vt, 0.05);
|
||||
propSel.add(xover, 0.1);
|
||||
|
||||
// Replace a single one
|
||||
eoCommaReplacement<Chrom> replace;
|
||||
|
||||
// Terminators
|
||||
eoGenContinue<Chrom> continuator1(10);
|
||||
eoFitContinue<Chrom> continuator2(CHROM_SIZE);
|
||||
eoCombinedContinue<Chrom> continuator(continuator1, continuator2);
|
||||
eoCheckPoint<Chrom> checkpoint(continuator);
|
||||
eoStdoutMonitor monitor;
|
||||
checkpoint.add(monitor);
|
||||
eoSecondMomentStats<Chrom> stats;
|
||||
eoPopStat<Chrom> dumper( 10 );
|
||||
monitor.add(stats);
|
||||
checkpoint.add(dumper);
|
||||
checkpoint.add(stats);
|
||||
|
||||
// GA generation
|
||||
eoEasyEA<Chrom> ea(checkpoint, eval, breeder, replace);
|
||||
|
||||
// evolution
|
||||
try {
|
||||
ea(pop);
|
||||
} catch (std::exception& e) {
|
||||
std::cerr << "exception: " << e.what() << std::endl;;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
std::cout << "pop" << std::endl;
|
||||
for (i = 0; i < pop.size(); ++i)
|
||||
std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl;
|
||||
|
||||
std::cout << "\n --> Number of Evaluations = " << eval.getValue() << std::endl;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// Local Variables:
|
||||
// mode: C++
|
||||
// c-file-style: "Stroustrup"
|
||||
// End:
|
||||
23
trunk/paradiseo-eo/test/t-eo.cpp
Normal file
23
trunk/paradiseo-eo/test/t-eo.cpp
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// t-eo.cpp
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include <eo> // EO
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
typedef EO<float> Chrom;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
int main()
|
||||
{
|
||||
Chrom chrom1, chrom2;
|
||||
|
||||
std::cout << "chrom1 = " << chrom1 << std::endl
|
||||
<< "chrom2 = " << chrom2 << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
220
trunk/paradiseo-eo/test/t-eo2dVector.cc
Normal file
220
trunk/paradiseo-eo/test/t-eo2dVector.cc
Normal file
|
|
@ -0,0 +1,220 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
File............: t-eo2dVector.cc
|
||||
Author..........: Geneura Team (this file: Victor Rivas, vrivas@ujaen.es)
|
||||
Date............: 01-Oct-1999, at Fac. of Sciences, Univ. of Granada (Spain)
|
||||
Description.....: Test for 2 dimensional eoVector.
|
||||
|
||||
================ Modif. 1 ================
|
||||
Author........:
|
||||
Date..........:
|
||||
Description...:
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include <stdexcept>
|
||||
#include <eo2dVector.h> // eo2dVector
|
||||
#include <eoUniform.h> // Random generator
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
typedef unsigned T;
|
||||
typedef double fitnessT;
|
||||
typedef eo2dVector<T,fitnessT> C;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
main()
|
||||
{
|
||||
{
|
||||
C c1;
|
||||
cout << "Default constructor: " << endl
|
||||
<< c1 << endl;
|
||||
}
|
||||
{
|
||||
C c1( 5,6,1 );
|
||||
cout << "Default constructor with values: " << endl
|
||||
<< c1 << endl;
|
||||
|
||||
}
|
||||
{
|
||||
eoUniform<T> aleat( 1,10 );
|
||||
C c1( 5,6, aleat );
|
||||
cout << "Random constructor: " << endl
|
||||
<< c1 << endl;
|
||||
|
||||
}
|
||||
{
|
||||
C c1( 3,4,1 ), c2( c1 );
|
||||
cout << "Copy constructor: " << endl
|
||||
<< "Original chromosome: " << endl
|
||||
<< c1 << endl
|
||||
<< "Copy chromosome: " << endl
|
||||
<< c2 << endl;
|
||||
}
|
||||
|
||||
eoUniform<T> aleat( 1,10 );
|
||||
C c1( 3,4,aleat );
|
||||
|
||||
cout << "-----------------------------------------------------" << endl
|
||||
<< "Since now on all the operations are applied to " << endl
|
||||
<< c1
|
||||
<< "-----------------------------------------------------" << endl;
|
||||
{
|
||||
cout << "getGene(2,2): "
|
||||
<< c1.getGene(2,2) << endl;
|
||||
}
|
||||
{
|
||||
c1.setGene( 2,2,300 );
|
||||
cout << "setGene(2,2,300): " << endl
|
||||
<< c1 << endl;
|
||||
}
|
||||
{
|
||||
unsigned u1=0, u3=333, u5=555;
|
||||
vector<T> v1( 4,u1 ), v2( 4,u3 ), v3( 4,u5 );
|
||||
c1.insertRow( 0,v1 );
|
||||
c1.insertRow( 3,v2 );
|
||||
c1.insertRow( 5,v3 );
|
||||
cout << "Insert rows at positions 0, 3 and 5: " << endl
|
||||
<< c1 << endl;
|
||||
}
|
||||
{
|
||||
c1.deleteRow( 5 );
|
||||
c1.deleteRow( 3 );
|
||||
c1.deleteRow( 0 );
|
||||
cout << "Delete rows at positions 5, 3 and 0: " << endl
|
||||
<< c1 << endl;
|
||||
}
|
||||
{
|
||||
unsigned u1=0, u3=333, u6=666;
|
||||
vector<T> v1( 3,u1 ), v2( 3,u3 ), v3( 3,u6 );
|
||||
c1.insertCol( 0,v1 );
|
||||
c1.insertCol( 3,v2 );
|
||||
c1.insertCol( 6,v3 );
|
||||
cout << "Insert columns at positions 0, 3 and 6: " << endl
|
||||
<< c1 << endl;
|
||||
}
|
||||
{
|
||||
c1.deleteCol( 6 );
|
||||
c1.deleteCol( 3 );
|
||||
c1.deleteCol( 0 );
|
||||
cout << "Delete columns at positions 6, 3 and 0: " << endl
|
||||
<< c1 << endl;
|
||||
}
|
||||
{
|
||||
cout << "Number of Rows: " << endl
|
||||
<< c1.numOfRows() << endl;
|
||||
}
|
||||
{
|
||||
cout << "Number of Columns: " << endl
|
||||
<< c1.numOfCols() << endl;
|
||||
}
|
||||
|
||||
{
|
||||
cout << "Class Name: " << endl
|
||||
<< c1.className() << endl;
|
||||
}
|
||||
|
||||
|
||||
cout << "-----------------------------------------------------" << endl
|
||||
<< "Catching exceptions: " << endl
|
||||
<< c1
|
||||
<< "-----------------------------------------------------" << endl;
|
||||
{
|
||||
cout << "* Trying getGene(10,1): " << endl;
|
||||
try {
|
||||
c1.getGene( 10,1 );
|
||||
} catch (exception& e ) {
|
||||
cerr << e.what() << endl;
|
||||
}
|
||||
}
|
||||
{
|
||||
cout << "* Trying getGene(1,10): " << endl;
|
||||
try {
|
||||
c1.getGene( 1,10) ;
|
||||
} catch (exception& e ) {
|
||||
cerr << e.what() << endl;
|
||||
}
|
||||
}
|
||||
{
|
||||
cout << "* Trying setGene( 10,1,999 ): " << endl;
|
||||
try {
|
||||
c1.setGene( 10,1,999 );
|
||||
} catch (exception& e ) {
|
||||
cerr << e.what() << endl;
|
||||
}
|
||||
}
|
||||
{
|
||||
cout << "* Trying setGene( 1,10,999 ): " << endl;
|
||||
try {
|
||||
c1.setGene( 1,10,999 );
|
||||
} catch (exception& e ) {
|
||||
cerr << e.what() << endl;
|
||||
}
|
||||
}
|
||||
{
|
||||
unsigned u1=111;
|
||||
vector<T> v1( 4, u1 );
|
||||
cout << "* Trying insertRow( 10, v1 ): " << endl;
|
||||
try {
|
||||
c1.insertRow( 10,v1 );
|
||||
} catch (exception& e ) {
|
||||
cerr << e.what() << endl;
|
||||
}
|
||||
}
|
||||
{
|
||||
unsigned u1=111;
|
||||
vector<T> v1( 5, u1 );
|
||||
cout << "* Trying insertRow( 1, v1 ) with v1.size()=5: " << endl;
|
||||
try {
|
||||
c1.insertRow( 1,v1 );
|
||||
} catch (exception& e ) {
|
||||
cerr << e.what() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
cout << "* Trying deleteRow( 10 ): " << endl;
|
||||
try {
|
||||
c1.deleteRow( 10 );
|
||||
} catch (exception& e ) {
|
||||
cerr << e.what() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
unsigned u1=111;
|
||||
vector<T> v1( 3, u1 );
|
||||
cout << "* Trying insertCol( 10,v1 ): " << endl;
|
||||
try {
|
||||
c1.insertCol( 10,v1 );
|
||||
} catch (exception& e ) {
|
||||
cerr << e.what() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
unsigned u1=111;
|
||||
vector<T> v1( 5, u1 );
|
||||
cout << "* Trying insertCol( 1,v1 ) with v1.size()=5: " << endl;
|
||||
try {
|
||||
c1.insertCol( 1,v1 );
|
||||
} catch (exception& e ) {
|
||||
cerr << e.what() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
cout << "* Trying deleteCol( 10 ): " << endl;
|
||||
try {
|
||||
c1.deleteCol( 10 );
|
||||
} catch (exception& e ) {
|
||||
cerr << e.what() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
66
trunk/paradiseo-eo/test/t-eoAtomOps.cpp
Normal file
66
trunk/paradiseo-eo/test/t-eoAtomOps.cpp
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
/* -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
t-eoAtomOps.cpp
|
||||
Program that tests the atomic operator classes
|
||||
|
||||
(c) GeNeura Team, 1999
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; 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
|
||||
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------------//
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable:4786)
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
|
||||
using namespace std;
|
||||
|
||||
// Operators we are going to test
|
||||
#include <eoAtomCreep.h>
|
||||
#include <eoAtomBitFlip.h>
|
||||
#include <eoAtomRandom.h>
|
||||
#include <eoAtomMutation.h>
|
||||
|
||||
// Several EOs
|
||||
#include <other/eoString.h>
|
||||
|
||||
// RNGs
|
||||
#include <eoNegExp.h>
|
||||
|
||||
main(int argc, char *argv[]) {
|
||||
eoString<float> aString("123456");
|
||||
eoAtomCreep<char> creeper;
|
||||
eoAtomMutation< eoString<float> > mutator( creeper, 0.5 );
|
||||
|
||||
eoNegExp<char> charNE( 2 );
|
||||
eoAtomRandom<char> randomer( charNE );
|
||||
eoAtomMutation< eoString<float> > mutator2 ( randomer, 0.5 );
|
||||
|
||||
std::cout << "Before aString " << aString << std::endl;
|
||||
mutator( aString);
|
||||
std::cout << " after mutator " << aString << std::endl;
|
||||
mutator2( aString);
|
||||
std::cout << " after mutator2 " << aString << std::endl;;
|
||||
return 0; // to avoid VC++ complaints
|
||||
}
|
||||
|
||||
26
trunk/paradiseo-eo/test/t-eoBaseFunctions.cpp
Normal file
26
trunk/paradiseo-eo/test/t-eoBaseFunctions.cpp
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
|
||||
#include <eoBaseFunctions.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct eo1 : public eoF<void>
|
||||
{
|
||||
void operator()(void) {}
|
||||
};
|
||||
|
||||
struct eo2 : public eoF<int>
|
||||
{
|
||||
int operator()(void) { return 1; }
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
eo1 _1; _1();
|
||||
eo2 _2;
|
||||
int i = _2();
|
||||
|
||||
std::cout << i << '\n';
|
||||
return i;
|
||||
}
|
||||
128
trunk/paradiseo-eo/test/t-eoCMAES.cpp
Normal file
128
trunk/paradiseo-eo/test/t-eoCMAES.cpp
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
|
||||
#include <iostream>
|
||||
|
||||
#include <eoScalarFitness.h>
|
||||
#include <eoVector.h>
|
||||
#include <eoPop.h>
|
||||
#include <utils/eoParser.h>
|
||||
#include <utils/eoCheckPoint.h>
|
||||
#include <eoEvalFuncPtr.h>
|
||||
|
||||
#include <eoGenContinue.h>
|
||||
#include <eoFitContinue.h>
|
||||
#include <utils/eoStdoutMonitor.h>
|
||||
#include <utils/eoStat.h>
|
||||
#include <utils/eoTimedMonitor.h>
|
||||
|
||||
#include <eoMergeReduce.h>
|
||||
#include <eoEasyEA.h>
|
||||
|
||||
#include <es/CMAState.h>
|
||||
#include <es/CMAParams.h>
|
||||
#include <es/eoCMAInit.h>
|
||||
#include <es/eoCMABreed.h>
|
||||
|
||||
using namespace eo;
|
||||
using namespace std;
|
||||
|
||||
typedef eoMinimizingFitness FitT;
|
||||
typedef eoVector<FitT, double> EoType;
|
||||
|
||||
double sqr(double x) { return x*x; }
|
||||
|
||||
eoValueParam<int> evals(0,"Function Evals","Number of Evaluations");
|
||||
|
||||
double f_sphere(const vector<double>& values) {
|
||||
double sum = 0.0;
|
||||
for (unsigned i = 0; i < values.size(); ++i) {
|
||||
sum += values[i] * values[i];
|
||||
}
|
||||
++evals.value();
|
||||
return sum;
|
||||
}
|
||||
|
||||
double f_rosen(const vector<double>& x) {
|
||||
double sum =0.0;
|
||||
|
||||
for (int i = 0; i < x.size()-1; ++i) {
|
||||
sum += 100 * sqr(sqr(x[i])-x[i+1]) + sqr(1.-x[i]);
|
||||
}
|
||||
++evals.value();
|
||||
return sum;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
|
||||
// make sure we have a dimensionality parameter (for testing)
|
||||
char** rargv = new char*[argc+1];
|
||||
rargv[0] = argv[0];
|
||||
rargv[1] = "-N10";
|
||||
for (int i = 2; i < argc; ++i) {
|
||||
rargv[i] = argv[i-1];
|
||||
}
|
||||
|
||||
eoParser parser(argc+1, rargv);
|
||||
|
||||
CMAParams params(parser);
|
||||
|
||||
vector<double> initial_point(params.n, 0.0);
|
||||
|
||||
CMAState state(params, initial_point);
|
||||
|
||||
if (parser.userNeedsHelp())
|
||||
{
|
||||
parser.printHelp(std::cout);
|
||||
return 1;
|
||||
}
|
||||
|
||||
eoCMAInit<FitT> init(state);
|
||||
|
||||
eoPop<EoType> pop(params.mu, init);
|
||||
|
||||
eoEvalFuncPtr<EoType, double, const vector<double>&> eval( f_rosen );
|
||||
|
||||
eoCMABreed<FitT> breed(state, params.lambda);
|
||||
|
||||
for (unsigned i = 0; i < pop.size(); ++i) {
|
||||
eval(pop[i]);
|
||||
}
|
||||
|
||||
eoCommaReplacement<EoType> comma;
|
||||
|
||||
eoGenContinue<EoType> gen(params.maxgen);
|
||||
eoFitContinue<EoType> fit(1e-10);
|
||||
|
||||
eoCheckPoint<EoType> checkpoint(gen);
|
||||
checkpoint.add(fit);
|
||||
|
||||
eoBestFitnessStat<EoType> stat;
|
||||
|
||||
eoStdoutMonitor mon;
|
||||
mon.add(stat);
|
||||
mon.add(evals);
|
||||
|
||||
eoTimedMonitor timed(1);// 1 seconds
|
||||
timed.add(mon); // wrap it
|
||||
|
||||
checkpoint.add(timed);
|
||||
checkpoint.add(stat);
|
||||
|
||||
eoEasyEA<EoType> algo(
|
||||
checkpoint,
|
||||
eval,
|
||||
breed,
|
||||
comma);
|
||||
|
||||
|
||||
algo(pop);
|
||||
pop.sort();
|
||||
|
||||
cout << pop[0] << endl;
|
||||
cout << "Fitness achieved = " << pop[0].fitness() << endl;
|
||||
cout << "Function evaluations = " << evals.value() << endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
183
trunk/paradiseo-eo/test/t-eoCheckpointing.cpp
Normal file
183
trunk/paradiseo-eo/test/t-eoCheckpointing.cpp
Normal file
|
|
@ -0,0 +1,183 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
|
||||
// to avoid long name warnings
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable:4786)
|
||||
#endif
|
||||
|
||||
#include <stdexcept> // runtime_error
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// tt.cpp:
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
// general
|
||||
#include <utils/eoRNG.h> // Random number generators
|
||||
#include <ga.h>
|
||||
#include <utils/eoParser.h>
|
||||
#include <utils/eoState.h>
|
||||
#include <eoGenContinue.h>
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// include package checkpointing
|
||||
#include <utils/checkpointing>
|
||||
|
||||
struct Dummy : public EO<double>
|
||||
{
|
||||
typedef double Type;
|
||||
};
|
||||
|
||||
|
||||
struct eoDummyPop : public eoPop<Dummy>
|
||||
{
|
||||
public :
|
||||
eoDummyPop(int s = 2) { resize(s); }
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
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> factor(0.99, "mutationFactor", "Decrease factor for mutation rate");
|
||||
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");
|
||||
parser.processParam(load_name, "Persistence");
|
||||
parser.processParam(save_name, "Persistence");
|
||||
parser.processParam(seed, "Rng seeding");
|
||||
|
||||
eoState state;
|
||||
state.registerObject(parser);
|
||||
|
||||
if (load_name.value() != "")
|
||||
{ // 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);
|
||||
// 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
|
||||
// Parameter's value is passed by reference, so every time the incrementer increments,
|
||||
// the data in generationCounter will change.
|
||||
eoIncrementor<unsigned> increment(generationCounter.value());
|
||||
|
||||
// Add it to the checkpoint, this will result in the counter being incremented every generation
|
||||
checkpoint.add(increment);
|
||||
|
||||
// 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);
|
||||
|
||||
// the monitor can monitor parameters such as the generationCounter
|
||||
monitor.add(generationCounter);
|
||||
|
||||
// Second moment stats: average and stdev
|
||||
eoSecondMomentStats<EoType> stats;
|
||||
|
||||
// Add it to the checkpoint to get it called at the appropriate time
|
||||
checkpoint.add(stats);
|
||||
|
||||
// Add it to the monitor to get it written to the file
|
||||
monitor.add(stats);
|
||||
|
||||
// save state every third generation
|
||||
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);
|
||||
checkpoint.add(stateSaver2);
|
||||
|
||||
// Register the algorithm
|
||||
state.registerObject(rng);
|
||||
state.registerObject(pop);
|
||||
|
||||
if (parser.userNeedsHelp())
|
||||
{
|
||||
parser.printHelp(std::cout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Either load or initialize
|
||||
if (load_name.value() != "")
|
||||
{
|
||||
state.load(load_name.value()); // load the rest
|
||||
}
|
||||
else
|
||||
{
|
||||
// else
|
||||
|
||||
// initialize rng and population
|
||||
|
||||
rng.reseed(seed.value());
|
||||
|
||||
pop.resize(2);
|
||||
|
||||
pop[0].fitness(1);
|
||||
pop[1].fitness(2);
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
std::cout << "gen " << generationCounter.value() << std::endl;
|
||||
}
|
||||
|
||||
// run the algorithm
|
||||
|
||||
// Save when needed
|
||||
if (save_name.value() != "")
|
||||
{
|
||||
std::string file_name = save_name.value();
|
||||
save_name.value() = ""; // so that it does not appear in the parser section of the state file
|
||||
state.save(file_name);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
try
|
||||
{
|
||||
the_main(argc, argv);
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
std::cout << "Exception: " << e.what() << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
150
trunk/paradiseo-eo/test/t-eoESAll.cpp
Normal file
150
trunk/paradiseo-eo/test/t-eoESAll.cpp
Normal file
|
|
@ -0,0 +1,150 @@
|
|||
// Program to test several EO-ES features
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable:4786)
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <stdexcept>
|
||||
#include <ctime>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <crtdbg.h>
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include <eo>
|
||||
|
||||
// representation specific
|
||||
#include <es/make_es.h>
|
||||
|
||||
#include "real_value.h" // the sphere fitness
|
||||
|
||||
// Now the main
|
||||
///////////////
|
||||
typedef eoMinimizingFitness FitT;
|
||||
|
||||
template <class EOT>
|
||||
void runAlgorithm(EOT, eoParser& _parser, eoState& _state);
|
||||
|
||||
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.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);
|
||||
}
|
||||
else if (stdevsParam.value() == false)
|
||||
{
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Using eoEsFull" << std::endl;
|
||||
runAlgorithm(eoEsFull<FitT>(), parser, state);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// A main that catches the exceptions
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
#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(argc, argv);
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
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)
|
||||
*/
|
||||
template <class EOT>
|
||||
void runAlgorithm(EOT, eoParser& _parser, eoState& _state)
|
||||
{
|
||||
typedef typename EOT::Fitness FitT;
|
||||
|
||||
///// 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 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);
|
||||
|
||||
//// 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);
|
||||
|
||||
// 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);
|
||||
|
||||
//// GO
|
||||
///////
|
||||
std::cout << "Initial Population\n";
|
||||
pop.sortedPrintOn(std::cout);
|
||||
std::cout << std::endl;
|
||||
|
||||
run_ea(ga, pop); // run the ga
|
||||
|
||||
std::cout << "Final Population\n";
|
||||
pop.sortedPrintOn(std::cout);
|
||||
std::cout << std::endl;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue