EvolvingObjects
continuators.cpp
00001 /*
00002     PyEO
00003 
00004     Copyright (C) 2003 Maarten Keijzer
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 */
00020 
00021 #include <eoGenContinue.h>
00022 #include <eoCombinedContinue.h>
00023 #include <eoEvalContinue.h>
00024 #include <eoFitContinue.h>
00025 #include <eoSteadyFitContinue.h>
00026 #include <utils/eoCheckPoint.h>
00027 #include <utils/eoStat.h>
00028 
00029 #include "PyEO.h"
00030 #include "def_abstract_functor.h"
00031 
00032 using namespace boost::python;
00033 
00034 #define DEF(x) class_<x<PyEO>, bases<eoContinue<PyEO > > >(#x).def("__call__", &eoContinue<PyEO>::operator())
00035 #define DEF2(x, i1) class_<x<PyEO>, bases<eoContinue<PyEO > > >(#x, init<i1>() ).def("__call__", &eoContinue<PyEO>::operator())
00036 #define DEF3(x, i1, i2) class_<x<PyEO>, bases<eoContinue<PyEO > > >(#x, init<i1, i2 >() ).def("__call__", &eoContinue<PyEO>::operator())
00037 
00038 void add_checkpoint();
00039 
00040 void continuators()
00041 {
00042     /* Counters, wrappers etc */
00043 
00044     class_<eoEvalFuncCounter<PyEO>, bases<eoEvalFunc<PyEO> > >
00045         ("eoEvalFuncCounter",
00046          init< eoEvalFunc<PyEO>&, std::string>()
00047          )
00048         .def("__call__", &eoEvalFuncCounter<PyEO>::operator())
00049         ;
00050     /* Continuators */
00051     def_abstract_functor<eoContinue<PyEO> >("eoContinue");
00052 
00053     class_<eoGenContinue<PyEO>, bases<eoContinue<PyEO> >, boost::noncopyable >
00054         ("eoGenContinue", init<unsigned long>() )
00055         .def("__call__", &eoGenContinue<PyEO>::operator())
00056         ;
00057 
00058     class_<eoCombinedContinue<PyEO>, bases<eoContinue<PyEO> > >
00059         ("eoCombinedContinue", init<eoContinue<PyEO>&>()[WC1])
00060         .def( init<eoContinue<PyEO>&, eoContinue<PyEO>& >()[WC2] )
00061         .def("add", &eoCombinedContinue<PyEO>::add, WC1)
00062         .def("__call__", &eoCombinedContinue<PyEO>::operator())
00063         ;
00064 
00065     class_<eoEvalContinue<PyEO>, bases<eoContinue<PyEO> > >
00066         ("eoEvalContinue",
00067          init<eoEvalFuncCounter<PyEO>&, unsigned long>()[WC1]
00068          )
00069         .def("__call__", &eoEvalContinue<PyEO>::operator())
00070         ;
00071 
00072     DEF2(eoFitContinue, object); // object is the fitness type
00073 
00074     DEF3(eoSteadyFitContinue, unsigned long, unsigned long);
00075 
00076     add_checkpoint();
00077 }
00078 
00079 void addContinue(eoCheckPoint<PyEO>& c, eoContinue<PyEO>& cc) { c.add(cc); }
00080 void addMonitor(eoCheckPoint<PyEO>& c, eoMonitor& m) { c.add(m);}
00081 void addStat(eoCheckPoint<PyEO>& c, eoStatBase<PyEO>& s) { c.add(s);}
00082 void addSortedStat(eoCheckPoint<PyEO>& c, eoSortedStatBase<PyEO>& s) { c.add(s);}
00083 
00084 void add_checkpoint()
00085 {
00086     class_<eoCheckPoint<PyEO>, bases< eoContinue<PyEO> > >
00087         ("eoCheckPoint",
00088          init<eoContinue<PyEO>&> ()[with_custodian_and_ward<1,2>()]
00089          )
00090         .def("add", addContinue, with_custodian_and_ward<1,2>() )
00091         .def("add", addMonitor, with_custodian_and_ward<1,2>() )
00092         .def("add", addStat, with_custodian_and_ward<1,2>())
00093         .def("add", addSortedStat, with_custodian_and_ward<1,2>())
00094         .def("__call__", &eoCheckPoint<PyEO>::operator())
00095         ;
00096 }
 All Classes Namespaces Files Functions Variables Typedefs Friends