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

# eoSymEval.h

    00001 /*
    00002  *             Copyright (C) 2005 Maarten Keijzer
    00003  *
    00004  *          This program is free software; you can redistribute it and/or modify
    00005  *          it under the terms of version 2 of the GNU General Public License as
    00006  *          published by the Free Software Foundation.
    00007  *
    00008  *          This program is distributed in the hope that it will be useful,
    00009  *          but WITHOUT ANY WARRANTY; without even the implied warranty of
    00010  *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00011  *          GNU General Public License for more details.
    00012  *
    00013  *          You should have received a copy of the GNU General Public License
    00014  *          along with this program; if not, write to the Free Software
    00015  *          Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00016  */
    00017
    00018 #ifndef SYMEVAL_H
    00019 #define SYMEVAL_H
    00020
    00021 #include <Sym.h>
    00022 #include <FunDef.h>
    00023 #include <ErrorMeasure.h>
    00024 #include <BoundsCheck.h>
    00025
    00026 #include <eoPopEvalFunc.h>
    00027
    00028 template <class EoType>
    00029 class eoSymPopEval : public eoPopEvalFunc<EoType> {
    00030
    00031     BoundsCheck&  check;
    00032     ErrorMeasure& measure;
    00033     unsigned size_cap;
    00034
    00035     public:
    00036
    00037     eoSymPopEval(BoundsCheck& _check, ErrorMeasure& _measure, unsigned _size_cap) :
    00038         check(_check), measure(_measure), size_cap(_size_cap) {}
    00039
    00048     void operator()(eoPop<EoType>& p1, eoPop<EoType>& p2) {
    00049
    00050         std::vector<unsigned> unevaluated;
    00051         std::vector<Sym> tmppop;
    00052
    00053         for (unsigned i = 0; i < p1.size(); ++i) {
    00054             if (p1[i].invalid()) {
    00055
    00056                 if (expand_all(p1[i]).size() < size_cap && check.in_bounds(p1[i])) {
    00057                     unevaluated.push_back(i);
    00058                     tmppop.push_back( static_cast<Sym>(p1[i]) );
    00059                 } else {
    00060                     p1[i].fitness( measure.worst_performance() );
    00061                 }
    00062             }
    00063         }
    00064
    00065         for (unsigned i = 0; i < p2.size(); ++i) {
    00066             if (p2[i].invalid()) {
    00067
    00068                 if (expand_all(p2[i]).size() < size_cap && check.in_bounds(p2[i])) {
    00069
    00070                     unevaluated.push_back(p1.size() + i);
    00071                     tmppop.push_back( static_cast<Sym>(p2[i]) );
    00072
    00073                 } else {
    00074                     p2[i].fitness( measure.worst_performance() ); // pretty bad error
    00075                 }
    00076             }
    00077         }
    00078
    00079         std::vector<ErrorMeasure::result> result = measure.calc_error(tmppop);
    00080
    00081         for (unsigned i = 0; i < result.size(); ++i) {
    00082             unsigned idx = unevaluated[i];
    00083
    00084             if (idx < p1.size()) {
    00085                 p1[idx].fitness(result[i].error);
    00086             } else {
    00087                 idx -= p1.size();
    00088                 p2[idx].fitness(result[i].error);
    00089             }
    00090         }
    00091     }
    00092
    00093 };
    00094
    00095
    00096 #endif