testing and debugging eoGeneration
This commit is contained in:
parent
49b35da8f9
commit
1247f801fb
7 changed files with 156 additions and 149 deletions
|
|
@ -60,11 +60,12 @@
|
||||||
#include <eoBitOp.h>
|
#include <eoBitOp.h>
|
||||||
|
|
||||||
#include <eoLottery.h>
|
#include <eoLottery.h>
|
||||||
|
|
||||||
#include <eoBreeder.h>
|
#include <eoBreeder.h>
|
||||||
|
|
||||||
#include <eoInsertion.h>
|
#include <eoInsertion.h>
|
||||||
#include <eoInclusion.h>
|
#include <eoInclusion.h>
|
||||||
|
#include <eoGeneration.h>
|
||||||
|
|
||||||
|
#include <eoProportionalOpSel.h>
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// to be continued ...
|
// to be continued ...
|
||||||
|
|
|
||||||
|
|
@ -18,19 +18,20 @@ template<class Chrom> class eoGeneration
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// Constructor.
|
/// Constructor.
|
||||||
eoGeneration(eoSelect& _select,
|
eoGeneration(eoSelect<Chrom>& _select,
|
||||||
eoTranform& _transform,
|
eoTransform<Chrom>& _transform,
|
||||||
eoMerge& _replace):
|
eoMerge<Chrom>& _replace):
|
||||||
select(_select), transform(_transform), replace(_replace) {}
|
select(_select), transform(_transform), replace(_replace) {}
|
||||||
|
|
||||||
/// apply one generation of evolution to the population
|
/// Apply one generation of evolution to the population.
|
||||||
void operator()(eoPop& pop)
|
template<class Evaluator> void operator()(eoPop<Chrom>& pop,
|
||||||
|
Evaluator evaluator)
|
||||||
{
|
{
|
||||||
eoPop breeders;
|
eoPop<Chrom> breeders;
|
||||||
|
|
||||||
select(pop, breeders);
|
select(pop, breeders);
|
||||||
transform(breeders);
|
transform(breeders);
|
||||||
for_each(pop.begin(), pop.end(), Chrom::Fitness);
|
for_each(breeders.begin(), breeders.end(), evaluator);
|
||||||
replace(breeders, pop);
|
replace(breeders, pop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -38,9 +39,9 @@ template<class Chrom> class eoGeneration
|
||||||
string className() const { return "eoGeneration"; }
|
string className() const { return "eoGeneration"; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
eoSelect& select;
|
eoSelect<Chrom>& select;
|
||||||
eoTranform& transform;
|
eoTransform<Chrom>& transform;
|
||||||
eoMerge& replace;
|
eoMerge<Chrom>& replace;
|
||||||
};
|
};
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,8 @@
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#include <eoMerge.h>
|
#include <eoPop.h> // eoPop
|
||||||
|
#include <eoPopOps.h> // eoMerge
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* eoInsertion: A replacement algorithm.
|
* eoInsertion: A replacement algorithm.
|
||||||
|
|
|
||||||
|
|
@ -1,57 +0,0 @@
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// eoMerge.h
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#ifndef eoMerge_h
|
|
||||||
#define eoMerge_h
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#include <eoPop.h> // eoPop
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
/** eoMerge involves three populations, that can be merged and transformed to
|
|
||||||
give a third
|
|
||||||
*/
|
|
||||||
template<class EOT>
|
|
||||||
class eoMerge: public eoObject{
|
|
||||||
|
|
||||||
public:
|
|
||||||
/// (Default) Constructor.
|
|
||||||
eoMerge(const float& _rate = 1.0): rep_rate(_rate) {}
|
|
||||||
|
|
||||||
/// Dtor
|
|
||||||
virtual ~eoMerge() {}
|
|
||||||
|
|
||||||
/** Pure virtual transformation function. Extracts something from breeders
|
|
||||||
* and transfers it to the pop
|
|
||||||
* @param breeders Tranformed individuals.
|
|
||||||
* @param pop The original population at the begining, the result at the end
|
|
||||||
*/
|
|
||||||
virtual void operator () ( eoPop<EOT>& breeders, eoPop<EOT>& pop ) = 0;
|
|
||||||
|
|
||||||
/** @name Methods from eoObject */
|
|
||||||
//@{
|
|
||||||
/** readFrom and printOn are not overriden
|
|
||||||
*/
|
|
||||||
/** Inherited from eoObject. Returns the class name.
|
|
||||||
@see eoObject
|
|
||||||
*/
|
|
||||||
string className() const {return "eoMerge";};
|
|
||||||
//@}
|
|
||||||
|
|
||||||
/// Return the rate to be selected from the original population
|
|
||||||
float rate() const { return rep_rate; }
|
|
||||||
|
|
||||||
/// Set the rate to be obtained after replacement.
|
|
||||||
/// @param _rate The rate.
|
|
||||||
void rate(const float& _rate) { rep_rate = _rate; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
float rep_rate;
|
|
||||||
};
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#endif eoMerge_h
|
|
||||||
|
|
@ -1,28 +1,28 @@
|
||||||
// eoPopOps.h
|
// eoPopOps.h
|
||||||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// eo1d.h
|
// eo1d.h
|
||||||
// (c) GeNeura Team, 1998
|
// (c) GeNeura Team, 1998
|
||||||
/*
|
/*
|
||||||
This library is free software; you can redistribute it and/or
|
This library is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU Lesser General Public
|
modify it under the terms of the GNU Lesser General Public
|
||||||
License as published by the Free Software Foundation; either
|
License as published by the Free Software Foundation; either
|
||||||
version 2 of the License, or (at your option) any later version.
|
version 2 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
This library is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
Lesser General Public License for more details.
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
You should have received a copy of the GNU Lesser General Public
|
||||||
License along with this library; if not, write to the Free Software
|
License along with this library; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
||||||
*/
|
*/
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef _EOPOPOPS_H
|
#ifndef _EOPOPOPS_H
|
||||||
#define _EOPOPOPS_H
|
#define _EOPOPOPS_H
|
||||||
|
|
||||||
|
|
@ -31,71 +31,113 @@ using namespace std;
|
||||||
/**
|
/**
|
||||||
@author Geneura Team
|
@author Geneura Team
|
||||||
@version 0.0
|
@version 0.0
|
||||||
*/
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
#include <eoPop.h>
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
/** eoTransform is a class that transforms or does something on a population.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
#include <eoPop.h>
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
/** eoTransform is a class that transforms or does something on a population.
|
||||||
|
*/
|
||||||
template<class EOT>
|
template<class EOT>
|
||||||
class eoTransform: public eoObject{
|
class eoTransform: public eoObject{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/** ctor */
|
/** ctor */
|
||||||
eoTransform() {};
|
eoTransform() {};
|
||||||
|
|
||||||
/// Dtor
|
|
||||||
virtual ~eoTransform(){};
|
|
||||||
|
|
||||||
/// Pure virtual transformation function. Does something on the population
|
|
||||||
virtual void operator () ( eoPop<EOT>& _pop ) = 0;
|
|
||||||
|
|
||||||
/** @name Methods from eoObject */
|
/// Dtor
|
||||||
//@{
|
virtual ~eoTransform(){};
|
||||||
|
|
||||||
|
/// Pure virtual transformation function. Does something on the population
|
||||||
|
virtual void operator () ( eoPop<EOT>& _pop ) = 0;
|
||||||
|
|
||||||
|
/** @name Methods from eoObject */
|
||||||
|
//@{
|
||||||
/** readFrom and printOn are not overriden
|
/** readFrom and printOn are not overriden
|
||||||
*/
|
*/
|
||||||
/** Inherited from eoObject. Returns the class name.
|
/** Inherited from eoObject. Returns the class name.
|
||||||
@see eoObject
|
@see eoObject
|
||||||
*/
|
*/
|
||||||
string className() const {return "eoTransform";};
|
string className() const {return "eoTransform";};
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** eoSelect usually takes elements from one population, with or without
|
//-----------------------------------------------------------------------------
|
||||||
transformation, and transfers them to the other population
|
|
||||||
*/
|
/** eoSelect usually takes elements from one population, with or without transformation, and transfers them to the other population */
|
||||||
template<class EOT>
|
template<class EOT>
|
||||||
class eoSelect: public eoObject{
|
class eoSelect: public eoObject{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/** ctor
|
/** ctor
|
||||||
*/
|
*/
|
||||||
eoSelect() {};
|
eoSelect() {};
|
||||||
|
|
||||||
/// Dtor
|
/// Dtor
|
||||||
virtual ~eoSelect(){};
|
virtual ~eoSelect(){};
|
||||||
|
|
||||||
/** Pure virtual transformation function. Extracts something from the parents,
|
/** Pure virtual transformation function. Extracts something from the parents,
|
||||||
and transfers it to the siblings
|
and transfers it to the siblings
|
||||||
@param _parents the initial generation. Will be kept constant
|
@param _parents the initial generation. Will be kept constant
|
||||||
@param _siblings the created offspring. Will be usually an empty population
|
@param _siblings the created offspring. Will be usually an empty population
|
||||||
*/
|
*/
|
||||||
virtual void operator () ( const eoPop<EOT>& _parents, eoPop<EOT>& _siblings ) const = 0;
|
virtual void operator () ( const eoPop<EOT>& _parents, eoPop<EOT>& _siblings ) const = 0;
|
||||||
|
|
||||||
/** @name Methods from eoObject */
|
/** @name Methods from eoObject */
|
||||||
//@{
|
//@{
|
||||||
/** readFrom and printOn are not overriden
|
/** readFrom and printOn are not overriden
|
||||||
*/
|
*/
|
||||||
/** Inherited from eoObject. Returns the class name.
|
/** Inherited from eoObject. Returns the class name.
|
||||||
@see eoObject
|
@see eoObject
|
||||||
*/
|
*/
|
||||||
string className() const {return "eoSelect";};
|
string className() const {return "eoSelect";};
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** eoMerge involves three populations, that can be merged and transformed to
|
||||||
|
give a third
|
||||||
|
*/
|
||||||
|
template<class EOT>
|
||||||
|
class eoMerge: public eoObject{
|
||||||
|
|
||||||
|
public:
|
||||||
|
/// (Default) Constructor.
|
||||||
|
eoMerge(const float& _rate = 1.0): rep_rate(_rate) {}
|
||||||
|
|
||||||
|
/// Dtor
|
||||||
|
virtual ~eoMerge() {}
|
||||||
|
|
||||||
|
/** Pure virtual transformation function. Extracts something from breeders
|
||||||
|
* and transfers it to the pop
|
||||||
|
* @param breeders Tranformed individuals.
|
||||||
|
* @param pop The original population at the begining, the result at the end
|
||||||
|
*/
|
||||||
|
virtual void operator () ( eoPop<EOT>& breeders, eoPop<EOT>& pop ) = 0;
|
||||||
|
|
||||||
|
/** @name Methods from eoObject */
|
||||||
|
//@{
|
||||||
|
/** readFrom and printOn are not overriden
|
||||||
|
*/
|
||||||
|
/** Inherited from eoObject. Returns the class name.
|
||||||
|
@see eoObject
|
||||||
|
*/
|
||||||
|
string className() const {return "eoMerge";};
|
||||||
|
//@}
|
||||||
|
|
||||||
|
/// Return the rate to be selected from the original population
|
||||||
|
float rate() const { return rep_rate; }
|
||||||
|
|
||||||
|
/// Set the rate to be obtained after replacement.
|
||||||
|
/// @param _rate The rate.
|
||||||
|
void rate(const float& _rate) { rep_rate = _rate; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
float rep_rate;
|
||||||
|
};
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,14 @@ LDADDS = $(top_builddir)/src/libeo.a
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
noinst_PROGRAMS = t-eobreeder t-eoinclusion t-eoinsertion t-eo t-eofitness t-eoproblem t-eobin t-eolottery
|
noinst_PROGRAMS = t-eogeneration t-eobreeder t-eoinclusion t-eoinsertion t-eo t-eofitness t-eoproblem t-eobin t-eolottery
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
t_eogeneration_SOURCES = t-eogeneration.cpp
|
||||||
|
t_eogeneration_DEPENDENCIES = $(DEPS)
|
||||||
|
t_eogeneration_LDFLAGS = -lm
|
||||||
|
t_eogeneration_LDADD = $(LDADDS)
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,14 @@ LDADDS = $(top_builddir)/src/libeo.a
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
noinst_PROGRAMS = t-eobreeder t-eoinclusion t-eoinsertion t-eo t-eofitness t-eoproblem t-eobin t-eolottery
|
noinst_PROGRAMS = t-eogeneration t-eobreeder t-eoinclusion t-eoinsertion t-eo t-eofitness t-eoproblem t-eobin t-eolottery
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
t_eogeneration_SOURCES = t-eogeneration.cpp
|
||||||
|
t_eogeneration_DEPENDENCIES = $(DEPS)
|
||||||
|
t_eogeneration_LDFLAGS = -lm
|
||||||
|
t_eogeneration_LDADD = $(LDADDS)
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
|
@ -148,6 +155,7 @@ DEFS = @DEFS@ -I. -I$(srcdir)
|
||||||
CPPFLAGS = @CPPFLAGS@
|
CPPFLAGS = @CPPFLAGS@
|
||||||
LDFLAGS = @LDFLAGS@
|
LDFLAGS = @LDFLAGS@
|
||||||
LIBS = @LIBS@
|
LIBS = @LIBS@
|
||||||
|
t_eogeneration_OBJECTS = t-eogeneration.o
|
||||||
t_eobreeder_OBJECTS = t-eobreeder.o
|
t_eobreeder_OBJECTS = t-eobreeder.o
|
||||||
t_eoinclusion_OBJECTS = t-eoinclusion.o
|
t_eoinclusion_OBJECTS = t-eoinclusion.o
|
||||||
t_eoinsertion_OBJECTS = t-eoinsertion.o
|
t_eoinsertion_OBJECTS = t-eoinsertion.o
|
||||||
|
|
@ -174,10 +182,10 @@ DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
|
||||||
TAR = gtar
|
TAR = gtar
|
||||||
GZIP_ENV = --best
|
GZIP_ENV = --best
|
||||||
DEP_FILES = .deps/t-eo.P .deps/t-eobin.P .deps/t-eobreeder.P \
|
DEP_FILES = .deps/t-eo.P .deps/t-eobin.P .deps/t-eobreeder.P \
|
||||||
.deps/t-eofitness.P .deps/t-eoinclusion.P .deps/t-eoinsertion.P \
|
.deps/t-eofitness.P .deps/t-eogeneration.P .deps/t-eoinclusion.P \
|
||||||
.deps/t-eolottery.P .deps/t-eoproblem.P
|
.deps/t-eoinsertion.P .deps/t-eolottery.P .deps/t-eoproblem.P
|
||||||
SOURCES = $(t_eobreeder_SOURCES) $(t_eoinclusion_SOURCES) $(t_eoinsertion_SOURCES) $(t_eo_SOURCES) $(t_eofitness_SOURCES) $(t_eoproblem_SOURCES) $(t_eobin_SOURCES) $(t_eolottery_SOURCES)
|
SOURCES = $(t_eogeneration_SOURCES) $(t_eobreeder_SOURCES) $(t_eoinclusion_SOURCES) $(t_eoinsertion_SOURCES) $(t_eo_SOURCES) $(t_eofitness_SOURCES) $(t_eoproblem_SOURCES) $(t_eobin_SOURCES) $(t_eolottery_SOURCES)
|
||||||
OBJECTS = $(t_eobreeder_OBJECTS) $(t_eoinclusion_OBJECTS) $(t_eoinsertion_OBJECTS) $(t_eo_OBJECTS) $(t_eofitness_OBJECTS) $(t_eoproblem_OBJECTS) $(t_eobin_OBJECTS) $(t_eolottery_OBJECTS)
|
OBJECTS = $(t_eogeneration_OBJECTS) $(t_eobreeder_OBJECTS) $(t_eoinclusion_OBJECTS) $(t_eoinsertion_OBJECTS) $(t_eo_OBJECTS) $(t_eofitness_OBJECTS) $(t_eoproblem_OBJECTS) $(t_eobin_OBJECTS) $(t_eolottery_OBJECTS)
|
||||||
|
|
||||||
all: all-redirect
|
all: all-redirect
|
||||||
.SUFFIXES:
|
.SUFFIXES:
|
||||||
|
|
@ -231,6 +239,10 @@ distclean-libtool:
|
||||||
|
|
||||||
maintainer-clean-libtool:
|
maintainer-clean-libtool:
|
||||||
|
|
||||||
|
t-eogeneration: $(t_eogeneration_OBJECTS) $(t_eogeneration_DEPENDENCIES)
|
||||||
|
@rm -f t-eogeneration
|
||||||
|
$(CXXLINK) $(t_eogeneration_LDFLAGS) $(t_eogeneration_OBJECTS) $(t_eogeneration_LDADD) $(LIBS)
|
||||||
|
|
||||||
t-eobreeder: $(t_eobreeder_OBJECTS) $(t_eobreeder_DEPENDENCIES)
|
t-eobreeder: $(t_eobreeder_OBJECTS) $(t_eobreeder_DEPENDENCIES)
|
||||||
@rm -f t-eobreeder
|
@rm -f t-eobreeder
|
||||||
$(CXXLINK) $(t_eobreeder_LDFLAGS) $(t_eobreeder_OBJECTS) $(t_eobreeder_LDADD) $(LIBS)
|
$(CXXLINK) $(t_eobreeder_LDFLAGS) $(t_eobreeder_OBJECTS) $(t_eobreeder_LDADD) $(LIBS)
|
||||||
|
|
|
||||||
Reference in a new issue