This commit is contained in:
jmerelo 1999-12-17 09:19:13 +00:00
commit d3642e4fde
12 changed files with 397 additions and 207 deletions

View file

@ -4,9 +4,14 @@
##
###############################################################################
SUBDIRS = src test
SUBDIRS = src test win
#Directory for documents
DOCDIR = ~/public_html/eodocs
#Directory for indices -- not useful for the user
IDXDIR = ~/index
EXTRA_DIST=LICENSE
docs:
doc++ -d $(DOCDIR) -B foot.html -f src/*.h src/*.cpp
/home/jmerelo/bin/index -e html -i /home/jmerelo/index/neweo.idx /home/jmerelo/public_html/eodocs/ -v 3
/home/jmerelo/bin/index -e html -i $(IDXDIR)/neweo.idx $(DOCDIR)/ -v 3

View file

@ -1,11 +1,13 @@
AC_INIT(src/eo)
AM_INIT_AUTOMAKE(eo, 0.0.5)
AM_INIT_AUTOMAKE(eo, 0.0.8)
AC_PROG_CXX
CXXFLAGS=-g
AM_PROG_LIBTOOL
AM_MAINTAINER_MODE
AC_OUTPUT(Makefile src/Makefile test/Makefile)
AC_OUTPUT(Makefile src/Makefile test/Makefile win/Makefile)

View file

@ -1,78 +1,76 @@
//-----------------------------------------------------------------------------
// eoBin.h
//-----------------------------------------------------------------------------
#ifndef eoBin_h
#define eoBin_h
//-----------------------------------------------------------------------------
#include <iostream> // ostream, istream
#include <functional> // bind2nd
#include <string> // string
#include <eoVector.h> // EO
/*****************************************************************************
* eoBin: implementation of binary chromosome. *
* based on STL's bit_vector (vector<bool>). *
*****************************************************************************/
template <class F> class eoBin: public eoVector<bool, F>
{
public:
/**
* (Default) Constructor.
* @param size Size of the binary string.
*/
eoBin(unsigned size = 0, bool value = false):
eoVector<bool,F>(size, value) {}
/**
* Constructor.
* @param size Size of the binary string.
*/
eoBin(unsigned size, const eoRnd<bool>& rnd): eoVector<bool,F>(size)
{
generate(begin(), end(), rnd);
}
/** Constructor from istream.
@param is The istream to read from.*/
eoBin(istream& _is):eoVector<bool,F>(_is){};
/// My class name.
string className() const
{
return "eoBin";
}
/**
* To print me on a stream.
* @param os The ostream.
*/
void printOn(ostream& os) const
{
copy(begin(), end(), ostream_iterator<bool>(os));
}
/**
* To read me from a stream.
* @param is The istream.
*/
void readFrom(istream& is)
{
string bits;
is >> bits;
if (is)
{
resize(bits.size());
transform(bits.begin(), bits.end(), begin(),
bind2nd(equal_to<char>(), '1'));
}
}
};
//-----------------------------------------------------------------------------
#endif eoBin_h
//-----------------------------------------------------------------------------
// eoBin.h
//-----------------------------------------------------------------------------
#ifndef eoBin_h
#define eoBin_h
//-----------------------------------------------------------------------------
#include <iostream> // ostream, istream
#include <functional> // bind2nd
#include <string> // string
#include <eoVector.h> // EO
/** eoBin: implementation of binary chromosome.
* based on STL's bit_vector (vector<bool>).
*/
template <class F> class eoBin: public eoVector<bool, F>
{
public:
/**
* (Default) Constructor.
* @param size Size of the binary string.
*/
eoBin(unsigned size = 0, bool value = false):
eoVector<bool,F>(size, value) {}
/**
* Constructor.
* @param size Size of the binary string.
*/
eoBin(unsigned size, const eoRnd<bool>& rnd): eoVector<bool,F>(size)
{
generate(begin(), end(), rnd);
}
/** Constructor from istream.
@param is The istream to read from.*/
eoBin(istream& _is):eoVector<bool,F>(_is){};
/// My class name.
string className() const
{
return "eoBin";
}
/**
* To print me on a stream.
* @param os The ostream.
*/
void printOn(ostream& os) const
{
copy(begin(), end(), ostream_iterator<bool>(os));
}
/**
* To read me from a stream.
* @param is The istream.
*/
void readFrom(istream& is)
{
string bits;
is >> bits;
if (is)
{
resize(bits.size());
transform(bits.begin(), bits.end(), begin(),
bind2nd(equal_to<char>(), '1'));
}
}
};
//-----------------------------------------------------------------------------
#endif eoBin_h

View file

@ -31,10 +31,12 @@
#include <eoEvalFunc.h>
#include <eoPopOps.h> // eoSelect, eoTranform, eoMerge
//-----------------------------------------------------------------------------
// eoGeneration
//-----------------------------------------------------------------------------
/** eoGeneration
* Single step of a evolutionary algorithm. Applies selection, then genetic
* operators, replaces using a replacement policy, and finally evaluates the
* new ones */
template<class Chrom> class eoGeneration: public eoAlgo<Chrom>
{
public:

View file

@ -5,6 +5,7 @@
###############################################################################
DEPS = $(top_builddir)/src/libeo.a
EXTRA_DIST = LICENSE
###############################################################################
@ -13,7 +14,17 @@ 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
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_selectOne_SOURCES = t-selectOne.cpp
t_selectOne_DEPENDENCIES = $(DEPS)
t_selectOne_LDFLAGS = -lm
t_selectOne_LDADD = $(LDADDS)
###############################################################################
@ -73,7 +84,7 @@ t_eoEasyEA_LDADD = $(LDADDS)
###############################################################################
t_eobreeder_SOURCES = t-eobreeder.cpp
t_eobreeder_SOURCES = t-eobreeder.cpp binary_value.h
t_eobreeder_DEPENDENCIES = $(DEPS)
t_eobreeder_LDFLAGS = -lm
t_eobreeder_LDADD = $(LDADDS)

View file

@ -1,4 +1,4 @@
# Makefile.in generated automatically by automake 1.4a from Makefile.am
# Makefile.in generated automatically by automake 1.4 from Makefile.am
# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
@ -49,10 +49,9 @@ AUTOMAKE = @AUTOMAKE@
AUTOHEADER = @AUTOHEADER@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
INSTALL_DATA = @INSTALL_DATA@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_FLAG =
transform = @program_transform_name@
NORMAL_INSTALL = :
@ -79,6 +78,7 @@ RANLIB = @RANLIB@
VERSION = @VERSION@
DEPS = $(top_builddir)/src/libeo.a
EXTRA_DIST = LICENSE
###############################################################################
@ -87,7 +87,15 @@ 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
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_selectOne_SOURCES = t-selectOne.cpp
t_selectOne_DEPENDENCIES = $(DEPS)
t_selectOne_LDFLAGS = -lm
t_selectOne_LDADD = $(LDADDS)
###############################################################################
@ -147,7 +155,7 @@ t_eoEasyEA_LDADD = $(LDADDS)
###############################################################################
t_eobreeder_SOURCES = t-eobreeder.cpp
t_eobreeder_SOURCES = t-eobreeder.cpp binary_value.h
t_eobreeder_DEPENDENCIES = $(DEPS)
t_eobreeder_LDFLAGS = -lm
t_eobreeder_LDADD = $(LDADDS)
@ -241,6 +249,7 @@ t_parser_OBJECTS = t-parser.o
t_eoESFull_OBJECTS = t-eoESFull.o
t_eoESOps_OBJECTS = t-eoESOps.o
t_eoAtomOps_OBJECTS = t-eoAtomOps.o
t_selectOne_OBJECTS = t-selectOne.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)
@ -258,8 +267,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)
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)
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)
all: all-redirect
.SUFFIXES:
@ -390,6 +399,10 @@ t-eoESOps: $(t_eoESOps_OBJECTS) $(t_eoESOps_DEPENDENCIES)
t-eoAtomOps: $(t_eoAtomOps_OBJECTS) $(t_eoAtomOps_DEPENDENCIES)
@rm -f t-eoAtomOps
$(CXXLINK) $(t_eoAtomOps_LDFLAGS) $(t_eoAtomOps_OBJECTS) $(t_eoAtomOps_LDADD) $(LIBS)
t-selectOne: $(t_selectOne_OBJECTS) $(t_selectOne_DEPENDENCIES)
@rm -f t-selectOne
$(CXXLINK) $(t_selectOne_LDFLAGS) $(t_selectOne_OBJECTS) $(t_selectOne_LDADD) $(LIBS)
.cc.o:
$(CXXCOMPILE) -c $<
.cc.lo:
@ -436,7 +449,7 @@ distdir: $(DISTFILES)
@for file in $(DISTFILES); do \
d=$(srcdir); \
if test -d $$d/$$file; then \
cp -pr $$d/$$file $(distdir)/$$file; \
cp -pr $$/$$file $(distdir)/$$file; \
else \
test -f $(distdir)/$$file \
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
@ -465,7 +478,7 @@ uninstall: uninstall-am
all-am: Makefile $(PROGRAMS)
all-redirect: all-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) INSTALL_STRIP_FLAG=-s install
$(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
installdirs:

View file

@ -1,29 +1,53 @@
//-----------------------------------------------------------------------------
// t-eouniform
//-----------------------------------------------------------------------------
#include <iostream> // cout
#include <strstream> // ostrstream, istrstream
#include <eoUniform.h> // eoBin
#include <eoNormal.h>
#include <eoNegExp.h>
//-----------------------------------------------------------------------------
main() {
eoNormal<float> n1(-2.5,3.5);
eoNormal<double> n2(0.003, 0.0005 );
eoNormal<unsigned long> n3( 10000000U, 10000U);
eoNegExp<float> e1(3.5);
eoNegExp<double> e2(0.003 );
eoNegExp<long> e3( 10000U);
cout << "n1\t\tn2\t\tn3\t\te1\t\te2\t\te3" << endl;
for ( unsigned i = 0; i < 100; i ++) {
cout << n1() << "\t" << n2() << "\t" << n3() << "\t" <<
e1() << "\t" << e2() << "\t" << e3() << endl;
}
return 0; // to avoid VC++ complaints
}
//-----------------------------------------------------------------------------
// -*- 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
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.
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
*/
//-----------------------------------------------------------------------------
#include <iostream> // cout
#include <strstream> // ostrstream, istrstream
#include <eoUniform.h> // eoBin
#include <eoNormal.h>
#include <eoNegExp.h>
//-----------------------------------------------------------------------------
main() {
eoNormal<float> n1(-2.5,3.5);
eoNormal<double> n2(0.003, 0.0005 );
eoNormal<unsigned long> n3( 10000000U, 10000U);
eoNegExp<float> e1(3.5);
eoNegExp<double> e2(0.003 );
eoNegExp<long> e3( 10000U);
cout << "n1\t\tn2\t\tn3\t\te1\t\te2\t\te3" << endl;
for ( unsigned i = 0; i < 100; i ++) {
cout << n1() << "\t" << n2() << "\t" << n3() << "\t" <<
e1() << "\t" << e2() << "\t" << e3() << endl;
}
return 0; // to avoid VC++ complaints
}
//-----------------------------------------------------------------------------

View file

@ -1,5 +1,27 @@
// -*- 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.
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
*/
//-----------------------------------------------------------------------------
#include <iostream> // cout
@ -102,7 +124,7 @@ main()
for (float r = 0.1; r < 1.0; r += 0.1)
{
eoBinUxOver<Chrom> uxover(r);
eoUniformXOver<Chrom> uxover(r);
fill(chrom.begin(), chrom.end(), false);
fill(chrom2.begin(), chrom2.end(), true);
uxover(chrom, chrom2);
@ -110,6 +132,20 @@ main()
<< chrom << " " << chrom2 << endl;
}
// Check multiOps
eoMultiMonOp<Chrom> mOp( &next );
mOp.adOp( &bitflip );
cout << "before multiMonOp............ " << chrom << endl;
mOp( chrom );
cout << "after multiMonOp .............. " << chrom << endl;
eoBinGxOver<Chrom> gxover(2, 4);
eoMultiBinOp<Chrom> mbOp( &gxover );
mOp.adOp( &bitflip );
cout << "before multiBinOp............ " << chrom << " " << chrom2 << endl;
mbOp( chrom, chrom2 );
cout << "after multiBinOp .............. " << chrom << " " << chrom2 <<endl;
return 0;
}

View file

@ -1,71 +1,84 @@
//-----------------------------------------------------------------------------
// t-eobreeder.cpp
//-----------------------------------------------------------------------------
// 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 <eoBreeder.h>
//-----------------------------------------------------------------------------
typedef eoBin<float> Chrom;
//-----------------------------------------------------------------------------
void binary_value(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);
}
//-----------------------------------------------------------------------------
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;
eoProportionalOpSel<Chrom> propSel;
eoBreeder<Chrom> breeder( propSel );
propSel.addOp(bitflip, 0.25);
propSel.addOp(xover, 0.75);
breeder(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;
}
//-----------------------------------------------------------------------------
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// t-eobreeder.cpp
// This program test the breeder object
// (c) GeNeura Team, 1998
/*
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.
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
*/
//-----------------------------------------------------------------------------
// 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 <eoBreeder.h>
//-----------------------------------------------------------------------------
typedef eoBin<float> Chrom;
#include "binary_value.h"
//-----------------------------------------------------------------------------
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;
eoProportionalOpSel<Chrom> propSel;
eoBreeder<Chrom> breeder( propSel );
propSel.addOp(bitflip, 0.25);
propSel.addOp(xover, 0.75);
breeder(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

@ -2,22 +2,15 @@
// t-eoinclusion.cpp
//-----------------------------------------------------------------------------
#include <eo> // eoBin, eoPop, eoInclusion
#include <eoBin.h>
#include <eoPop.h>
#include <eoInclusion.h>
//-----------------------------------------------------------------------------
typedef eoBin<float> Chrom;
//-----------------------------------------------------------------------------
void binary_value(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);
}
#include "binary_value.h"
//-----------------------------------------------------------------------------

87
eo/test/t-selectOne.cpp Normal file
View file

@ -0,0 +1,87 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// t-selectOne.cpp
// This program test the breeder object
// (c) GeNeura Team, 1998
/*
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 <eoUniformSelect.h>
#include <eoStochTournament.h>
#include <eoDetTournament.h>
//-----------------------------------------------------------------------------
typedef eoBin<float> Chrom;
#include "binary_value.h"
//-----------------------------------------------------------------------------
main()
{
const unsigned POP_SIZE = 8, CHROM_SIZE = 4;
unsigned i;
eoUniform<Chrom::Type> uniform(false, true);
eoBinRandom<Chrom> random;
eoPop<Chrom> pop;
// Create the population
for (i = 0; i < POP_SIZE; ++i) {
Chrom chrom(CHROM_SIZE);
random(chrom);
binary_value(chrom);
pop.push_back(chrom);
}
// print population
cout << "population:" << endl;
for (i = 0; i < pop.size(); ++i)
cout << pop[i] << " " << pop[i].fitness() << endl;
// Declare 1-selectors
eoUniformSelect<Chrom> uSelect;
Chrom aChrom;
aChrom = uSelect( pop );
cout << "Uniform Select " << aChrom << " " << aChrom.fitness() << endl;
eoStochTournament<Chrom> sSelect(0.7);
aChrom = sSelect( pop );
cout << "Stochastic Tournament " << aChrom << " " << aChrom.fitness() << endl;
eoDetTournament<Chrom> dSelect(3);
aChrom = dSelect( pop );
cout << "Deterministic Tournament " << aChrom << " " << aChrom.fitness() << endl;
return 0;
}
//-----------------------------------------------------------------------------

6
eo/win/Makefile.am Normal file
View file

@ -0,0 +1,6 @@
EXTRA_DIST=EO.dsw random.dsp t_eoinsertion.dsp t_ops.dsp\
atomops.dsp t_eoaged.dsp t_eornd.dsp t_opsel.dsp\
t_eobin.dsp t_eostring.dsp t_opselmason.dsp\
eo.dsp t_eobitfact.dsp t_eovector.dsp t_pop.dsp\
t_eobreeder.dsp t_es.dsp t_popops.dsp\
eolib.dsp t_eoid.dsp t_lottery.dsp\