From 387059901b003f043761a2f313c6ac03ee946bb6 Mon Sep 17 00:00:00 2001 From: gustavo Date: Fri, 8 Oct 1999 17:45:49 +0000 Subject: [PATCH] adding more functions and tests for eoNonUniform --- eo/src/eo | 4 +- eo/src/eoNonUniform.h | 79 +++++++++++++++++++++++++++++++++----- eo/test/.cvsignore | 1 + eo/test/Makefile.am | 8 +++- eo/test/Makefile.in | 32 +++++++++------ eo/test/t-eoNonUniform.cpp | 31 +++++++++++++++ 6 files changed, 132 insertions(+), 23 deletions(-) create mode 100644 eo/test/t-eoNonUniform.cpp diff --git a/eo/src/eo b/eo/src/eo index 43e84fc79..1f8423c9f 100644 --- a/eo/src/eo +++ b/eo/src/eo @@ -81,13 +81,15 @@ // Algorithms #include +// aliens +#include + //----------------------------------------------------------------------------- // to be continued ... //----------------------------------------------------------------------------- /* #include #include -#include */ //----------------------------------------------------------------------------- diff --git a/eo/src/eoNonUniform.h b/eo/src/eoNonUniform.h index 2ce8bbb99..438f72660 100644 --- a/eo/src/eoNonUniform.h +++ b/eo/src/eoNonUniform.h @@ -2,26 +2,85 @@ // eoNonUniform.h //----------------------------------------------------------------------------- -#ifndef eoNonUniform_h -#define eoNonUniform_h +#ifndef EONONUNIFORM_H +#define EONONUNIFORM_H //----------------------------------------------------------------------------- -// eoNonUniform: base class for non uniform operators + +#include // pow + +//----------------------------------------------------------------------------- +// eoNonUniform //----------------------------------------------------------------------------- -template class eoNonUniform +class eoNonUniform { public: - eoNonUniform(const Time& _time = Time(), const Time& _max_time = Time()): - time_value(_time), max_time_value(_max_time) {} + eoNonUniform(const unsigned _num_step): + step_value(0), num_step_value(_num_step) {} - const Time& time() const { return time_value; } - const Time& max_time() const { return max_time_value; } + void reset() { step_value = 0; } + + const unsigned& step() const { return step_value; } + const unsigned& num_step() const { return num_step_value; } + + operator int() const { return step_value < num_step_value; } + + void operator++() { ++step_value; } + void operator++(int) { ++step_value; } private: - Time &time_value, &max_time_value; + unsigned step_value, num_step_value; +}; + +//----------------------------------------------------------------------------- +// eoLinear +//----------------------------------------------------------------------------- + +class eoLinear +{ +public: + eoLinear(const double _first, + const double _last, + const eoNonUniform& _non_uniform): + first(_first), + diff((_last - _first) / (_non_uniform.num_step() - 1)), + non_uniform(_non_uniform) {} + + double operator()() const + { + return first + diff * non_uniform.step(); + } + +private: + double first, diff; + const eoNonUniform& non_uniform; +}; + +//----------------------------------------------------------------------------- +// eoNegExp2 +//----------------------------------------------------------------------------- + +class eoNegExp2 +{ + public: + eoNegExp2(const double _r, + const double _b, + const eoNonUniform& _non_uniform): + r(_r), b(_b), + non_uniform(_non_uniform) {} + + double operator()() const + { + return 1.0 - pow(r, pow(1.0 - (double)non_uniform.step() / + non_uniform.num_step(), b)); + } + + private: + double r, b; + const eoNonUniform& non_uniform; }; //----------------------------------------------------------------------------- -#endif eoNonUniform_h +#endif NON_UNIFORM_HH diff --git a/eo/test/.cvsignore b/eo/test/.cvsignore index 2e9f301a8..53ebcf49f 100644 --- a/eo/test/.cvsignore +++ b/eo/test/.cvsignore @@ -10,3 +10,4 @@ t-eoinsertion t-eolottery t-eoproblem t-eogeneration +t-eoNonUniform diff --git a/eo/test/Makefile.am b/eo/test/Makefile.am index 5ac001fe4..43c6df123 100644 --- a/eo/test/Makefile.am +++ b/eo/test/Makefile.am @@ -13,7 +13,13 @@ 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 +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_eoNonUniform_SOURCES = t-eoNonUniform.cpp +t_eoNonUniform_DEPENDENCIES = $(DEPS) +t_eoNonUniform_LDFLAGS = -lm +t_eoNonUniform_LDADD = $(LDADDS) ############################################################################### diff --git a/eo/test/Makefile.in b/eo/test/Makefile.in index 35a27402e..46075b193 100644 --- a/eo/test/Makefile.in +++ b/eo/test/Makefile.in @@ -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 = : @@ -87,7 +86,13 @@ 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 +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_eoNonUniform_SOURCES = t-eoNonUniform.cpp +t_eoNonUniform_DEPENDENCIES = $(DEPS) +t_eoNonUniform_LDFLAGS = -lm +t_eoNonUniform_LDADD = $(LDADDS) ############################################################################### @@ -185,6 +190,7 @@ t_eolottery_OBJECTS = t-eolottery.o t_eo2dVector_OBJECTS = t-eo2dVector.o t_eogeneration_OBJECTS = t-eogeneration.o t_eoEasyEA_OBJECTS = t-eoEasyEA.o +t_eoNonUniform_OBJECTS = t-eoNonUniform.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) @@ -198,11 +204,11 @@ 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-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 -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) -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) +.deps/t-eoNonUniform.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 +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) +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) all: all-redirect .SUFFIXES: @@ -299,6 +305,10 @@ t-eogeneration: $(t_eogeneration_OBJECTS) $(t_eogeneration_DEPENDENCIES) t-eoEasyEA: $(t_eoEasyEA_OBJECTS) $(t_eoEasyEA_DEPENDENCIES) @rm -f t-eoEasyEA $(CXXLINK) $(t_eoEasyEA_LDFLAGS) $(t_eoEasyEA_OBJECTS) $(t_eoEasyEA_LDADD) $(LIBS) + +t-eoNonUniform: $(t_eoNonUniform_OBJECTS) $(t_eoNonUniform_DEPENDENCIES) + @rm -f t-eoNonUniform + $(CXXLINK) $(t_eoNonUniform_LDFLAGS) $(t_eoNonUniform_OBJECTS) $(t_eoNonUniform_LDADD) $(LIBS) .cc.o: $(CXXCOMPILE) -c $< .cc.lo: @@ -350,7 +360,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 \ @@ -449,7 +459,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: diff --git a/eo/test/t-eoNonUniform.cpp b/eo/test/t-eoNonUniform.cpp new file mode 100644 index 000000000..352b229b2 --- /dev/null +++ b/eo/test/t-eoNonUniform.cpp @@ -0,0 +1,31 @@ +//----------------------------------------------------------------------------- +// t-eoNonUniform.cc +//----------------------------------------------------------------------------- + +#include +#include + +//----------------------------------------------------------------------------- + +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; + } +} + +//-----------------------------------------------------------------------------