EvolvingObjects
Replacement operators

Replacors are operators that replace a subset of a population by another set of individuals. More...

Classes

class  eoG3Replacement< EOT >
 eoG3Replacement is an eoReplacement: More...
class  eoMerge< Chrom >
 eoMerge: Base class for elitist replacement algorithms. More...
class  eoElitism< EOT >
 Straightforward elitism class, specify the number of individuals to copy into new geneneration or the rate w.r.t. More...
class  eoNoElitism< EOT >
 No elite. More...
class  eoPlus< EOT >
 Very elitist class, copies entire population into next gen. More...
class  eoMergeReduce< EOT >
 eoMergeReduce: abstract replacement strategy that is just an application of an embedded merge, followed by an embedded reduce More...
class  eoPlusReplacement< EOT >
 ES type of replacement strategy: first add parents to population, then truncate. More...
class  eoCommaReplacement< EOT >
 ES type of replacement strategy: ignore parents, truncate offspring. More...
class  eoEPReplacement< EOT >
 EP type of replacement strategy: first add parents to population, then truncate using EP tournament. More...
class  eoMGGReplacement< EOT >
 eoMGGReplacement is an eoReplacement: More...
class  eoReduce< EOT >
 eoReduce: .reduce the new generation to the specified size At the moment, limited to truncation - with 2 different methods, one that sorts the whole population, and one that repeatidely kills the worst. More...
class  eoTruncate< EOT >
 truncation method using sort More...
class  eoRandomReduce< EOT >
 random truncation More...
class  eoEPReduce< EOT >
 EP truncation method (some global stochastic tournament + sort) Softer selective pressure than pure truncate. More...
class  eoLinearTruncate< EOT >
 a truncate class that does not sort, but repeatidely kills the worse. More...
class  eoDetTournamentTruncate< EOT >
 a truncate class based on a repeated deterministic (reverse!) tournament To be used in SSGA-like replacements (e.g. More...
class  eoStochTournamentTruncate< EOT >
 a truncate class based on a repeated deterministic (reverse!) tournament To be used in SSGA-like replacements (e.g. More...
class  eoReduceMerge< EOT >
 eoReduceMerge: Replacement strategies that start by reducing the parents, then merge with the offspring More...
class  eoSSGAWorseReplacement< EOT >
 SSGA replace worst. More...
class  eoSSGADetTournamentReplacement< EOT >
 SSGA deterministic tournament replacement. More...
class  eoSSGAStochTournamentReplacement< EOT >
 SSGA stochastic tournament replacement. More...
class  eoReduceMergeReduce< EOT >
 eoReduceMergeReduce is an eoReplacement: More...
class  eoReduceSplit< EOT >
 eoReduceSplit: reduce the pop to the specified size AND eventually returns the eliminated guys More...
class  eoTruncateSplit< EOT >
 deterministic truncation method using sort More...
class  eoLinearTruncateSplit< EOT >
 a ReduceSplit class that does not sort, but repeatidely kills the worse. More...
class  eoRandomSplit< EOT >
 random truncation - batch version More...
class  eoLinearRandomSplit< EOT >
 random truncation - linear version More...
class  eoDetTournamentTruncateSplit< EOT >
 a ReduceSplit class based on a repeated deterministic (reverse!) tournament To be used in SSGA-like replacements (e.g. More...
class  eoStochTournamentTruncateSplit< EOT >
 a ReduceSplit class based on a repeated deterministic (reverse!) tournament To be used in SSGA-like replacements (e.g. More...
class  eoReplacement< EOT >
 The base class for all replacement functors. More...
class  eoGenerationalReplacement< EOT >
 generational replacement == swap populations More...
class  eoWeakElitistReplacement< EOT >
 eoWeakElitistReplacement: a wrapper for other replacement procedures. More...
class  eoSurviveAndDie< EOT >
 eoSurviveAndDie A pure abstract class, to store the howmany's More...
class  eoDeterministicSurviveAndDie< EOT >
 An instance (theonly one as of today, Dec. More...
class  eoDeterministicSaDReplacement< EOT >
 eoDeterministicSaDReplacement: replacement strategy that is just, in sequence saves best and kill worse from parents + saves best and kill worse from offspring + merge remaining (neither save nor killed) parents and offspring + reduce that merged population = returns reduced pop + best parents + best offspring More...

Enumerations

enum  OpType { unary = 0, binary = 1, quadratic = 2, general = 3 }

Functions

 eoOp< EOType >::eoOp (OpType _type)
 Ctor.
 eoOp< EOType >::eoOp (const eoOp &_eop)
 Copy Ctor.
virtual eoOp< EOType >::~eoOp ()
 Needed virtual destructor.
OpType eoOp< EOType >::getType () const
 getType: number of operands it takes and individuals it produces
 eoMonOp< EOType >::eoMonOp ()
 Ctor.
virtual std::string eoMonOp< EOType >::className () const
 eoBinOp< EOType >::eoBinOp ()
 Ctor.
virtual std::string eoBinOp< EOType >::className () const
 eoQuadOp< EOType >::eoQuadOp ()
 Ctor.
virtual std::string eoQuadOp< EOType >::className () const
 eoQuad2BinOp< EOT >::eoQuad2BinOp (eoQuadOp< EOT > &_quadOp)
 Ctor.
bool eoQuad2BinOp< EOT >::operator() (EOT &_eo1, const EOT &_eo2)
 Operator() simply calls embedded quadOp operator() with dummy second arg.

Variables

OpType eoOp< EOType >::opType
 OpType is the type of the operator: how many operands it takes and how many it produces.
eoQuadOp< EOT > & eoQuad2BinOp< EOT >::quadOp

Detailed Description

Replacors are operators that replace a subset of a population by another set of individuals.

Here is an example with several replacement operators:

//-----------------------------------------------------------------------------

// to avoid long name warnings
#ifdef _MSC_VER
#pragma warning(disable:4786)
#endif

#include <stdexcept>  // runtime_error

//-----------------------------------------------------------------------------
// tt.cpp:
//
//-----------------------------------------------------------------------------


// general
#include <eo>
//-----------------------------------------------------------------------------

struct Dummy : public EO<double>
{
    typedef double Type;
  void printOn(std::ostream & _os) const
  {
      _os << " - ";
      EO<double>::printOn(_os);
  }
};


struct eoDummyPop : public eoPop<Dummy>
{
public :
    eoDummyPop(int s=0) { resize(s); }
};

//-----------------------------------------------------------------------------

int the_main(int argc, char **argv)
{
  eoParser parser(argc, argv);
  eoValueParam<unsigned int> parentSizeParam(10, "parentSize", "Parent size",'P');
  parser.processParam( parentSizeParam );
    unsigned int pSize = parentSizeParam.value();

  eoValueParam<unsigned int> offsrpringSizeParam(10, "offsrpringSize", "Offsrpring size",'O');
  parser.processParam( offsrpringSizeParam );
    unsigned int oSize = offsrpringSizeParam.value();

  eoValueParam<unsigned int> tournamentSizeParam(2, "tournamentSize", "Deterministic tournament size",'T');
  parser.processParam( tournamentSizeParam );
    unsigned int tSize = tournamentSizeParam.value();

  eoValueParam<double> tournamentRateParam(0.75, "tournamentRate", "Stochastic tournament rate",'R');
  parser.processParam( tournamentRateParam );
    double tRate = tournamentRateParam.value();

  eoValueParam<double> sParentsElitismRateParam(0.1, "sParentsElitismRateParam", "Strong elitism rate for parents",'E');
  parser.processParam( sParentsElitismRateParam );
    double sParentsElitismRate = sParentsElitismRateParam.value();

  eoValueParam<double> sParentsEugenismRateParam(0, "sParentsEugenismRateParam", "Strong Eugenism rate",'e');
  parser.processParam( sParentsEugenismRateParam );
    double sParentsEugenismRate = sParentsEugenismRateParam.value();

  eoValueParam<double> sOffspringElitismRateParam(0, "sOffspringElitismRateParam", "Strong elitism rate for parents",'E');
  parser.processParam( sOffspringElitismRateParam );
    double sOffspringElitismRate = sOffspringElitismRateParam.value();

  eoValueParam<double> sOffspringEugenismRateParam(0, "sOffspringEugenismRateParam", "Strong Eugenism rate",'e');
  parser.processParam( sOffspringEugenismRateParam );
    double sOffspringEugenismRate = sOffspringEugenismRateParam.value();

    if (parser.userNeedsHelp())
      {
        parser.printHelp(std::cout);
        exit(1);
      }

    unsigned i;

    std::cout << "Testing the replacements\nParents SIze = " << pSize
         << " and offspring size = " << oSize << std::endl;

    rng.reseed(42);


    eoDummyPop orgParents(pSize);
    eoDummyPop orgOffspring(oSize);

    // initialize so we can recognize them later!
    for (i=0; i<pSize; i++)
      orgParents[i].fitness(2*i+1);
    for (i=0; i<oSize; i++)
      orgOffspring[i].fitness(2*i);

std::cout << "Initial parents (odd)\n" << orgParents << "\n And initial offsprings (even)\n" << orgOffspring << std::endl;

    // now the ones we're going to play with
    eoDummyPop parents(0);
    eoDummyPop offspring(0);

// the replacement procedures under test
    eoGenerationalReplacement<Dummy> genReplace;
    eoPlusReplacement<Dummy> plusReplace;
    eoEPReplacement<Dummy> epReplace(tSize);
    eoCommaReplacement<Dummy> commaReplace;
    eoWeakElitistReplacement<Dummy> weakElitistReplace(commaReplace);
    // the SSGA replacements
    eoSSGAWorseReplacement<Dummy> ssgaWorseReplace;
    eoSSGADetTournamentReplacement<Dummy> ssgaDTReplace(tSize);
    eoSSGAStochTournamentReplacement<Dummy> ssgaDSReplace(tRate);

    // here we go
    // Generational
    parents = orgParents;
    offspring = orgOffspring;

    std::cout << "eoGenerationalReplacement\n";
    std::cout << "=========================\n";
    genReplace(parents, offspring);
std::cout << "Parents (originally odd)\n" << parents << "\n And offsprings (orogonally even\n" << offspring << std::endl;

    // Plus
    parents = orgParents;
    offspring = orgOffspring;

    std::cout << "eoPlusReplacement\n";
    std::cout << "=================\n";
    plusReplace(parents, offspring);
std::cout << "Parents (originally odd)\n" << parents << "\n And offsprings (originally even)\n" << offspring << std::endl;

    // EP (proche d'un PLUS
    parents = orgParents;
    offspring = orgOffspring;

    std::cout << "eoEPReplacement\n";
    std::cout << "===============\n";
    epReplace(parents, offspring);
std::cout << "Parents (originally odd)\n" << parents << "\n And offsprings (originally even)\n" << offspring << std::endl;

    // Comma
    parents = orgParents;
    offspring = orgOffspring;

    if (parents.size() > offspring.size() )
        std::cout << "Skipping Comma Replacement, more parents than offspring\n";
    else
      {
        std::cout << "eoCommaReplacement\n";
        std::cout << "==================\n";
        commaReplace(parents, offspring);
        std::cout << "Parents (originally odd)\n" << parents << "\n And offsprings (originally even)\n" << offspring << std::endl;

        // Comma with weak elitism
        parents = orgParents;
        offspring = orgOffspring;

        std::cout << "The same, with WEAK elitism\n";
        std::cout << "===========================\n";
        weakElitistReplace(parents, offspring);
        std::cout << "Parents (originally odd)\n" << parents << "\n And offsprings (originally even)\n" << offspring << std::endl;
      }

        // preparing SSGA replace worse
        parents = orgParents;
        offspring = orgOffspring;

    if (parents.size() < offspring.size() )
        std::cout << "Skipping all SSGA Replacements, more offspring than parents\n";
    else
      {
        std::cout << "SSGA replace worse\n";
        std::cout << "==================\n";
        ssgaWorseReplace(parents, offspring);
        std::cout << "Parents (originally odd)\n" << parents << "\n And offsprings (originally even)\n" << offspring << std::endl;

    // SSGA deterministic tournament
        parents = orgParents;
        offspring = orgOffspring;

        std::cout << "SSGA deterministic tournament\n";
        std::cout << "=============================\n";
        ssgaDTReplace(parents, offspring);
        std::cout << "Parents (originally odd)\n" << parents << "\n And offsprings (originally even)\n" << offspring << std::endl;

    // SSGA stochastic tournament
        parents = orgParents;
        offspring = orgOffspring;

        std::cout << "SSGA stochastic tournament\n";
        std::cout << "==========================\n";
        ssgaDTReplace(parents, offspring);
        std::cout << "Parents (originally odd)\n" << parents << "\n And offsprings (originally even)\n" << offspring << std::endl;
      }

    // the general replacement
    eoDeterministicSaDReplacement<Dummy> sAdReplace(sParentsElitismRate, sParentsEugenismRate, sOffspringElitismRate, sOffspringEugenismRate);// 10% parents survive

    parents = orgParents;
    offspring = orgOffspring;

    std::cout << "General - strong elitism\n";
    std::cout << "========================\n";
    sAdReplace(parents, offspring);
    std::cout << "Parents (originally odd)\n" << parents << "\n And offsprings (originally even)\n" << offspring << std::endl;


    return 1;
}

int main(int argc, char **argv)
{
    try
    {
        the_main(argc, argv);
    }
    catch(std::exception& e)
    {
        std::cout << "Exception: " << e.what() << std::endl;
    }

}

-*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-

----------------------------------------------------------------------------- eoReduceMerge.h (c) Maarten Keijzer, Marc Schoenauer, GeNeura Team, 2000

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This library 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 Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

Contact: todos@geneura.ugr.es, http://geneura.ugr.es Marc.Schoenauer@polytechnique.fr mkeijzer@dhi.dk


Function Documentation

template<class EOT >
eoQuad2BinOp< EOT >::eoQuad2BinOp ( eoQuadOp< EOT > &  _quadOp) [inline]

Ctor.

Parameters:
_quadOpthe eoQuadOp to be transformed

Definition at line 168 of file eoOp.h.

 All Classes Namespaces Files Functions Variables Typedefs Friends