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> > >("eoEvalFuncCounter",
00045             init< eoEvalFunc<PyEO>&, std::string>())
00046         .def("__call__", &eoEvalFuncCounter<PyEO>::operator())
00047         ;
00048     /* Continuators */
00049     def_abstract_functor<eoContinue<PyEO> >("eoContinue"); 
00050         
00051     class_<eoGenContinue<PyEO>, bases<eoContinue<PyEO> >, boost::noncopyable >("eoGenContinue", init<unsigned long>() )
00052         .def("__call__", &eoGenContinue<PyEO>::operator())
00053         ;
00054   
00055     class_<eoCombinedContinue<PyEO>, bases<eoContinue<PyEO> > >("eoCombinedContinue", init<eoContinue<PyEO>&>()[WC1])
00056         .def( init<eoContinue<PyEO>&, eoContinue<PyEO>& >()[WC2] )
00057         .def("add", &eoCombinedContinue<PyEO>::add, WC1)
00058         .def("__call__", &eoCombinedContinue<PyEO>::operator())
00059         ;
00060    
00061     class_<eoEvalContinue<PyEO>, bases<eoContinue<PyEO> > >("eoEvalContinue", 
00062             init<eoEvalFuncCounter<PyEO>&, unsigned long>()[WC1])
00063         .def("__call__", &eoEvalContinue<PyEO>::operator())
00064         ;
00065 
00066     DEF2(eoFitContinue, object); // object is the fitness type
00067 
00068     DEF3(eoSteadyFitContinue, unsigned long, unsigned long);
00069 
00070     add_checkpoint();
00071 }
00072 
00073 void addContinue(eoCheckPoint<PyEO>& c, eoContinue<PyEO>& cc) { c.add(cc); }
00074 void addMonitor(eoCheckPoint<PyEO>& c, eoMonitor& m) { c.add(m);}
00075 void addStat(eoCheckPoint<PyEO>& c, eoStatBase<PyEO>& s) { c.add(s);}
00076 void addSortedStat(eoCheckPoint<PyEO>& c, eoSortedStatBase<PyEO>& s) { c.add(s);}
00077 
00078 void add_checkpoint()
00079 {
00080     class_<eoCheckPoint<PyEO>, bases< eoContinue<PyEO> > >("eoCheckPoint",
00081             
00082             init<eoContinue<PyEO>&> ()[with_custodian_and_ward<1,2>()]
00083             ) 
00084         .def("add", addContinue, with_custodian_and_ward<1,2>() )
00085         .def("add", addMonitor, with_custodian_and_ward<1,2>() )
00086         .def("add", addStat, with_custodian_and_ward<1,2>())
00087         .def("add", addSortedStat, with_custodian_and_ward<1,2>()) 
00088         .def("__call__", &eoCheckPoint<PyEO>::operator())
00089         ;
00090 }

Generated on Thu Oct 19 05:06:34 2006 for EO by  doxygen 1.3.9.1