00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <eoSelectOne.h>
00022 #include <eoDetTournamentSelect.h>
00023 #include <eoRandomSelect.h>
00024 #include <eoStochTournamentSelect.h>
00025 #include <eoTruncatedSelectOne.h>
00026 #include <eoSequentialSelect.h>
00027
00028 #include "PyEO.h"
00029 #include "pickle.h"
00030 #include "def_abstract_functor.h"
00031
00032 using namespace boost::python;
00033
00034 class eoSelectOneWrapper : public eoSelectOne<PyEO>
00035 {
00036 public:
00037 PyObject* self;
00038 eoSelectOneWrapper(PyObject* p) : self(p) {}
00039 const PyEO& operator()(const eoPop<PyEO>& pop)
00040 {
00041 return boost::python::call_method< const PyEO& >(self, "__call__", boost::ref(pop));
00042 }
00043 };
00044
00045 template <class Select>
00046 void add_select(std::string name)
00047 {
00048 class_<Select, bases<eoSelectOne<PyEO> > >(name.c_str(), init<>() )
00049 .def("__call__", &Select::operator(), return_internal_reference<>() )
00050 ;
00051 }
00052
00053 template <class Select, class Init>
00054 void add_select(std::string name, Init init)
00055 {
00056 class_<Select, bases<eoSelectOne<PyEO> > >(name.c_str(), init)
00057 .def("__call__", &Select::operator(), return_internal_reference<>() )
00058 ;
00059 }
00060
00061 template <class Select, class Init1, class Init2>
00062 void add_select(std::string name, Init1 init1, Init2 init2)
00063 {
00064 class_<Select, bases<eoSelectOne<PyEO> > >(name.c_str(), init1)
00065 .def( init2 )
00066 .def("__call__", &Select::operator(), return_internal_reference<>() )
00067 .def("setup", &Select::setup);
00068 }
00069
00070 void selectOne()
00071 {
00072
00073
00074 pickle(class_<eoHowMany>("eoHowMany", init<>())
00075 .def( init<double>() )
00076 .def( init<double, bool>() )
00077 .def( init<int>() )
00078 .def("__call__", &eoHowMany::operator())
00079 .def("__neg__", &eoHowMany::operator-)
00080 );
00081
00082 class_<eoSelectOne<PyEO>, eoSelectOneWrapper, boost::noncopyable>("eoSelectOne", init<>())
00083 .def("__call__", &eoSelectOneWrapper::operator(), return_internal_reference<>() )
00084 .def("setup", &eoSelectOne<PyEO>::setup);
00085
00086
00087
00088 add_select<eoDetTournamentSelect<PyEO> >("eoDetTournamentSelect", init<>(), init<unsigned>() );
00089 add_select<eoStochTournamentSelect<PyEO> >("eoStochTournamentSelect", init<>(), init<double>() );
00090 add_select<eoTruncatedSelectOne<PyEO> >("eoTruncatedSelectOne",
00091 init<eoSelectOne<PyEO>&, double>()[WC1], init<eoSelectOne<PyEO>&, eoHowMany >()[WC1] );
00092
00093
00094
00095
00096
00097 add_select<eoRandomSelect<PyEO> >("eoRandomSelect");
00098 add_select<eoBestSelect<PyEO> >("eoBestSelect");
00099 add_select<eoNoSelect<PyEO> >("eoNoSelect");
00100
00101 add_select<eoSequentialSelect<PyEO> >("eoSequentialSelect", init<>(), init<bool>());
00102 add_select<eoEliteSequentialSelect<PyEO> >("eoEliteSequentialSelect");
00103
00104
00105
00106
00107 }