Changes
This commit is contained in:
parent
de33c67f0e
commit
d3642e4fde
12 changed files with 397 additions and 207 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -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
87
eo/test/t-selectOne.cpp
Normal 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;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
Loading…
Add table
Add a link
Reference in a new issue