adding more functions and tests for eoNonUniform
This commit is contained in:
parent
557a06ff22
commit
387059901b
6 changed files with 132 additions and 23 deletions
|
|
@ -81,13 +81,15 @@
|
|||
// Algorithms
|
||||
#include <eoEasyEA.h>
|
||||
|
||||
// aliens
|
||||
#include <eoNonUniform.h>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// to be continued ...
|
||||
//-----------------------------------------------------------------------------
|
||||
/*
|
||||
#include <eoFitness.h>
|
||||
#include <eoProblem.h>
|
||||
#include <eoGeneration.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 <math.h> // pow
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoNonUniform
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template<class Time> 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
|
||||
|
|
|
|||
|
|
@ -10,3 +10,4 @@ t-eoinsertion
|
|||
t-eolottery
|
||||
t-eoproblem
|
||||
t-eogeneration
|
||||
t-eoNonUniform
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
###############################################################################
|
||||
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
||||
|
||||
|
|
|
|||
31
eo/test/t-eoNonUniform.cpp
Normal file
31
eo/test/t-eoNonUniform.cpp
Normal file
|
|
@ -0,0 +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;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
Loading…
Add table
Add a link
Reference in a new issue