testing and debugging eoGeneration

This commit is contained in:
gustavo 1999-09-28 11:56:21 +00:00
commit 1247f801fb
7 changed files with 156 additions and 149 deletions

View file

@ -60,11 +60,12 @@
#include <eoBitOp.h>
#include <eoLottery.h>
#include <eoBreeder.h>
#include <eoInsertion.h>
#include <eoInclusion.h>
#include <eoGeneration.h>
#include <eoProportionalOpSel.h>
//-----------------------------------------------------------------------------
// to be continued ...

View file

@ -18,19 +18,20 @@ template<class Chrom> class eoGeneration
{
public:
/// Constructor.
eoGeneration(eoSelect& _select,
eoTranform& _transform,
eoMerge& _replace):
eoGeneration(eoSelect<Chrom>& _select,
eoTransform<Chrom>& _transform,
eoMerge<Chrom>& _replace):
select(_select), transform(_transform), replace(_replace) {}
/// apply one generation of evolution to the population
void operator()(eoPop& pop)
/// Apply one generation of evolution to the population.
template<class Evaluator> void operator()(eoPop<Chrom>& pop,
Evaluator evaluator)
{
eoPop breeders;
eoPop<Chrom> breeders;
select(pop, breeders);
transform(breeders);
for_each(pop.begin(), pop.end(), Chrom::Fitness);
for_each(breeders.begin(), breeders.end(), evaluator);
replace(breeders, pop);
}
@ -38,9 +39,9 @@ template<class Chrom> class eoGeneration
string className() const { return "eoGeneration"; }
private:
eoSelect& select;
eoTranform& transform;
eoMerge& replace;
eoSelect<Chrom>& select;
eoTransform<Chrom>& transform;
eoMerge<Chrom>& replace;
};
//-----------------------------------------------------------------------------

View file

@ -7,7 +7,8 @@
//-----------------------------------------------------------------------------
#include <eoMerge.h>
#include <eoPop.h> // eoPop
#include <eoPopOps.h> // eoMerge
/******************************************************************************
* eoInsertion: A replacement algorithm.

View file

@ -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

View file

@ -1,28 +1,28 @@
// eoPopOps.h
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// eo1d.h
// (c) GeNeura Team, 1998
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// eo1d.h
// (c) GeNeura Team, 1998
/*
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
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
*/
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
#ifndef _EOPOPOPS_H
#define _EOPOPOPS_H
@ -31,71 +31,113 @@ using namespace std;
/**
@author Geneura Team
@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>
class eoTransform: public eoObject{
public:
/** ctor */
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
*/
*/
/** Inherited from eoObject. Returns the class name.
@see eoObject
*/
string className() const {return "eoTransform";};
@see eoObject
*/
string className() const {return "eoTransform";};
//@}
};
/** eoSelect usually takes elements from one population, with or without
transformation, and transfers them to the other population
*/
template<class EOT>
class eoSelect: public eoObject{
public:
/** ctor
*/
eoSelect() {};
/// Dtor
virtual ~eoSelect(){};
/** Pure virtual transformation function. Extracts something from the parents,
and transfers it to the siblings
@param _parents the initial generation. Will be kept constant
@param _siblings the created offspring. Will be usually an empty population
*/
virtual void operator () ( const eoPop<EOT>& _parents, eoPop<EOT>& _siblings ) const = 0;
/** @name Methods from eoObject */
//@{
/** readFrom and printOn are not overriden
*/
/** Inherited from eoObject. Returns the class name.
@see eoObject
*/
string className() const {return "eoSelect";};
//@}
};
};
//-----------------------------------------------------------------------------
/** eoSelect usually takes elements from one population, with or without transformation, and transfers them to the other population */
template<class EOT>
class eoSelect: public eoObject{
public:
/** ctor
*/
eoSelect() {};
/// Dtor
virtual ~eoSelect(){};
/** Pure virtual transformation function. Extracts something from the parents,
and transfers it to the siblings
@param _parents the initial generation. Will be kept constant
@param _siblings the created offspring. Will be usually an empty population
*/
virtual void operator () ( const eoPop<EOT>& _parents, eoPop<EOT>& _siblings ) const = 0;
/** @name Methods from eoObject */
//@{
/** readFrom and printOn are not overriden
*/
/** Inherited from eoObject. Returns the class name.
@see eoObject
*/
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

View file

@ -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)
###############################################################################

View file

@ -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@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
t_eogeneration_OBJECTS = t-eogeneration.o
t_eobreeder_OBJECTS = t-eobreeder.o
t_eoinclusion_OBJECTS = t-eoinclusion.o
t_eoinsertion_OBJECTS = t-eoinsertion.o
@ -174,10 +182,10 @@ DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
TAR = gtar
GZIP_ENV = --best
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-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)
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)
.deps/t-eofitness.P .deps/t-eogeneration.P .deps/t-eoinclusion.P \
.deps/t-eoinsertion.P .deps/t-eolottery.P .deps/t-eoproblem.P
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_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
.SUFFIXES:
@ -231,6 +239,10 @@ distclean-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)
@rm -f t-eobreeder
$(CXXLINK) $(t_eobreeder_LDFLAGS) $(t_eobreeder_OBJECTS) $(t_eobreeder_LDADD) $(LIBS)