/* PyEO Copyright (C) 2003 Maarten Keijzer This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include "PyEO.h" #include "pickle.h" class eoSelectOneWrapper : public eoSelectOne { public: PyObject* self; eoSelectOneWrapper(PyObject* p) : self(p) {} const PyEO& operator()(const eoPop& pop) { return boost::python::call_method< const PyEO& >(self, "__call__", boost::ref(pop)); } }; template void add_select(std::string name) { class_ > >(name.c_str(), init<>() ) .def("__call__", &Select::operator(), return_internal_reference<>() ) ; } template void add_select(std::string name, Init init) { class_ > >(name.c_str(), init) .def("__call__", &Select::operator(), return_internal_reference<>() ) ; } template void add_select(std::string name, Init1 init1, Init2 init2) { class_ > >(name.c_str(), init1) .def( init2 ) .def("__call__", &Select::operator(), return_internal_reference<>() ) .def("setup", &Select::setup); } void selectOne() { /* Concrete classes */ pickle(class_("eoHowMany", init<>()) .def( init() ) .def( init() ) .def( init() ) .def("__call__", &eoHowMany::operator()) .def("__neg__", &eoHowMany::operator-) ); class_, eoSelectOneWrapper, boost::noncopyable>("eoSelectOne", init<>()) .def("__call__", &eoSelectOneWrapper::operator(), return_internal_reference<>() ) .def("setup", &eoSelectOne::setup); /* SelectOne derived classes */ add_select >("eoDetTournamentSelect", init<>(), init() ); add_select >("eoStochTournamentSelect", init<>(), init() ); add_select >("eoTruncatedSelectOne", init&, double>(), init&, eoHowMany >() ); // eoProportionalSelect is not feasible to implement at this point as fitness is not recognizable as a float // use eoDetTournament instead: with a t-size of 2 it is equivalent to eoProportional with linear scaling //add_select >("eoProportionalSelect", init&>() ); add_select >("eoRandomSelect"); add_select >("eoBestSelect"); add_select >("eoNoSelect"); add_select >("eoSequentialSelect", init<>(), init()); add_select >("eoEliteSequentialSelect"); /* * eoSelectFromWorth.h:class eoSelectFromWorth : public eoSelectOne */ }