# RoyalRoad.h

    00001 /*
    00002    RoyalRoad.h
    00003    -- Implementation of the Royal Road function for any length and block size
    00004    (c) GeNeura Team 2001, Marc Schoenauer 2000
    00005
    00006     This library is free software; you can redistribute it and/or
    00007     modify it under the terms of the GNU Lesser General Public
    00008     License as published by the Free Software Foundation; either
    00009     version 2 of the License, or (at your option) any later version.
    00010
    00011     This library 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 GNU
    00014     Lesser General Public License for more details.
    00015
    00016     You should have received a copy of the GNU Lesser General Public
    00017     License along with this library; if not, write to the Free Software
    00018     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00019
    00020     Contact: todos@geneura.ugr.es, http://geneura.ugr.es
    00021              Marc.Schoenauer@polytechnique.fr
    00022 CVS Info: $Date: 2001/06/21 12:03:17 $ $Header: /cvsroot/eodev/eo/test/RoyalRoad.h,v 1.3 2001/06/21 12:03:17 jmerelo Exp $ $Author: jmerelo $
    00023 */
    00024
    00025 #ifndef RoyalRoad_h
    00026 #define RoyalRoad_h
    00027
    00028 template<class EOT>
    00029 class RoyalRoad: public eoEvalFunc<EOT> {
    00030
    00031  public:
    00032
    00033   typedef typename EOT::Fitness FitT;
    00034
    00036   RoyalRoad( unsigned _div ): eoEvalFunc<EOT >(), div( _div ) {};
    00037
    00038   // Applies the function
    00039   virtual void operator() ( EOT & _eo )  {
    00040         FitT fitness = 0;
    00041     if (_eo.invalid()) {
    00042           for ( unsigned i = 0; i < _eo.size()/div; i ++ ) {
    00043                 bool block = true;
    00044                 for ( unsigned j = 0; j < div; j ++ ) {
    00045                   block &= _eo[i*div+j];
    00046                 }
    00047                 if (block) {
    00048                   fitness += div;
    00049                 }
    00050           }
    00051           _eo.fitness( fitness );
    00052         }
    00053   };
    00054
    00055   private:
    00056         unsigned div;
    00057
    00058 };
    00059
    00060 #endif