From 18adaef0568f3ff99f1c452eef389843b85c3fa4 Mon Sep 17 00:00:00 2001 From: maartenkeijzer Date: Mon, 12 Nov 2007 16:23:57 +0000 Subject: [PATCH] Updated makefiles, updated the moo stuff and cleaned up some stuff that refused to compile --- eo/contrib/mathsym/README | 2 +- eo/doc/eo.cfg | 12 ++++++------ eo/src/EO.h | 5 +---- eo/src/Makefile.am | 3 ++- eo/src/eo | 1 + eo/src/eoEasyEA.h | 2 +- eo/src/eoPop.h | 3 +-- eo/src/eoSGA.h | 2 +- eo/src/es/eoCMABreed.h | 5 +++-- eo/src/moo/Makefile.am | 11 +++++++++-- eo/src/moo/eoEpsMOEA.h | 2 +- eo/src/moo/eoEpsilonArchive.h | 20 -------------------- eo/src/moo/eoNSGA_II_Eval.cpp | 3 +-- eo/src/moo/eoNSGA_II_Eval.h | 2 +- eo/src/pyeo/Makefile | 6 ++++-- eo/src/pyeo/PyEO.cpp | 2 +- eo/test/Makefile.am | 6 ++++++ eo/test/t-eo.cpp | 2 +- eo/test/t-eoEpsMOEA.cpp | 25 +++++++++++++++++++++++++ 19 files changed, 66 insertions(+), 48 deletions(-) diff --git a/eo/contrib/mathsym/README b/eo/contrib/mathsym/README index 0ac57dbc..4660c8fd 100644 --- a/eo/contrib/mathsym/README +++ b/eo/contrib/mathsym/README @@ -94,7 +94,7 @@ To add two values, do Sym sym = var + const; -This will create a tree with tree nodes. All other operations work identically. +This will create a tree with three nodes. Other operators are overloaded similarily. === Evaluation (eval/) === diff --git a/eo/doc/eo.cfg b/eo/doc/eo.cfg index 11a647ec..12c6cf93 100644 --- a/eo/doc/eo.cfg +++ b/eo/doc/eo.cfg @@ -17,20 +17,20 @@ # The PROJECT_NAME tag is a single word (or a sequence of words surrounded # by quotes) that should identify the project. -PROJECT_NAME = EO +PROJECT_NAME = Evolving Objects # The PROJECT_NUMBER tag can be used to enter a project or revision number. # This could be handy for archiving the generated documentation or # if some version control system is used. -PROJECT_NUMBER = 1.0.2-cvs +PROJECT_NUMBER = 1.02-cvs1 # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) # base path where the generated documentation will be put. # If a relative path is entered, it will be relative to the location # where doxygen was started. If left blank the current directory will be used. -OUTPUT_DIRECTORY = +OUTPUT_DIRECTORY = /home/mkeijzer/projects/eo/doc # The OUTPUT_LANGUAGE tag is used to specify the language in which all # documentation generated by doxygen is written. Doxygen will use this @@ -104,7 +104,7 @@ FULL_PATH_NAMES = NO # If left blank the directory from which doxygen is run is used as the # path to strip. -STRIP_FROM_PATH = +STRIP_FROM_PATH = /home/mkeijzer/projects/eo # If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter # (but less readable) file names. This can be useful is your file systems @@ -391,7 +391,7 @@ WARN_LOGFILE = # directories like "/usr/src/myproject". Separate the files or directories # with spaces. -INPUT = .. +INPUT = /home/mkeijzer/projects/eo # If the value of the INPUT tag contains directories, you can use the # FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp @@ -414,7 +414,7 @@ RECURSIVE = YES # excluded from the INPUT source files. This way you can easily exclude a # subdirectory from a directory tree whose root is specified with the INPUT tag. -EXCLUDE = ../src/obsolete +EXCLUDE = /home/mkeijzer/projects/eo/src/obsolete # The EXCLUDE_SYMLINKS tag can be used select whether or not files or directories # that are symbolic links (a Unix filesystem feature) are excluded from the input. diff --git a/eo/src/EO.h b/eo/src/EO.h index 1fa1e94c..07dfb77d 100644 --- a/eo/src/EO.h +++ b/eo/src/EO.h @@ -47,11 +47,8 @@ public: typedef F Fitness; /** Default constructor. - Fitness must have a ctor which takes 0 as a value; we can not use void - ctors here since default types like float have no void initializer. - VC++ allows it, but gcc does not */ - EO(): repFitness(Fitness()), invalidFitness(true) {} + EO(): repFitness(Fitness()), invalidFitness(true) { } /// Virtual dtor virtual ~EO() {}; diff --git a/eo/src/Makefile.am b/eo/src/Makefile.am index 67a75ff1..b48f8be7 100644 --- a/eo/src/Makefile.am +++ b/eo/src/Makefile.am @@ -143,6 +143,7 @@ pkginclude_HEADERS = eo \ eoWeightUpdater.h \ es.h \ ga.h \ - PO.h + PO.h \ + eoTimeContinue.h AM_CXXFLAGS = -I$(top_srcdir)/src diff --git a/eo/src/eo b/eo/src/eo index 09202b06..be7596fd 100644 --- a/eo/src/eo +++ b/eo/src/eo @@ -127,6 +127,7 @@ #include #include + // Algorithms #include #include diff --git a/eo/src/eoEasyEA.h b/eo/src/eoEasyEA.h index 3aa03518..89ef790f 100644 --- a/eo/src/eoEasyEA.h +++ b/eo/src/eoEasyEA.h @@ -185,7 +185,7 @@ public: breed(_pop, offspring); popEval(_pop, offspring); // eval of parents + offspring if necessary - + replace(_pop, offspring); // after replace, the new pop. is in _pop if (pSize > _pop.size()) diff --git a/eo/src/eoPop.h b/eo/src/eoPop.h index e9b2db95..a6ea147c 100644 --- a/eo/src/eoPop.h +++ b/eo/src/eoPop.h @@ -51,7 +51,7 @@ */ template -class eoPop: public std::vector, public eoObject, public eoPersistent +class eoPop: public std::vector, public eoObject, public eoPersistent { public: @@ -295,7 +295,6 @@ class eoPop: public std::vector, public eoObject, public eoPersistent this->operator[](i).invalidate(); } - protected: }; diff --git a/eo/src/eoSGA.h b/eo/src/eoSGA.h index d160a365..469d6dd4 100644 --- a/eo/src/eoSGA.h +++ b/eo/src/eoSGA.h @@ -89,7 +89,7 @@ public : } } - for (i=0; i < _pop.size(); i++) + for (i=0; i < offspring.size(); i++) { if (rng.flip(mutationRate) ) { diff --git a/eo/src/es/eoCMABreed.h b/eo/src/es/eoCMABreed.h index c210d299..1c998c42 100644 --- a/eo/src/es/eoCMABreed.h +++ b/eo/src/es/eoCMABreed.h @@ -47,7 +47,9 @@ class eoCMABreed : public eoBreed< eoVector > { // two temporary arrays of pointers to store the sorted population std::vector sorted(parents.size()); - std::vector* > mu(parents.size()); + + // mu stores population as vector (instead of eoPop) + std::vector* > mu(parents.size()); parents.sort(sorted); for (unsigned i = 0; i < sorted.size(); ++i) { @@ -55,7 +57,6 @@ class eoCMABreed : public eoBreed< eoVector > { } // learn - state.reestimate(mu, sorted[0]->fitness(), sorted.back()->fitness()); if (!state.updateEigenSystem(10)) { diff --git a/eo/src/moo/Makefile.am b/eo/src/moo/Makefile.am index 8a94c342..e829bd1f 100644 --- a/eo/src/moo/Makefile.am +++ b/eo/src/moo/Makefile.am @@ -5,7 +5,14 @@ libeomoo_a_SOURCES = eoFrontSorter.cpp \ eoNSGA_IIa_Eval.cpp \ eoNSGA_II_Eval.cpp -pkginclude_HEADERS = eoFrontSorter.h \ - eoMOFitness.h +pkginclude_HEADERS =\ +eoEpsilonArchive.h\ +eoEpsMOEA.h\ +eoFrontSorter.h\ +eoMOEval.h\ +eoMOFitness.h\ +eoNSGA_I_Eval.h\ +eoNSGA_IIa_Eval.h\ +eoNSGA_II_Eval.h AM_CXXFLAGS = -I$(top_srcdir)/src diff --git a/eo/src/moo/eoEpsMOEA.h b/eo/src/moo/eoEpsMOEA.h index 9ad8157a..9ed7a855 100644 --- a/eo/src/moo/eoEpsMOEA.h +++ b/eo/src/moo/eoEpsMOEA.h @@ -16,7 +16,7 @@ class eoEpsMOEA : public eoAlgo { eoEvalFunc& _eval, eoGenOp& _op, const std::vector& eps, - unsigned max_archive_size + unsigned max_archive_size = std::numeric_limits::max() ) : continuator(_continuator), eval (_eval), loopEval(_eval), diff --git a/eo/src/moo/eoEpsilonArchive.h b/eo/src/moo/eoEpsilonArchive.h index 00f001a1..f54da333 100644 --- a/eo/src/moo/eoEpsilonArchive.h +++ b/eo/src/moo/eoEpsilonArchive.h @@ -114,26 +114,6 @@ exitLoop: } } - /* - static unsigned counter = 0; - if (++counter % 500 == 0) { - std::vector mins(archive[0].discretized.size(), std::numeric_limits::max()); - std::vector maxs(archive[0].discretized.size(), std::numeric_limits::min()); - for (unsigned i = 0; i < archive.size(); ++i) { - for (unsigned dim = 0; dim < archive[i].discretized.size(); ++dim) { - mins[dim] = std::min( mins[dim], archive[i].discretized[dim] ); - maxs[dim] = std::max( maxs[dim], archive[i].discretized[dim] ); - } - } - - std::cout << "Range "; - for (unsigned dim = 0; dim < mins.size(); ++dim) { - std::cout << (maxs[dim] - mins[dim]) << ' '; - } - std::cout << archive.size() << std::endl; - - }*/ - if (archive.size() > max_size) { unsigned idx = rng.random(archive.size()); if (idx != archive.size()-1) std::swap(archive[idx], archive.back()); diff --git a/eo/src/moo/eoNSGA_II_Eval.cpp b/eo/src/moo/eoNSGA_II_Eval.cpp index 619a102b..617623fb 100644 --- a/eo/src/moo/eoNSGA_II_Eval.cpp +++ b/eo/src/moo/eoNSGA_II_Eval.cpp @@ -1,6 +1,5 @@ - #include -#include +#include namespace nsga2 { diff --git a/eo/src/moo/eoNSGA_II_Eval.h b/eo/src/moo/eoNSGA_II_Eval.h index 55b3fd60..2cfbe5af 100644 --- a/eo/src/moo/eoNSGA_II_Eval.h +++ b/eo/src/moo/eoNSGA_II_Eval.h @@ -25,7 +25,7 @@ class eoNSGA_II_Eval : public eoMOEval eoNSGA_II_Eval(eoPopEvalFunc& eval) : eoMOEval(eval) {} virtual void operator()(eoPop& parents, eoPop& offspring) { - eval(parents, offspring); + this->eval(parents, offspring); std::vector pop; pop.reserve(parents.size() + offspring.size()); diff --git a/eo/src/pyeo/Makefile b/eo/src/pyeo/Makefile index ef74f8e7..ca2d762b 100644 --- a/eo/src/pyeo/Makefile +++ b/eo/src/pyeo/Makefile @@ -16,7 +16,9 @@ OBJECTS=eoFunctorStore.o PyEO.o abstract1.o algos.o \ random_numbers.o geneticOps.o selectOne.o continuators.o\ reduce.o replacement.o selectors.o breeders.o\ mergers.o valueParam.o perf2worth.o monitors.o\ - statistics.o + statistics.o + +LIB=../libeo.a ../utils/libeoutils.a all: PyEO/PyEO.so @@ -24,7 +26,7 @@ clean: rm PyEO/*.so *.o test/*.pyc PyEO/PyEO.so: $(OBJECTS) - $(LINK) -o PyEO/PyEO.so $(OBJECTS) -lboost_python -lpython2.4 -shared #-lstlport + $(LINK) -o PyEO/PyEO.so $(OBJECTS) -lboost_python -lpython2.4 ${LIB} -shared #-lstlport eoFunctorStore.o: ../eoFunctorStore.h ../eoFunctorStore.cpp $(COMPILE) -o eoFunctorStore.o ../eoFunctorStore.cpp $(INC) diff --git a/eo/src/pyeo/PyEO.cpp b/eo/src/pyeo/PyEO.cpp index 95da4627..40d36310 100644 --- a/eo/src/pyeo/PyEO.cpp +++ b/eo/src/pyeo/PyEO.cpp @@ -180,7 +180,7 @@ BOOST_PYTHON_MODULE(PyEO) boost::python::class_ >("eoPop", init<>() ) .def( init< unsigned, eoInit& >()[with_custodian_and_ward<1,3>()] ) - .def("append", &eoPop::append) + .def("append", &eoPop::append, "docstring?") .def("__str__", to_string >) .def("__len__", pop_size) .def("sort", pop_sort ) diff --git a/eo/test/Makefile.am b/eo/test/Makefile.am index 4c202679..1099b2f9 100644 --- a/eo/test/Makefile.am +++ b/eo/test/Makefile.am @@ -108,4 +108,10 @@ t_eoEasyPSO_SOURCES = t-eoEasyPSO.cpp t_eoNSGA_SOURCES = t-eoNSGA.cpp t_eoFrontSorter_SOURCES = t-eoFrontSorter.cpp t_eoEpsMOEA_SOURCES = t-eoEpsMOEA.cpp +t_eoInt_SOURCES = t-eoInt.cpp +t_eoInitPermutation_SOURCES = t-eoInitPermutation.cpp +t_eoSwapMutation_SOURCES = t-eoSwapMutation.cpp +t_eoShiftMutation_SOURCES = t-eoShiftMutation.cpp +t_eoTwoOptMutation_SOURCES = t-eoTwoOptMutation.cpp +t_eoRingTopology_SOURCES = t-eoRingTopology.cpp diff --git a/eo/test/t-eo.cpp b/eo/test/t-eo.cpp index aea451c3..2e4cf4e7 100644 --- a/eo/test/t-eo.cpp +++ b/eo/test/t-eo.cpp @@ -9,7 +9,6 @@ typedef EO Chrom; //----------------------------------------------------------------------------- - int main() { Chrom chrom1, chrom2; @@ -17,6 +16,7 @@ int main() std::cout << "chrom1 = " << chrom1 << std::endl << "chrom2 = " << chrom2 << std::endl; + return 0; } diff --git a/eo/test/t-eoEpsMOEA.cpp b/eo/test/t-eoEpsMOEA.cpp index 7f6f40ba..d105c106 100644 --- a/eo/test/t-eoEpsMOEA.cpp +++ b/eo/test/t-eoEpsMOEA.cpp @@ -2,6 +2,7 @@ #include #include +#include using namespace std; @@ -133,6 +134,17 @@ class Init : public eoInit } }; +template +unsigned get_size(const eoPop& pop) { + return pop.size(); +} + +template +unsigned counter(const eoPop& pop) { + static unsigned c = 0; + return c++; +} + // Test pareto dominance and perf2worth, and while you're at it, test the eoGnuPlot monitor as well void the_main(int argc, char* argv[]) { @@ -174,7 +186,20 @@ void the_main(int argc, char* argv[]) snapshot.add(fitness0); snapshot.add(fitness1); + + eoGnuplot1DMonitor monitor("sizemon"); + + cp.add(monitor); + + eoFuncPtrStat size(get_size); + eoFuncPtrStat counterStat(counter); + + monitor.add(counterStat); + monitor.add(size); + cp.add(size); + cp.add(counterStat); + // the algo eoEpsMOEA ea(cp, eval, opsel, MinimizingFitnessTraits::eps );