Added new files to the brew, mainly distance and new-op-interface related

This commit is contained in:
jmerelo 2000-02-07 17:16:16 +00:00
commit 7db1492943
40 changed files with 2490 additions and 992 deletions

View file

@ -17,7 +17,36 @@ LDADDS = $(top_builddir)/src/libeo.a
noinst_PROGRAMS = t-eobreeder t-eoinclusion t-eoinsertion t-eo t-eofitness \
t-eoproblem t-eobin t-eolottery t-eo2dVector t-eogeneration t-eoEasyEA\
t-eoNonUniform t-eoUniform t-eoRandom t-parser t-eoESFull t-eoESOps\
t-eoAtomOps t-selectOne
t-eoAtomOps t-selectOne t-eoaltbreeder t-eoGeneralOps t-eoGOpSel \
t-eoVector
###############################################################################
t_eoVector_SOURCES = t-eoVector.cpp
t_eoVector_DEPENDENCIES = $(DEPS)
t_eoVector_LDFLAGS = -lm
t_eoVector_LDADD = $(LDADDS)
###############################################################################
t_eoGOpSel_SOURCES = t-eoGOpSel.cpp
t_eoGOpSel_DEPENDENCIES = $(DEPS)
t_eoGOpSel_LDFLAGS = -lm
t_eoGOpSel_LDADD = $(LDADDS)
###############################################################################
t_eoGeneralOps_SOURCES = t-eoGeneralOps.cpp
t_eoGeneralOps_DEPENDENCIES = $(DEPS)
t_eoGeneralOps_LDFLAGS = -lm
t_eoGeneralOps_LDADD = $(LDADDS)
###############################################################################
t_eoaltbreeder_SOURCES = t-eoaltbreeder.cpp
t_eoaltbreeder_DEPENDENCIES = $(DEPS)
t_eoaltbreeder_LDFLAGS = -lm
t_eoaltbreeder_LDADD = $(LDADDS)
###############################################################################

View file

@ -1,4 +1,4 @@
# Makefile.in generated automatically by automake 1.4 from Makefile.am
# Makefile.in generated automatically by automake 1.4a from Makefile.am
# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
@ -49,9 +49,10 @@ AUTOMAKE = @AUTOMAKE@
AUTOHEADER = @AUTOHEADER@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_FLAG =
transform = @program_transform_name@
NORMAL_INSTALL = :
@ -72,9 +73,9 @@ LN_S = @LN_S@
MAINT = @MAINT@
MAKEINFO = @MAKEINFO@
NM = @NM@
OBJDUMP = @OBJDUMP@
PACKAGE = @PACKAGE@
RANLIB = @RANLIB@
USE_SYMBOL_UNDERSCORE = @USE_SYMBOL_UNDERSCORE@
VERSION = @VERSION@
DEPS = $(top_builddir)/src/libeo.a
@ -87,9 +88,37 @@ LDADDS = $(top_builddir)/src/libeo.a
###############################################################################
noinst_PROGRAMS = t-eobreeder t-eoinclusion t-eoinsertion t-eo t-eofitness t-eoproblem t-eobin t-eolottery t-eo2dVector t-eogeneration t-eoEasyEA t-eoNonUniform t-eoUniform t-eoRandom t-parser t-eoESFull t-eoESOps t-eoAtomOps t-selectOne
noinst_PROGRAMS = t-eobreeder t-eoinclusion t-eoinsertion t-eo t-eofitness t-eoproblem t-eobin t-eolottery t-eo2dVector t-eogeneration t-eoEasyEA t-eoNonUniform t-eoUniform t-eoRandom t-parser t-eoESFull t-eoESOps t-eoAtomOps t-selectOne t-eoaltbreeder t-eoGeneralOps t-eoGOpSel t-eoVector
###############################################################################
t_eoVector_SOURCES = t-eoVector.cpp
t_eoVector_DEPENDENCIES = $(DEPS)
t_eoVector_LDFLAGS = -lm
t_eoVector_LDADD = $(LDADDS)
###############################################################################
t_eoGOpSel_SOURCES = t-eoGOpSel.cpp
t_eoGOpSel_DEPENDENCIES = $(DEPS)
t_eoGOpSel_LDFLAGS = -lm
t_eoGOpSel_LDADD = $(LDADDS)
###############################################################################
t_eoGeneralOps_SOURCES = t-eoGeneralOps.cpp
t_eoGeneralOps_DEPENDENCIES = $(DEPS)
t_eoGeneralOps_LDFLAGS = -lm
t_eoGeneralOps_LDADD = $(LDADDS)
###############################################################################
t_eoaltbreeder_SOURCES = t-eoaltbreeder.cpp
t_eoaltbreeder_DEPENDENCIES = $(DEPS)
t_eoaltbreeder_LDFLAGS = -lm
t_eoaltbreeder_LDADD = $(LDADDS)
###############################################################################
t_selectOne_SOURCES = t-selectOne.cpp
@ -250,6 +279,10 @@ t_eoESFull_OBJECTS = t-eoESFull.o
t_eoESOps_OBJECTS = t-eoESOps.o
t_eoAtomOps_OBJECTS = t-eoAtomOps.o
t_selectOne_OBJECTS = t-selectOne.o
t_eoaltbreeder_OBJECTS = t-eoaltbreeder.o
t_eoGeneralOps_OBJECTS = t-eoGeneralOps.o
t_eoGOpSel_OBJECTS = t-eoGOpSel.o
t_eoVector_OBJECTS = t-eoVector.o
CXXFLAGS = @CXXFLAGS@
CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
LTCXXCOMPILE = $(LIBTOOL) --mode=compile $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
@ -267,8 +300,8 @@ DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
TAR = gtar
GZIP_ENV = --best
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) $(t_eo2dVector_SOURCES) $(t_eogeneration_SOURCES) $(t_eoEasyEA_SOURCES) $(t_eoNonUniform_SOURCES) $(t_eoUniform_SOURCES) $(t_eoRandom_SOURCES) $(t_parser_SOURCES) $(t_eoESFull_SOURCES) $(t_eoESOps_SOURCES) $(t_eoAtomOps_SOURCES) $(t_selectOne_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) $(t_eo2dVector_OBJECTS) $(t_eogeneration_OBJECTS) $(t_eoEasyEA_OBJECTS) $(t_eoNonUniform_OBJECTS) $(t_eoUniform_OBJECTS) $(t_eoRandom_OBJECTS) $(t_parser_OBJECTS) $(t_eoESFull_OBJECTS) $(t_eoESOps_OBJECTS) $(t_eoAtomOps_OBJECTS) $(t_selectOne_OBJECTS)
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) $(t_eo2dVector_SOURCES) $(t_eogeneration_SOURCES) $(t_eoEasyEA_SOURCES) $(t_eoNonUniform_SOURCES) $(t_eoUniform_SOURCES) $(t_eoRandom_SOURCES) $(t_parser_SOURCES) $(t_eoESFull_SOURCES) $(t_eoESOps_SOURCES) $(t_eoAtomOps_SOURCES) $(t_selectOne_SOURCES) $(t_eoaltbreeder_SOURCES) $(t_eoGeneralOps_SOURCES) $(t_eoGOpSel_SOURCES) $(t_eoVector_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) $(t_eo2dVector_OBJECTS) $(t_eogeneration_OBJECTS) $(t_eoEasyEA_OBJECTS) $(t_eoNonUniform_OBJECTS) $(t_eoUniform_OBJECTS) $(t_eoRandom_OBJECTS) $(t_parser_OBJECTS) $(t_eoESFull_OBJECTS) $(t_eoESOps_OBJECTS) $(t_eoAtomOps_OBJECTS) $(t_selectOne_OBJECTS) $(t_eoaltbreeder_OBJECTS) $(t_eoGeneralOps_OBJECTS) $(t_eoGOpSel_OBJECTS) $(t_eoVector_OBJECTS)
all: all-redirect
.SUFFIXES:
@ -403,6 +436,22 @@ t-eoAtomOps: $(t_eoAtomOps_OBJECTS) $(t_eoAtomOps_DEPENDENCIES)
t-selectOne: $(t_selectOne_OBJECTS) $(t_selectOne_DEPENDENCIES)
@rm -f t-selectOne
$(CXXLINK) $(t_selectOne_LDFLAGS) $(t_selectOne_OBJECTS) $(t_selectOne_LDADD) $(LIBS)
t-eoaltbreeder: $(t_eoaltbreeder_OBJECTS) $(t_eoaltbreeder_DEPENDENCIES)
@rm -f t-eoaltbreeder
$(CXXLINK) $(t_eoaltbreeder_LDFLAGS) $(t_eoaltbreeder_OBJECTS) $(t_eoaltbreeder_LDADD) $(LIBS)
t-eoGeneralOps: $(t_eoGeneralOps_OBJECTS) $(t_eoGeneralOps_DEPENDENCIES)
@rm -f t-eoGeneralOps
$(CXXLINK) $(t_eoGeneralOps_LDFLAGS) $(t_eoGeneralOps_OBJECTS) $(t_eoGeneralOps_LDADD) $(LIBS)
t-eoGOpSel: $(t_eoGOpSel_OBJECTS) $(t_eoGOpSel_DEPENDENCIES)
@rm -f t-eoGOpSel
$(CXXLINK) $(t_eoGOpSel_LDFLAGS) $(t_eoGOpSel_OBJECTS) $(t_eoGOpSel_LDADD) $(LIBS)
t-eoVector: $(t_eoVector_OBJECTS) $(t_eoVector_DEPENDENCIES)
@rm -f t-eoVector
$(CXXLINK) $(t_eoVector_LDFLAGS) $(t_eoVector_OBJECTS) $(t_eoVector_LDADD) $(LIBS)
.cc.o:
$(CXXCOMPILE) -c $<
.cc.lo:
@ -449,7 +498,7 @@ distdir: $(DISTFILES)
@for file in $(DISTFILES); do \
d=$(srcdir); \
if test -d $$d/$$file; then \
cp -pr $$/$$file $(distdir)/$$file; \
cp -pr $$d/$$file $(distdir)/$$file; \
else \
test -f $(distdir)/$$file \
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
@ -478,7 +527,7 @@ uninstall: uninstall-am
all-am: Makefile $(PROGRAMS)
all-redirect: all-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
$(MAKE) $(AM_MAKEFLAGS) INSTALL_STRIP_FLAG=-s install
installdirs:

View file

@ -1,18 +1,18 @@
#include <eo>
//-----------------------------------------------------------------------------
typedef eoBin<float> Chrom;
/** Just a simple function that takes binary value of a chromosome and sets
the fitnes.
@param _chrom A binary chromosome
*/
void binary_value(Chrom& _chrom)
{
float sum = 0;
for (unsigned i = 0; i < _chrom.size(); i++)
if (_chrom[i])
#include <eo>
//-----------------------------------------------------------------------------
typedef eoBin<float> Chrom;
/** Just a simple function that takes binary value of a chromosome and sets
the fitnes.
@param _chrom A binary chromosome
*/
float binary_value(const Chrom& _chrom)
{
float sum = 0;
for (unsigned i = 0; i < _chrom.size(); i++)
if (_chrom[i])
sum += pow(2, _chrom.size() - i - 1);
_chrom.fitness(sum);
}
return sum;
}

View file

@ -1,23 +1,20 @@
#include <eoESFullChrom.h>
//-----------------------------------------------------------------------------
typedef vector<double> Vec;
/** Just a simple function that takes an eoVector<float> and sets the fitnes
to -sphere (we'll see later how to minimize rather than maximize!)
@param _ind A floatingpoint vector
*/
float the_real_value(Vec& _ind)
{
double sum = 0; /* compute in double format, even if return a float */
for (unsigned i = 0; i < _ind.size(); i++)
sum += _ind[i] * _ind[i];
return -sum;
}
typedef eoESFullChrom<float> Ind;
void real_value(Ind & _ind) {
_ind.fitness( the_real_value(_ind) );
}
#include <eoESFullChrom.h>
//-----------------------------------------------------------------------------
typedef vector<double> Vec;
/** Just a simple function that takes an eoVector<float> and sets the fitnes
to -sphere (we'll see later how to minimize rather than maximize!)
@param _ind A floatingpoint vector
*/
float real_value(const eoESFullChrom<float>& _ind)
{
double sum = 0; /* compute in double format, even if return a float */
for (unsigned i = 0; i < _ind.size(); i++)
sum += _ind[i] * _ind[i];
return -sum;
}

View file

@ -1,33 +1,66 @@
// Program to test several EO-ES features
#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 <eoString.h>
main(int argc, char *argv[]) {
eoString<float> aString("123456");
eoAtomCreep<char> creeper;
eoAtomMutation< eoString<float> > mutator( creeper, 0.5 );
cout << "Before aString " << aString;
mutator( aString);
cout << " after mutator " << aString;
return 0; // to avoid VC++ complaints
}
/* -*- 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 <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 );
cout << "Before aString " << aString << endl;
mutator( aString);
cout << " after mutator " << aString << endl;
mutator2( aString);
cout << " after mutator2 " << aString << endl;;
return 0; // to avoid VC++ complaints
}

107
eo/test/t-eoGOpSel.cpp Normal file
View file

@ -0,0 +1,107 @@
/* -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
t-eoGOpSel.cpp
Testing proportional operator selectors
(c) Maarten Keijzer and GeNeura Team, 2000
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
*/
//-----------------------------------------------------------------------------//
// to avoid long name warnings
#pragma warning(disable:4786)
#include "eoBin.h" // eoBin, eoPop, eoBreeder
#include <eoPop.h>
#include <eoBitOp.h>
#include <eoProportionalGOpSel.h>
//#include <eoAltBreeder.h>
// Fitness evaluation
#include "binary_value.h"
//-----------------------------------------------------------------------------
typedef eoBin<float> Chrom;
//-----------------------------------------------------------------------------
main()
{
const unsigned POP_SIZE = 8, CHROM_SIZE = 4;
unsigned i;
eoUniform<Chrom::Type> uniform(false, true);
eoBinRandom<Chrom> random;
eoPop<Chrom> pop;
for (i = 0; i < POP_SIZE; ++i)
{
Chrom chrom(CHROM_SIZE);
random(chrom);
chrom.fitness(binary_value(chrom));
pop.push_back(chrom);
}
cout << "population:" << endl;
for (i = 0; i < pop.size(); ++i)
cout << pop[i] << " " << pop[i].fitness() << endl;
eoBinBitFlip<Chrom> bitflip;
eoBinCrossover<Chrom> xover;
//Create the proportional operator selector and add the
// two operators creatd above to it.
eoProportionalGOpSel<Chrom > propSel;
propSel.addOp(bitflip, 0.5);
propSel.addOp(xover, 0.5);
for ( i = 0; i < POP_SIZE; i ++ ) {
eoGeneralOp<Chrom>& foo = propSel.selectOp();
cout << foo.nInputs() << " "
<< foo.nOutputs() << endl;
}
// eoAltBreeder<Chrom> breeder( propSel );
// breeder(pop);
// eoSequentialOpSelector<Chrom, eoAltBreeder<Chrom>::outIt > seqSel;
// eoAltBreeder<Chrom> breeder2( seqSel );
// seqSel.addOp(bitflip, 0.25);
// seqSel.addOp(xover, 0.75);
// breeder2(pop);
// // reevaluation of fitness
// for_each(pop.begin(), pop.end(), binary_value);
// cout << "new population:" << endl;
// for (i = 0; i < pop.size(); ++i)
// cout << pop[i] << " " << pop[i].fitness() << endl;
return 0;
}
//-----------------------------------------------------------------------------

View file

@ -0,0 +1,71 @@
/* -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
t-eoGeneralOps.cpp
Program that tests the General operator interface, and the wrappers
for monary and unary operators.
(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 <eoString.h>
// generalOp we are testing
#include <eoGeneralOp.h>
main(int argc, char *argv[]) {
eoString<float> aString("123456");
eoAtomCreep<char> creeper;
eoAtomMutation< eoString<float> > mutator( creeper, 0.5 );
eoWrappedMonOp< eoString<float> > wCreeper( mutator );
cout << "Before aString " << aString;
mutator( aString);
cout << " after mutator " << aString;
// Test now the alternative interface
eoPop< eoString<float> > vIn, vOut;
insert_iterator<eoPop<eoString<float> > > ins( vOut, vOut.begin() );
vIn.push_back( aString );
wCreeper( vIn.begin(), ins );
cout << endl << "Before " << vIn[0] << endl << " after " << vOut[0] << endl;;
return 0; // to avoid VC++ complaints
}

View file

@ -1,31 +1,30 @@
// -*- 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; -*-
/*-----------------------------------------------------------------------------
* t-eoRandom
* Testing program for the eoRNG class
* (c) GeNeura Team, 1999
t-eoRandom.cpp
Test program for random generator
This library 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.
(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 library is distributed in the hope that it will be useful,
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
Lesser General Public License for more details.
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 Lesser General Public
License along with this library; if not, write to the Free Software
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
*/
//-----------------------------------------------------------------------------
#include <iostream> // cout
#include <strstream> // ostrstream, istrstream
#include <eoUniform.h> // eoBin

57
eo/test/t-eoVector.cpp Normal file
View file

@ -0,0 +1,57 @@
/* -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
t-eoVectpr.cpp
This program tests vector-like chromosomes
(c) GeNeura Team, 1999, 2000
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
*/
//-----------------------------------------------------------------------------
#include <iostream> // cout
#include <strstream> // ostrstream, istrstream
#include <eoUniform.h>
#include <eoVector.h> // eoVector
#include <eo1dWDistance.h>
//-----------------------------------------------------------------------------
typedef eoVector<float> Chrom;
//-----------------------------------------------------------------------------
main()
{
const unsigned SIZE = 4;
unsigned i, j;
eoUniform<Chrom::Type> uniform(-1,1);
Chrom chrom1(SIZE,uniform), chrom2( SIZE, uniform);
cout << "chrom1: " << chrom1 << endl <<
"chrom2: " << chrom2 << endl;
eo1dWDistance< float, float > chromDist( chrom1 );
cout << "Distance from chrom1 to chrom2 " << chromDist.distance( chrom2 ) << endl;
return 0;
}
//-----------------------------------------------------------------------------

View file

@ -0,0 +1,98 @@
/* -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
t-eoaltbreeder.cpp
Extensive esting of the eoAltBreeder class
(c) Maarten Keijzer and GeNeura Team, 2000
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
*/
//-----------------------------------------------------------------------------//
// to avoid long name warnings
#pragma warning(disable:4786)
#include "eoBin.h" // eoBin, eoPop, eoBreeder
#include <eoPop.h>
#include <eoBitOp.h>
#include <eoProportionalOpSel.h>
#include <eoAltBreeder.h>
// Fitness evaluation
#include "binary_value.h"
//-----------------------------------------------------------------------------
typedef eoBin<float> Chrom;
//-----------------------------------------------------------------------------
main()
{
const unsigned POP_SIZE = 8, CHROM_SIZE = 4;
unsigned i;
eoUniform<Chrom::Type> uniform(false, true);
eoBinRandom<Chrom> random;
eoPop<Chrom> pop;
for (i = 0; i < POP_SIZE; ++i)
{
Chrom chrom(CHROM_SIZE);
random(chrom);
binary_value(chrom);
pop.push_back(chrom);
}
cout << "population:" << endl;
for (i = 0; i < pop.size(); ++i)
cout << pop[i] << " " << pop[i].fitness() << endl;
eoBinBitFlip<Chrom> bitflip;
eoBinCrossover<Chrom> xover;
eoProportionalOpSelector<Chrom, eoAltBreeder<Chrom>::outIt > propSel;
eoAltBreeder<Chrom> breeder( propSel );
propSel.addOp(bitflip, 0.25);
propSel.addOp(xover, 0.75);
breeder(pop);
eoSequentialOpSelector<Chrom, eoAltBreeder<Chrom>::outIt > seqSel;
eoAltBreeder<Chrom> breeder2( seqSel );
seqSel.addOp(bitflip, 0.25);
seqSel.addOp(xover, 0.75);
breeder2(pop);
// reevaluation of fitness
for_each(pop.begin(), pop.end(), binary_value);
cout << "new population:" << endl;
for (i = 0; i < pop.size(); ++i)
cout << pop[i] << " " << pop[i].fitness() << endl;
return 0;
}
//-----------------------------------------------------------------------------

View file

@ -1,24 +1,23 @@
// -*- 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; -*-
//-----------------------------------------------------------------------------
// t-eobin.cpp
// This program test the the binary cromosomes and several genetic operators
// (c) GeNeura Team, 1999
/*
This library 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.
t-eobin.cpp
This program tests the the binary cromosomes and several genetic operators
(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 library is distributed in the hope that it will be useful,
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
Lesser General Public License for more details.
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 Lesser General Public
License along with this library; if not, write to the Free Software
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
*/

View file

@ -1,82 +1,145 @@
//-----------------------------------------------------------------------------
// t-eogeneration.cpp
//-----------------------------------------------------------------------------
// to avoid long name warnings
#pragma warning(disable:4786)
#include <eo>
#include "binary_value.h"
//-----------------------------------------------------------------------------
typedef eoBin<float> Chrom;
//-----------------------------------------------------------------------------
main()
{
const unsigned POP_SIZE = 8, CHROM_SIZE = 16;
unsigned i;
eoUniform<Chrom::Type> uniform(false, true);
eoBinRandom<Chrom> random;
eoPop<Chrom> pop;
for (i = 0; i < POP_SIZE; ++i)
{
Chrom chrom(CHROM_SIZE);
random(chrom);
binary_value(chrom);
pop.push_back(chrom);
}
cout << "population:" << endl;
for (i = 0; i < pop.size(); ++i)
cout << "\t" << pop[i] << " " << pop[i].fitness() << endl;
// selection
eoLottery<Chrom> lottery;
// breeder
eoBinBitFlip<Chrom> bitflip;
eoBinCrossover<Chrom> xover;
eoProportionalOpSel<Chrom> propSel;
eoBreeder<Chrom> breeder( propSel );
propSel.addOp(bitflip, 0.25);
propSel.addOp(xover, 0.75);
// replacement
eoInclusion<Chrom> inclusion;
// Evaluation
eoEvalFuncPtr<Chrom> eval( binary_value );
// GA generation
eoGeneration<Chrom> generation(lottery, breeder, inclusion, eval);
// evolution
unsigned g = 0;
do {
try
{
generation(pop);
}
catch (exception& e)
{
cout << "exception: " << e.what() << endl;;
exit(EXIT_FAILURE);
}
cout << "pop[" << ++g << "]" << endl;
for (i = 0; i < pop.size(); ++i)
cout << "\t" << pop[i] << " " << pop[i].fitness() << endl;
} while (pop[0].fitness() < pow(2.0, CHROM_SIZE) - 1);
return 0;
}
//-----------------------------------------------------------------------------
/* -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
t-eogeneration.cpp
Testing the eoGeneration classes, and classes related to it
(c) GeNeura Team, 1999, 2000
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
*/
//-----------------------------------------------------------------------------//
// to avoid long name warnings
#ifdef _MSC_VER
#pragma warning(disable:4786)
#endif
#include <eoGeneration.h>
#include <eoEvalFuncPtrCnt.h>
#include "binary_value.h"
//-----------------------------------------------------------------------------
typedef eoBin<float> Chrom;
//-----------------------------------------------------------------------------
main()
{
const unsigned POP_SIZE = 8, CHROM_SIZE = 16;
unsigned i;
eoUniform<Chrom::Type> uniform(false, true);
eoBinRandom<Chrom> random;
eoPop<Chrom> pop;
// Evaluation
eoEvalFuncPtr<Chrom> eval( binary_value );
for (i = 0; i < POP_SIZE; ++i)
{
Chrom chrom(CHROM_SIZE);
random(chrom);
eval(chrom);
pop.push_back(chrom);
}
cout << "population:" << endl;
for (i = 0; i < pop.size(); ++i)
cout << "\t" << pop[i] << " " << pop[i].fitness() << endl;
// selection
eoLottery<Chrom> lottery;
// breeder
eoBinBitFlip<Chrom> bitflip;
eoBinCrossover<Chrom> xover;
eoProportionalOpSel<Chrom> propSel;
eoBreeder<Chrom> breeder( propSel );
propSel.addOp(bitflip, 0.25);
propSel.addOp(xover, 0.75);
// replacement
eoInclusion<Chrom> inclusion;
// GA generation
eoGeneration<Chrom> generation(lottery, breeder, inclusion, eval);
// evolution
unsigned g = 0;
do {
try
{
generation(pop);
}
catch (exception& e)
{
cout << "exception: " << e.what() << endl;;
exit(EXIT_FAILURE);
}
cout << "pop[" << ++g << "]" << endl;
for (i = 0; i < pop.size(); ++i)
cout << "\t" << pop[i] << " " << pop[i].fitness() << endl;
} while (pop[0].fitness() < pow(2.0, CHROM_SIZE) - 1);
// Try again, with a "counted" evaluation function
// GA generation
// Evaluation
eoEvalFuncPtrCnt<Chrom> eval2( binary_value );
eoPop<Chrom> pop2;
for (i = 0; i < POP_SIZE; ++i)
{
Chrom chrom(CHROM_SIZE);
random(chrom);
binary_value(chrom);
eval2(chrom);
pop2.push_back(chrom);
}
eoGeneration<Chrom> generation2(lottery, breeder, inclusion, eval2);
// evolution
do {
try
{
generation2(pop2);
}
catch (exception& e)
{
cout << "exception: " << e.what() << endl;;
exit(EXIT_FAILURE);
}
cout << "pop[" << ++g << "]" << endl;
for (i = 0; i < pop2.size(); ++i)
cout << "\t" << pop2[i] << " " << pop[i].fitness() << endl;
} while (pop2[0].fitness() < pow(2.0, CHROM_SIZE) - 1);
cout << "Number of evaluations " << eval2.getNumOfEvaluations() << endl;
return 0;
}
//-----------------------------------------------------------------------------