Added Marc's ES files and .dsp files for others

This commit is contained in:
jmerelo 1999-11-15 09:26:33 +00:00
commit 449ed17ff8
71 changed files with 6359 additions and 4825 deletions

View file

@ -13,7 +13,28 @@ 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
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_eoAtomOps_SOURCES = t-eoAtomOps.cpp
t_eoAtomOps_DEPENDENCIES = $(DEPS)
t_eoAtomOps_LDFLAGS = -lm
t_eoAtomOps_LDADD = $(LDADDS)
###############################################################################
t_eoESOps_SOURCES = t-eoESOps.cpp
t_eoESOps_DEPENDENCIES = $(DEPS)
t_eoESOps_LDFLAGS = -lm
t_eoESOps_LDADD = $(LDADDS)
###############################################################################
t_eoESFull_SOURCES = t-eoESFull.cpp real_value.h
t_eoESFull_DEPENDENCIES = $(DEPS)
t_eoESFull_LDFLAGS = -lm
t_eoESFull_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 = :
@ -86,7 +87,28 @@ 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
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_eoAtomOps_SOURCES = t-eoAtomOps.cpp
t_eoAtomOps_DEPENDENCIES = $(DEPS)
t_eoAtomOps_LDFLAGS = -lm
t_eoAtomOps_LDADD = $(LDADDS)
###############################################################################
t_eoESOps_SOURCES = t-eoESOps.cpp
t_eoESOps_DEPENDENCIES = $(DEPS)
t_eoESOps_LDFLAGS = -lm
t_eoESOps_LDADD = $(LDADDS)
###############################################################################
t_eoESFull_SOURCES = t-eoESFull.cpp real_value.h
t_eoESFull_DEPENDENCIES = $(DEPS)
t_eoESFull_LDFLAGS = -lm
t_eoESFull_LDADD = $(LDADDS)
###############################################################################
@ -216,6 +238,9 @@ t_eoNonUniform_OBJECTS = t-eoNonUniform.o
t_eoUniform_OBJECTS = t-eoUniform.o
t_eoRandom_OBJECTS = t-eoRandom.o
t_parser_OBJECTS = t-parser.o
t_eoESFull_OBJECTS = t-eoESFull.o
t_eoESOps_OBJECTS = t-eoESOps.o
t_eoAtomOps_OBJECTS = t-eoAtomOps.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)
@ -233,21 +258,16 @@ DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
TAR = gtar
GZIP_ENV = --best
DEP_FILES = .deps/t-eo.P .deps/t-eo2dVector.P .deps/t-eoEasyEA.P \
.deps/t-eoNonUniform.P .deps/t-eoRandom.P .deps/t-eoUniform.P \
.deps/t-eobin.P .deps/t-eobreeder.P .deps/t-eofitness.P \
.deps/t-eogeneration.P .deps/t-eoinclusion.P .deps/t-eoinsertion.P \
.deps/t-eolottery.P .deps/t-eoproblem.P .deps/t-parser.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) $(t_eo2dVector_SOURCES) $(t_eogeneration_SOURCES) $(t_eoEasyEA_SOURCES) $(t_eoNonUniform_SOURCES) $(t_eoUniform_SOURCES) $(t_eoRandom_SOURCES) $(t_parser_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)
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)
all: all-redirect
.SUFFIXES:
.SUFFIXES: .S .c .cc .cpp .lo .o .s
$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
cd $(top_srcdir) && $(AUTOMAKE) --gnu test/Makefile
cd $(top_srcdir) && $(AUTOMAKE) --gnu --include-deps test/Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(BUILT_SOURCES)
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
cd $(top_builddir) \
&& CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
@ -261,6 +281,9 @@ distclean-noinstPROGRAMS:
maintainer-clean-noinstPROGRAMS:
.c.o:
$(COMPILE) -c $<
.s.o:
$(COMPILE) -c $<
@ -277,6 +300,9 @@ distclean-compile:
maintainer-clean-compile:
.c.lo:
$(LIBTOOL) --mode=compile $(COMPILE) -c $<
.s.lo:
$(LIBTOOL) --mode=compile $(COMPILE) -c $<
@ -352,6 +378,18 @@ t-eoRandom: $(t_eoRandom_OBJECTS) $(t_eoRandom_DEPENDENCIES)
t-parser: $(t_parser_OBJECTS) $(t_parser_DEPENDENCIES)
@rm -f t-parser
$(CXXLINK) $(t_parser_LDFLAGS) $(t_parser_OBJECTS) $(t_parser_LDADD) $(LIBS)
t-eoESFull: $(t_eoESFull_OBJECTS) $(t_eoESFull_DEPENDENCIES)
@rm -f t-eoESFull
$(CXXLINK) $(t_eoESFull_LDFLAGS) $(t_eoESFull_OBJECTS) $(t_eoESFull_LDADD) $(LIBS)
t-eoESOps: $(t_eoESOps_OBJECTS) $(t_eoESOps_DEPENDENCIES)
@rm -f t-eoESOps
$(CXXLINK) $(t_eoESOps_LDFLAGS) $(t_eoESOps_OBJECTS) $(t_eoESOps_LDADD) $(LIBS)
t-eoAtomOps: $(t_eoAtomOps_OBJECTS) $(t_eoAtomOps_DEPENDENCIES)
@rm -f t-eoAtomOps
$(CXXLINK) $(t_eoAtomOps_LDFLAGS) $(t_eoAtomOps_OBJECTS) $(t_eoAtomOps_LDADD) $(LIBS)
.cc.o:
$(CXXCOMPILE) -c $<
.cc.lo:
@ -395,91 +433,16 @@ distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
subdir = test
distdir: $(DISTFILES)
here=`cd $(top_builddir) && pwd`; \
top_distdir=`cd $(top_distdir) && pwd`; \
distdir=`cd $(distdir) && pwd`; \
cd $(top_srcdir) \
&& $(AUTOMAKE) --include-deps --build-dir=$$here --srcdir-name=$(top_srcdir) --output-dir=$$top_distdir --gnu test/Makefile
@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 \
|| cp -p $$d/$$file $(distdir)/$$file || :; \
fi; \
done
DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
-include $(DEP_FILES)
mostlyclean-depend:
clean-depend:
distclean-depend:
-rm -rf .deps
maintainer-clean-depend:
%.o: %.c
@echo '$(COMPILE) -c $<'; \
$(COMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-cp .deps/$(*F).pp .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm .deps/$(*F).pp
%.lo: %.c
@echo '$(LTCOMPILE) -c $<'; \
$(LTCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-sed -e 's/^\([^:]*\)\.o[ ]*:/\1.lo \1.o :/' \
< .deps/$(*F).pp > .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm -f .deps/$(*F).pp
%.o: %.cc
@echo '$(CXXCOMPILE) -c $<'; \
$(CXXCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-cp .deps/$(*F).pp .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm .deps/$(*F).pp
%.lo: %.cc
@echo '$(LTCXXCOMPILE) -c $<'; \
$(LTCXXCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-sed -e 's/^\([^:]*\)\.o[ ]*:/\1.lo \1.o :/' \
< .deps/$(*F).pp > .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm -f .deps/$(*F).pp
%.o: %.cpp
@echo '$(CXXCOMPILE) -c $<'; \
$(CXXCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-cp .deps/$(*F).pp .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm .deps/$(*F).pp
%.lo: %.cpp
@echo '$(LTCXXCOMPILE) -c $<'; \
$(LTCXXCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-sed -e 's/^\([^:]*\)\.o[ ]*:/\1.lo \1.o :/' \
< .deps/$(*F).pp > .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm -f .deps/$(*F).pp
info-am:
info: info-am
dvi-am:
@ -502,7 +465,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:
@ -516,27 +479,27 @@ distclean-generic:
maintainer-clean-generic:
mostlyclean-am: mostlyclean-noinstPROGRAMS mostlyclean-compile \
mostlyclean-libtool mostlyclean-tags mostlyclean-depend \
mostlyclean-libtool mostlyclean-tags \
mostlyclean-generic
mostlyclean: mostlyclean-am
clean-am: clean-noinstPROGRAMS clean-compile clean-libtool clean-tags \
clean-depend clean-generic mostlyclean-am
clean-generic mostlyclean-am
clean: clean-am
distclean-am: distclean-noinstPROGRAMS distclean-compile \
distclean-libtool distclean-tags distclean-depend \
distclean-generic clean-am
distclean-libtool distclean-tags distclean-generic \
clean-am
-rm -f libtool
distclean: distclean-am
maintainer-clean-am: maintainer-clean-noinstPROGRAMS \
maintainer-clean-compile maintainer-clean-libtool \
maintainer-clean-tags maintainer-clean-depend \
maintainer-clean-generic distclean-am
maintainer-clean-tags maintainer-clean-generic \
distclean-am
@echo "This command is intended for maintainers to use;"
@echo "it deletes files that may require special tools to rebuild."
@ -547,14 +510,12 @@ clean-noinstPROGRAMS maintainer-clean-noinstPROGRAMS \
mostlyclean-compile distclean-compile clean-compile \
maintainer-clean-compile mostlyclean-libtool distclean-libtool \
clean-libtool maintainer-clean-libtool tags mostlyclean-tags \
distclean-tags clean-tags maintainer-clean-tags distdir \
mostlyclean-depend distclean-depend clean-depend \
maintainer-clean-depend info-am info dvi-am dvi check check-am \
installcheck-am installcheck install-exec-am install-exec \
install-data-am install-data install-am install uninstall-am uninstall \
all-redirect all-am all installdirs mostlyclean-generic \
distclean-generic clean-generic maintainer-clean-generic clean \
mostlyclean distclean maintainer-clean
distclean-tags clean-tags maintainer-clean-tags distdir info-am info \
dvi-am dvi check check-am installcheck-am installcheck install-exec-am \
install-exec install-data-am install-data install-am install \
uninstall-am uninstall all-redirect all-am all installdirs \
mostlyclean-generic distclean-generic clean-generic \
maintainer-clean-generic clean mostlyclean distclean maintainer-clean
###############################################################################

23
eo/test/real_value.h Normal file
View file

@ -0,0 +1,23 @@
#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) );
}

33
eo/test/t-eoAtomOps.cpp Normal file
View file

@ -0,0 +1,33 @@
// 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
}

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

@ -0,0 +1,107 @@
// Program to test several EO-ES features
#ifdef _MSC_VER
#pragma warning(disable:4786)
#endif
#include <string>
#include <iostream>
#include <iterator>
using namespace std;
// general
#include <eoParser.h> // though contained in all others!
// evolution specific
#include <eoEvalFuncPtr.h>
//#include <eoSequentialOpHolder.h>
//#include <eoFullEA.h>
// representation specific
#include <eoESFullChrom.h> // though contained in following
//#include <eoESReco.h>
//#include <eoESMut.h>
//#include <eoESRandomize.h>
// this fitness
#include "real_value.h" // the sphere fitness
// Now the main
///////////////
typedef eoESFullChrom<float> Ind;
main(int argc, char *argv[]) {
// unsigned mu, lambda;
// bool comma;
// Create the command-line parser
Parser parser( argc, argv, "Basic EA for vector<float> with adaptive mutations");
//reproducible random seed - thanks, Maarten
InitRandom(parser);
// a first Ind, reading its parameters from the parser
// will be used later to inialize the whole population
Ind FirstEO(parser);
// Evaluation
// here we should call some parser-based constructor,
// as many evaluation function need parameters
// and also have some preliminary stuffs to do
eoEvalFuncPtr<Ind> eval( real_value );
/*
// Evolution and population parameters
eoScheme<Ind> the_scheme(parser);
// recombination and mutation operators, reading their parameters from the parser
eoESReco<float> MyReco(parser, FirstEO);
eoESMutate<float> MyMut(parser, FirstEO);
// termination conditions read by the parser
eoTermVector<Ind> the_terms(parser);
// Initialization of the population
// shoudl be called using the parser, in case you want to read from file(s)
eoESRandomize<float> randomize; // an eoESInd randomnizer
eoPop<Ind> pop(the_scheme.PopSize(), FirstEO, randomize);
// eval(pop); // shoudl we call it from inside the constructor???
// ALL parmeters have been read: write them out
// Writing the parameters on arv[0].status
// but of course this can be modified - see the example parser.cpp
parser.outputParam();
// except the help parameter???
if( parser.getBool("-h" , "--help" , "Shows this help")) {
parser.printHelp();
exit(1);
}
unsigned i, iind;
cout << "Initial population: \n" << endl;
for (i = 0; i < pop.size(); ++i) {
eval(pop[i]);
cout << pop[i].fitness() << "\t" << pop[i] << endl;
}
// the Operators
eoSequentialOpHolder <Ind> seqholder;
// seqholder.addOp(MyReco, 1.0);
seqholder.addOp(MyMut, 1.0);
// One generation
eoEvolStep<Ind> evol_scheme(the_scheme, seqholder, eval);
// the algorithm:
eoFullEA<Ind> ea(evol_scheme, the_terms);
ea(pop);
cout << "Final population: \n" << endl;
for (i = 0; i < pop.size(); ++i)
cout << pop[i].fitness() << "\t" << pop[i] << endl;
*/
return 0;
}

116
eo/test/t-eoESOps.cpp Normal file
View file

@ -0,0 +1,116 @@
// Program to test several EO-ES features
#ifdef _MSC_VER
#pragma warning(disable:4786)
#endif
#include <string>
#include <iostream>
#include <iterator>
using namespace std;
// general
#include <eoParser.h> // though contained in all others!
// evolution specific
#include <eoEvalFuncPtr.h>
//#include <eoSequentialOpHolder.h>
//#include <eoFullEA.h>
// representation specific
#include <eoESFullChrom.h> // though contained in following
//#include <eoESReco.h>
#include <eoESFullMut.h>
//#include <eoESRandomize.h>
// this fitness
#include "real_value.h" // the sphere fitness
// Now the main
///////////////
typedef eoESFullChrom<float> Ind;
main(int argc, char *argv[]) {
unsigned mu, lambda;
bool comma;
// Create the command-line parser
Parser parser( argc, argv, "Basic EA for vector<float> with adaptive mutations");
//reproducible random seed - thanks, Maarten
InitRandom(parser);
// a first Ind, reading its parameters from the parser
// will be used later to inialize the whole population
Ind FirstEO(parser);
// Evaluation
// here we should call some parser-based constructor,
// as many evaluation function need parameters
// and also have some preliminary stuffs to do
eoEvalFuncPtr<Ind> eval( real_value );
// recombination and mutation operators, reading their parameters from the parser
eoESMutate<float> MyMut(parser,
FirstEO.StdDevLength(), FirstEO.size(),
FirstEO.CorCffLength() );
cout << "First EO " << FirstEO << endl;
MyMut(FirstEO);
cout << "First EO mutated" << FirstEO << endl;
/*
// Evolution and population parameters
eoScheme<Ind> the_scheme(parser);
// recombination and mutation operators, reading their parameters from the parser
eoESReco<float> MyReco(parser, FirstEO);
eoESMutate<float> MyMut(parser, FirstEO);
// termination conditions read by the parser
eoTermVector<Ind> the_terms(parser);
// Initialization of the population
// shoudl be called using the parser, in case you want to read from file(s)
eoESRandomize<float> randomize; // an eoESInd randomnizer
eoPop<Ind> pop(the_scheme.PopSize(), FirstEO, randomize);
// eval(pop); // shoudl we call it from inside the constructor???
// ALL parmeters have been read: write them out
// Writing the parameters on arv[0].status
// but of course this can be modified - see the example parser.cpp
parser.outputParam();
// except the help parameter???
if( parser.getBool("-h" , "--help" , "Shows this help")) {
parser.printHelp();
exit(1);
}
unsigned i, iind;
cout << "Initial population: \n" << endl;
for (i = 0; i < pop.size(); ++i) {
eval(pop[i]);
cout << pop[i].fitness() << "\t" << pop[i] << endl;
}
// the Operators
eoSequentialOpHolder <Ind> seqholder;
// seqholder.addOp(MyReco, 1.0);
seqholder.addOp(MyMut, 1.0);
// One generation
eoEvolStep<Ind> evol_scheme(the_scheme, seqholder, eval);
// the algorithm:
eoFullEA<Ind> ea(evol_scheme, the_terms);
ea(pop);
cout << "Final population: \n" << endl;
for (i = 0; i < pop.size(); ++i)
cout << pop[i].fitness() << "\t" << pop[i] << endl;
return 0;
*/
}

View file

@ -1,31 +1,31 @@
//-----------------------------------------------------------------------------
// t-eoNonUniform.cc
//-----------------------------------------------------------------------------
#include <iostream>
#include <eo>
//-----------------------------------------------------------------------------
main()
{
eoNonUniform nu(1000);
cout << "----------------------------------------------------------" << endl
<< "nu.step() = " << nu.step()
<< "\t nu.num_step() = " << nu.num_step() << endl
<< "----------------------------------------------------------" << endl;
eoLinear l1(0, 1, nu), l2(1, 0, nu);
eoNegExp2 n1(0.1, 8, nu), n2(0.75, 3, nu);
for (; nu; ++nu)
{
cout << nu.step()
<< "\t" << l1() << "\t" << l2()
<< "\t" << n1() << "\t" << n2()
<< endl;
}
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// t-eoNonUniform.cc
//-----------------------------------------------------------------------------
#include <iostream>
#include <eo>
//-----------------------------------------------------------------------------
main()
{
eoNonUniform nu(1000);
cout << "----------------------------------------------------------" << endl
<< "nu.step() = " << nu.step()
<< "\t nu.num_step() = " << nu.num_step() << endl
<< "----------------------------------------------------------" << endl;
eoLinear l1(0, 1, nu), l2(1, 0, nu);
eoNegExp2 n1(0.1, 8, nu), n2(0.75, 3, nu);
for (; nu; ++nu)
{
cout << nu.step()
<< "\t" << l1() << "\t" << l2()
<< "\t" << n1() << "\t" << n2()
<< endl;
}
}
//-----------------------------------------------------------------------------

View file

@ -1,28 +1,29 @@
//-----------------------------------------------------------------------------
// 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;
}
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// 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
}
//-----------------------------------------------------------------------------

View file

@ -1,22 +1,22 @@
//-----------------------------------------------------------------------------
// t-eouniform
//-----------------------------------------------------------------------------
#include <iostream> // cout
#include <strstream> // ostrstream, istrstream
#include <eoUniform.h> // eoBin
//-----------------------------------------------------------------------------
main() {
eoUniform<float> u1(-2.5,3.5);
eoUniform<double> u2(0.003, 0 );
eoUniform<unsigned long> u3( 10000U, 10000000U);
cout << "u1\t\tu2\t\tu3" << endl;
for ( unsigned i = 0; i < 100; i ++) {
cout << u1() << "\t" << u2() << "\t" << u3() << endl;
}
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// t-eouniform
//-----------------------------------------------------------------------------
#include <iostream> // cout
#include <strstream> // ostrstream, istrstream
#include <eoUniform.h> // eoBin
//-----------------------------------------------------------------------------
main() {
eoUniform<float> u1(-2.5,3.5);
eoUniform<double> u2(0.003, 0 );
eoUniform<unsigned long> u3( 10000U, 10000000U);
cout << "u1\t\tu2\t\tu3" << endl;
for ( unsigned i = 0; i < 100; i ++) {
cout << u1() << "\t" << u2() << "\t" << u3() << endl;
}
}
//-----------------------------------------------------------------------------

View file

@ -1,71 +1,71 @@
//-----------------------------------------------------------------------------
// t-eobreeder.cpp
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// t-eobreeder.cpp
//-----------------------------------------------------------------------------
// to avoid long name warnings
#pragma warning(disable:4786)
#include <eoBin.h> // eoBin, eoPop, eoBreeder
#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;
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
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;
}
//-----------------------------------------------------------------------------

View file

@ -1,87 +1,87 @@
//-----------------------------------------------------------------------------
// t-eofitness.cpp
// (c) GeNeura Team 1998
//-----------------------------------------------------------------------------
#include <time.h> // time
#include <stdlib.h> // srand, rand
#include <iostream> // cout
#include <eo> // eoFitness
//-----------------------------------------------------------------------------
class eoFloat: public eoFitness
{
public:
eoFloat(const float x) { fitness = x; }
eoFloat(const int x) { fitness = static_cast<float>(x); }
bool operator<(const eoFitness& other) const
{
const eoFloat& x = (const eoFloat&) other;
return fitness < x.fitness;
}
operator float() const
{
return fitness;
}
void printOn(ostream& os) const
{
os << fitness;
}
void readFrom(istream& is)
{
is >> fitness;
}
private:
float fitness;
};
//-----------------------------------------------------------------------------
main()
{
srand(time(0));
eoFloat a = static_cast<float>(rand()) / RAND_MAX,
b = static_cast<float>(rand()) / RAND_MAX;
cout.precision(2);
unsigned repeat = 2;
while (repeat--)
{
cout << "------------------------------------------------------" << endl;
cout << "testing < ";
if (a < b)
cout << a << " < " << b << " is true" << endl;
else
cout << a << " < " << b << " is false" <<endl;
cout << "testing > ";
if (a > b)
cout << a << " > " << b << " is true" << endl;
else
cout << a << " > " << b << " is false" <<endl;
cout << "testing == ";
if (a == b)
cout << a << " == " << b << " is true" << endl;
else
cout << a << " == " << b << " is false" <<endl;
cout << "testing != ";
if (a != b)
cout << a << " != " << b << " is true" << endl;
else
cout << a << " != " << b << " is false" <<endl;
a = b;
}
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// t-eofitness.cpp
// (c) GeNeura Team 1998
//-----------------------------------------------------------------------------
#include <time.h> // time
#include <stdlib.h> // srand, rand
#include <iostream> // cout
#include <eo> // eoFitness
//-----------------------------------------------------------------------------
class eoFloat: public eoFitness
{
public:
eoFloat(const float x) { fitness = x; }
eoFloat(const int x) { fitness = static_cast<float>(x); }
bool operator<(const eoFitness& other) const
{
const eoFloat& x = (const eoFloat&) other;
return fitness < x.fitness;
}
operator float() const
{
return fitness;
}
void printOn(ostream& os) const
{
os << fitness;
}
void readFrom(istream& is)
{
is >> fitness;
}
private:
float fitness;
};
//-----------------------------------------------------------------------------
main()
{
srand(time(0));
eoFloat a = static_cast<float>(rand()) / RAND_MAX,
b = static_cast<float>(rand()) / RAND_MAX;
cout.precision(2);
unsigned repeat = 2;
while (repeat--)
{
cout << "------------------------------------------------------" << endl;
cout << "testing < ";
if (a < b)
cout << a << " < " << b << " is true" << endl;
else
cout << a << " < " << b << " is false" <<endl;
cout << "testing > ";
if (a > b)
cout << a << " > " << b << " is true" << endl;
else
cout << a << " > " << b << " is false" <<endl;
cout << "testing == ";
if (a == b)
cout << a << " == " << b << " is true" << endl;
else
cout << a << " == " << b << " is false" <<endl;
cout << "testing != ";
if (a != b)
cout << a << " != " << b << " is true" << endl;
else
cout << a << " != " << b << " is false" <<endl;
a = b;
}
}
//-----------------------------------------------------------------------------

View file

@ -1,82 +1,82 @@
//-----------------------------------------------------------------------------
// 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;
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// 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;
}
//-----------------------------------------------------------------------------

View file

@ -1,108 +1,108 @@
//-----------------------------------------------------------------------------
// t-eoinsertion.cpp
//-----------------------------------------------------------------------------
#include <eo> // eoBin, eoPop, eoInsertion
//-----------------------------------------------------------------------------
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 CHROM_SIZE = 4;
unsigned i;
eoUniform<Chrom::Type> uniform(false, true);
eoBinRandom<Chrom> random;
for (unsigned POP_SIZE = 4; POP_SIZE <=6; POP_SIZE++)
{
eoPop<Chrom> pop;
for (i = 0; i < POP_SIZE; i++)
{
Chrom chrom(CHROM_SIZE);
random(chrom);
binary_value(chrom);
pop.push_back(chrom);
}
for (unsigned POP2_SIZE = 4; POP2_SIZE <=6; POP2_SIZE++)
{
eoPop<Chrom> pop2, pop3, pop4, pop5, popx;
for (i = 0; i < POP2_SIZE; i++)
{
Chrom chrom(CHROM_SIZE);
random(chrom);
binary_value(chrom);
pop2.push_back(chrom);
}
cout << "--------------------------------------------------" << endl
<< "breeders \tpop" << endl
<< "--------------------------------------------------" << endl;
for (i = 0; i < max(pop.size(), pop2.size()); i++)
{
if (pop.size() > i)
cout << pop[i] << " " << pop[i].fitness() << " \t";
else
cout << "\t\t";
if (pop2.size() > i)
cout << pop2[i] << " " << pop2[i].fitness();
cout << endl;
}
eoInsertion<Chrom> insertion(0.75);
popx = pop;
pop3 = pop2;
insertion(popx, pop3);
eoInsertion<Chrom> insertion2;
popx = pop;
pop4 = pop2;
insertion2(popx, pop4);
eoInsertion<Chrom> insertion3(1.5);
popx = pop;
pop5 = pop2;
insertion3(popx, pop5);
cout << endl
<< "0.75 \t\t1.0 \t\t1.5" << endl
<< "---- \t\t--- \t\t---" << endl;
for (i = 0; i < pop5.size(); i++)
{
if (pop3.size() > i)
cout << pop3[i] << " " << pop3[i].fitness() << " \t";
else
cout << " \t\t";
if (pop4.size() > i)
cout << pop4[i] << " " << pop4[i].fitness() << " \t";
else
cout << " \t\t";
if (pop5.size() > i)
cout << pop5[i] << " " << pop5[i].fitness();
cout << endl;
}
}
}
return 0;
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// t-eoinsertion.cpp
//-----------------------------------------------------------------------------
#include <eo> // eoBin, eoPop, eoInsertion
//-----------------------------------------------------------------------------
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 CHROM_SIZE = 4;
unsigned i;
eoUniform<Chrom::Type> uniform(false, true);
eoBinRandom<Chrom> random;
for (unsigned POP_SIZE = 4; POP_SIZE <=6; POP_SIZE++)
{
eoPop<Chrom> pop;
for (i = 0; i < POP_SIZE; i++)
{
Chrom chrom(CHROM_SIZE);
random(chrom);
binary_value(chrom);
pop.push_back(chrom);
}
for (unsigned POP2_SIZE = 4; POP2_SIZE <=6; POP2_SIZE++)
{
eoPop<Chrom> pop2, pop3, pop4, pop5, popx;
for (i = 0; i < POP2_SIZE; i++)
{
Chrom chrom(CHROM_SIZE);
random(chrom);
binary_value(chrom);
pop2.push_back(chrom);
}
cout << "--------------------------------------------------" << endl
<< "breeders \tpop" << endl
<< "--------------------------------------------------" << endl;
for (i = 0; i < max(pop.size(), pop2.size()); i++)
{
if (pop.size() > i)
cout << pop[i] << " " << pop[i].fitness() << " \t";
else
cout << "\t\t";
if (pop2.size() > i)
cout << pop2[i] << " " << pop2[i].fitness();
cout << endl;
}
eoInsertion<Chrom> insertion(0.75);
popx = pop;
pop3 = pop2;
insertion(popx, pop3);
eoInsertion<Chrom> insertion2;
popx = pop;
pop4 = pop2;
insertion2(popx, pop4);
eoInsertion<Chrom> insertion3(1.5);
popx = pop;
pop5 = pop2;
insertion3(popx, pop5);
cout << endl
<< "0.75 \t\t1.0 \t\t1.5" << endl
<< "---- \t\t--- \t\t---" << endl;
for (i = 0; i < pop5.size(); i++)
{
if (pop3.size() > i)
cout << pop3[i] << " " << pop3[i].fitness() << " \t";
else
cout << " \t\t";
if (pop4.size() > i)
cout << pop4[i] << " " << pop4[i].fitness() << " \t";
else
cout << " \t\t";
if (pop5.size() > i)
cout << pop5[i] << " " << pop5[i].fitness();
cout << endl;
}
}
}
return 0;
}
//-----------------------------------------------------------------------------

View file

@ -1,165 +1,133 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
/* parser.cpp
example of use of Parser.h
(c) geneura team, 1999
-----------------------------------------------------------------------------*/
#include <eoParser.h>
#include <eoRNG.h>
#include <sys/time.h>
void GetOutputParam(Parser & parser,
string & _string) {
try {
parser.AddTitle("Separate parameter: the output file name");
_string = parser.getString("-O", "--OutputFile", "", "The output file name" );
} catch (UException & e) {
cout << e.what() << endl;
parser.printHelp();
exit(1);
} catch (exception & e) {
cout << e.what() << endl;
exit(1);
}
}
void sub(Parser & parser) {
int i;
cout << "Function sub:" << endl;
try {
parser.AddTitle("Private parameters of subroutine sub");
i = parser.getInt("-j", "--sint", "5", "private integer of subroutine" );
} catch (UException & e) {
cout << e.what() << endl;
parser.printHelp();
exit(1);
} catch (exception & e) {
cout << e.what() << endl;
exit(1);
}
cout << "Read " << i << endl;
}
/// Uses the parser and returns param values
void getParams( Parser & parser,
unsigned & _integer,
float & _floating,
string & _string,
vector<string> & _array,
bool & _boolean) {
try {
_integer = parser.getInt("-i", "--int", "2", "interger number" );
_floating = parser.getFloat("-f", "--float", "0.2", "floating point number" );
_string = parser.getString("-s", "--string", "string", "a string" );
_array = parser.getArray("-a", "--array", "a b", "an array enclosed within < >" );
_boolean = parser.getBool("-b","--bool", "a bool value" );
}
catch (UException & e)
{
cout << e.what() << endl;
parser.printHelp();
exit(1);
}
catch (exception & e)
{
cout << e.what() << endl;
exit(1);
}
}
/// Uses the parser and returns param values
void InitRandom( Parser & parser) {
unsigned long _seed;
try {
_seed = parser.getUnsignedLong("-S", "--seed", "0", "Seed for Random number generator" );
}
catch (UException & e)
{
cout << e.what() << endl;
parser.printHelp();
exit(1);
}
catch (exception & e)
{
cout << e.what() << endl;
exit(1);
}
if (_seed == 0) { // use clock to get a "random" seed
struct timeval tval;
struct timezone tzp;
gettimeofday (&tval, &tzp); // time since midnight January 1, 1970.
_seed = tval.tv_usec ; // micro seconds
char s[32];
sprintf(s,"%ld", _seed);
parser.setParamValue("--seed", s); // so it will be printed out in the status file, and canbe later re-used to re-run EXACTLY the same run
}
rng.reseed(_seed);
return;
}
int main( int argc, char* argv[]) {
unsigned in;
float f;
string s;
vector<string> a;
bool b;
// Create the command-line parser
Parser parser( argc, argv, "Parser example");
InitRandom(parser);
parser.AddTitle("General parameters");
getParams(parser, in, f, s, a, b);
cout << "\n integer: " << in << endl
<< " float: "<< f << endl
<< " string: /"<< s << "/" << endl
<< " boolean: "<< b << endl
<< " array: < ";
vector<string>::const_iterator i;
for (i=a.begin() ; i<a.end() ; i++) {
cout << *i << " ";
}
cout << ">" << endl << endl ;
// call to the subroutine that also needs some parameters
sub(parser);
// writing all parameters
//
// if programmer wishes, the name of the output file can be set as a parameter itself
// otherwise it will be argv[0].status
string OutputFileName;
GetOutputParam(parser, OutputFileName);
parser.outputParam(OutputFileName);
if( parser.getBool("-h" , "--help" , "Shows this help")) {
parser.printHelp();
exit(1);
}
// but progrmamer should be careful to write the parser parameters
// after the last bit that uses it has finished
// Now the main body of the program
for (int i=0; i<20; i++) {
cout << rng.normal() << endl;
}
cout << "C'est fini" << endl;
return 0;
}
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
/* parser.cpp
example of use of Parser.h
(c) geneura team, 1999
-----------------------------------------------------------------------------*/
#include <eoParser.h>
#include <eoRNG.h>
#include <sys/time.h>
void GetOutputParam(Parser & parser,
string & _string) {
try {
parser.AddTitle("Separate parameter: the output file name");
_string = parser.getString("-O", "--OutputFile", "", "The output file name" );
} catch (UException & e) {
cout << e.what() << endl;
parser.printHelp();
exit(1);
} catch (exception & e) {
cout << e.what() << endl;
exit(1);
}
}
void sub(Parser & parser) {
int i;
cout << "Function sub:" << endl;
try {
parser.AddTitle("Private parameters of subroutine sub");
i = parser.getInt("-j", "--sint", "5", "private integer of subroutine" );
} catch (UException & e) {
cout << e.what() << endl;
parser.printHelp();
exit(1);
} catch (exception & e) {
cout << e.what() << endl;
exit(1);
}
cout << "Read " << i << endl;
}
/// Uses the parser and returns param values
void getParams( Parser & parser,
unsigned & _integer,
float & _floating,
string & _string,
vector<string> & _array,
bool & _boolean) {
try {
_integer = parser.getInt("-i", "--int", "2", "interger number" );
_floating = parser.getFloat("-f", "--float", "0.2", "floating point number" );
_string = parser.getString("-s", "--string", "string", "a string" );
_array = parser.getArray("-a", "--array", "a b", "an array enclosed within < >" );
_boolean = parser.getBool("-b","--bool", "a bool value" );
}
catch (UException & e)
{
cout << e.what() << endl;
parser.printHelp();
exit(1);
}
catch (exception & e)
{
cout << e.what() << endl;
exit(1);
}
}
int main( int argc, char* argv[]) {
unsigned in;
float f;
string s;
vector<string> a;
bool b;
// Create the command-line parser
Parser parser( argc, argv, "Parser example");
InitRandom(parser);
parser.AddTitle("General parameters");
getParams(parser, in, f, s, a, b);
cout << "\n integer: " << in << endl
<< " float: "<< f << endl
<< " string: /"<< s << "/" << endl
<< " boolean: "<< b << endl
<< " array: < ";
vector<string>::const_iterator i;
for (i=a.begin() ; i<a.end() ; i++) {
cout << *i << " ";
}
cout << ">" << endl << endl ;
// call to the subroutine that also needs some parameters
sub(parser);
// writing all parameters
//
// if programmer wishes, the name of the output file can be set as a parameter itself
// otherwise it will be argv[0].status
string OutputFileName;
GetOutputParam(parser, OutputFileName);
parser.outputParam(OutputFileName);
if( parser.getBool("-h" , "--help" , "Shows this help")) {
parser.printHelp();
exit(1);
}
// but progrmamer should be careful to write the parser parameters
// after the last bit that uses it has finished
// Now the main body of the program
for (int i=0; i<20; i++) {
cout << rng.normal() << endl;
}
cout << "C'est fini" << endl;
return 0;
}