Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | Related Pages | Search for

# perf2worth.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 #include <eoNDSorting.h>
    00021
    00022 #include "PyEO.h"
    00023
    00024 using namespace boost::python;
    00025
    00026 struct Perf2WorthWrapper : public eoPerf2Worth<PyEO,double>
    00027 {
    00028     PyObject* self;
    00029     Perf2WorthWrapper(PyObject* p) : self(p) {}
    00030
    00031     void operator()( const eoPop<PyEO>& pop)
    00032     {
    00033         call_method<void>(self, "__call__", boost::ref(pop));
    00034     }
    00035
    00036 };
    00037
    00038 numeric::array get_worths(eoPerf2Worth<PyEO, double>& p)
    00039 {
    00040     std::vector<double>& worths = p.value();
    00041     list result;
    00042
    00043     for (unsigned i = 0; i < worths.size(); ++i)
    00044         result.append(worths[i]);
    00045
    00046     return numeric::array(result);
    00047 }
    00048
    00049 struct CachedPerf2WorthWrapper : public eoPerf2WorthCached<PyEO, double>
    00050 {
    00051     PyObject* self;
    00052     CachedPerf2WorthWrapper(PyObject* p) : self(p) {}
    00053
    00054     void calculate_worths(const eoPop<PyEO>& pop)
    00055     {
    00056         call_method<void>(self, "calculate_worths", boost::ref(pop));
    00057     }
    00058 };
    00059
    00060 void perf2worth()
    00061 {
    00062     //numeric::array::set_module_and_type("Numeric", "ArrayType");
    00063
    00064     class_<
    00065         eoPerf2Worth<PyEO, double>,
    00066         Perf2WorthWrapper,
    00067         bases< eoValueParam<std::vector<double> > >,
    00068         boost::noncopyable>("eoPerf2Worth", init<>())
    00069
    00070             .def("__call__", &Perf2WorthWrapper::operator())
    00071             .def("sort_pop", &eoPerf2Worth<PyEO, double>::sort_pop)
    00072            //.def("value", get_worths)
    00073         ;
    00074
    00075     class_<eoPerf2WorthCached<PyEO, double>, CachedPerf2WorthWrapper, bases<eoPerf2Worth<PyEO, double> >, boost::noncopyable>
    00076         ("eoPerf2WorthCached", init<>())
    00077         .def("__call__", &eoPerf2WorthCached<PyEO, double>::operator())
    00078         .def("calculate_worths", &CachedPerf2WorthWrapper::calculate_worths)
    00079         ;
    00080
    00081     //class_<eoNoPerf2Worth<PyEO>, bases<eoPerf2Worth<PyEO, double> > >("eoNoPerf2Worth")
    00082 //      .def("__call__", &eoNoPerf2Worth<PyEO>::operator());
    00083
    00084     class_<eoNDSorting_II<PyEO>, bases<eoPerf2WorthCached<PyEO, double> > >("eoNDSorting_II")
    00085         .def("calculate_worths", &eoNDSorting_II<PyEO>::calculate_worths);
    00086 }
    00087
    00088