The BIG change of general operator interface
I also changed
- the eoQuadratic into eoQuad (as dicussed with Maarten)
- the eoBin into eoBit, with more appropriate names for the "binary"
operators (that can be unary!) as no one protested when I posted on
eodev list
This commit is contained in:
parent
1b681e4e0d
commit
415b419671
60 changed files with 2034 additions and 940 deletions
|
|
@ -11,4 +11,4 @@ lib_LIBRARIES = libeo.a
|
|||
libeo_a_SOURCES = eoPrintable.cpp eoPersistent.cpp eoFunctorStore.cpp
|
||||
|
||||
libeoincdir = $(includedir)/eo
|
||||
libeoinc_HEADERS = eo EO.h apply.h eoAlgo.h eoBackInserter.h eoBreed.h eoCombinedContinue.h eoContinue.h eoCounter.h eoDetSelect.h eoDetTournamentInserter.h eoDetTournamentSelect.h eoEasyEA.h eoEvalFunc.h eoEvalFuncPtr.h eoEvolutionStrategy.h eoFactory.h eoFitContinue.h eoFitnessScalingSelect.h eoFixedLength.h eoFunctor.h eoFunctorStore.h eoGOpBreeder.h eoGOpSelector.h eoGenContinue.h eoGenericBinOp.h eoGenericMonOp.h eoGenericQuadOp.h eoIndiSelector.h eoInit.h eoInplaceTransform.h eoInserter.h eoMerge.h eoMergeReduce.h eoObject.h eoOp.h eoOpFactory.h eoOpSelMason.h eoOpSelector.h eoPersistent.h eoPop.h eoPrintable.h eoProportionalCombinedOp.h eoProportionalGOpSel.h eoProportionalOpSel.h eoProportionalSelect.h eoRandomSelect.h eoRankingSelect.h eoReduce.h eoReduceMerge.h eoReplacement.h eoSGA.h eoSGATransform.h eoScalarFitness.h eoSelect.h eoSelectFactory.h eoSelectMany.h eoSelectNumber.h eoSelectOne.h eoSelectPerc.h eoSequentialGOpSel.h eoSteadyFitContinue.h eoSteadyStateEA.h eoSteadyStateInserter.h eoSteadyStateTransform.h eoStochTournamentInserter.h eoStochTournamentSelect.h eoSurviveAndDie.h eoTransform.h eoVariableLength.h eoVariableLengthCrossover.h eoVariableLengthMutation.h eoWrappedOps.h es.h ga.h
|
||||
libeoinc_HEADERS = eo EO.h apply.h eoAlgo.h eoBreed.h eoCombinedContinue.h eoContinue.h eoCounter.h eoDetSelect.h eoDetTournamentSelect.h eoEasyEA.h eoEvalFunc.h eoEvalFuncPtr.h eoEvolutionStrategy.h eoFactory.h eoFitContinue.h eoFitnessScalingSelect.h eoFixedLength.h eoFunctor.h eoFunctorStore.h eoGenContinue.h eoGenericBinOp.h eoGenericMonOp.h eoGenericQuadOp.h eoInit.h eoMerge.h eoMergeReduce.h eoObject.h eoOp.h eoOpSelMason.h eoPersistent.h eoPop.h eoPrintable.h eoProportionalCombinedOp.h eoProportionalSelect.h eoRandomSelect.h eoRankingSelect.h eoReduce.h eoReduceMerge.h eoReplacement.h eoSGA.h eoSGATransform.h eoScalarFitness.h eoSelect.h eoSelectFactory.h eoSelectMany.h eoSelectNumber.h eoSelectOne.h eoSelectPerc.h eoSteadyFitContinue.h eoStochTournamentSelect.h eoSurviveAndDie.h eoTransform.h eoVariableLength.h eoVariableLengthCrossover.h eoVariableLengthMutation.h es.h ga.h
|
||||
|
|
|
|||
|
|
@ -1,101 +0,0 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoEvolutionStrategy.h
|
||||
// (c) Maarten Keijzer 2000, GeNeura Team, 1998
|
||||
/*
|
||||
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
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _eoEvolutionStrategy_h
|
||||
#define _eoEvolutionStrategy_h
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include <eoEasyEA.h>
|
||||
#include <eoInplaceTransform.h>
|
||||
/** eoEvolutionStrategy:
|
||||
*/
|
||||
|
||||
template<class EOT>
|
||||
class eoEvolutionStrategy: public eoAlgo<EOT>
|
||||
{
|
||||
public:
|
||||
struct plus_strategy{};
|
||||
struct comma_strategy{};
|
||||
|
||||
eoEvolutionStrategy(
|
||||
eoContinue<EOT>& _continuator,
|
||||
eoEvalFunc<EOT>& _eval,
|
||||
eoGOpSelector<EOT>& _opSel,
|
||||
float _lambdaRate,
|
||||
comma_strategy)
|
||||
: selectPerc(randomSelect, _lambdaRate),
|
||||
transform(_opSel),
|
||||
easyEA(_continuator, _eval, selectPerc, transform, noElitism, truncate)
|
||||
{}
|
||||
|
||||
eoEvolutionStrategy(
|
||||
eoContinue<EOT>& _continuator,
|
||||
eoEvalFunc<EOT>& _eval,
|
||||
eoGOpSelector<EOT>& _opSel,
|
||||
float _lambdaRate,
|
||||
plus_strategy)
|
||||
: selectPerc(randomSelect, _lambdaRate),
|
||||
transform(_opSel),
|
||||
easyEA(_continuator, _eval, selectPerc, transform, plus, truncate)
|
||||
{}
|
||||
|
||||
|
||||
/// Apply a few generation of evolution to the population.
|
||||
virtual void operator()(eoPop<EOT>& _pop)
|
||||
{
|
||||
easyEA(_pop);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
eoPlus<EOT> plus;
|
||||
eoNoElitism<EOT> noElitism;
|
||||
eoTruncate<EOT> truncate;
|
||||
eoRandomSelect<EOT> randomSelect;
|
||||
eoSelectPerc<EOT> selectPerc;
|
||||
eoInplaceTransform2<EOT> transform;
|
||||
|
||||
/// easyEA is contained rather than a base because of member initialization order!
|
||||
eoEasyEA<EOT> easyEA;
|
||||
};
|
||||
|
||||
template <class EOT>
|
||||
eoEvolutionStrategy<EOT> make_es(eoContinue<EOT>& _continuator,
|
||||
eoEvalFunc<EOT>& _eval,
|
||||
eoGOpSelector<EOT>& _opSel,
|
||||
float _lambdaRate,
|
||||
bool _comma)
|
||||
|
||||
{
|
||||
if (_comma)
|
||||
return eoEvolutionStrategy<EOT>(_continuator, _eval, _opSel, _lambdaRate, eoEvolutionStrategy<EOT>::comma_strategy());
|
||||
//else
|
||||
return eoEvolutionStrategy<EOT>(_continuator, _eval, _opSel, _lambdaRate, eoEvolutionStrategy<EOT>::plus_strategy());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#endif eoSelectTransformReduce_h
|
||||
|
||||
160
eo/src/eoGenOp.h
Normal file
160
eo/src/eoGenOp.h
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoGenOp.h
|
||||
// (c) Maarten Keijzer and Marc Schoenauer, 2001
|
||||
/*
|
||||
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: mkeijzer@dhi.dk
|
||||
Marc.Schoenauer@polytechnique.fr
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _eoGenOp_H
|
||||
#define _eoGenOp_H
|
||||
|
||||
#include <eoOp.h>
|
||||
#include <eoPopulator.h>
|
||||
|
||||
|
||||
/** @name General variation operators
|
||||
|
||||
a class that allows to use i->j operators for any i and j
|
||||
thanks to the friend class eoPopulator
|
||||
|
||||
@author Maarten Keijzer
|
||||
@version 0.0
|
||||
*/
|
||||
|
||||
|
||||
/** The base class for General Operators
|
||||
*/
|
||||
template <class EOT>
|
||||
class eoGenOp : public eoOp<EOT>, public eoUF<eoPopulator<EOT> &, void>
|
||||
{
|
||||
public :
|
||||
/// Ctor that honors its superclass
|
||||
eoGenOp(): eoOp<EOT>( eoOp<EOT>::general ) {}
|
||||
|
||||
virtual unsigned max_production(void) = 0;
|
||||
virtual string className() = 0;
|
||||
void operator()(eoPopulator<EOT>& _pop)
|
||||
{
|
||||
_pop.reserve(max_production());
|
||||
apply(_pop);
|
||||
}
|
||||
|
||||
protected :
|
||||
/** the function that will do the work
|
||||
*/
|
||||
virtual void apply(eoPopulator<EOT>& _pop) = 0;
|
||||
};
|
||||
|
||||
|
||||
/** Wrapper for eoMonOp */
|
||||
template <class EOT>
|
||||
class eoMonGenOp : public eoGenOp<EOT>
|
||||
{
|
||||
public:
|
||||
eoMonGenOp(eoMonOp<EOT>& _op) : op(_op) {}
|
||||
|
||||
unsigned max_production(void) { return 1; }
|
||||
|
||||
void apply(eoPopulator<EOT>& _it)
|
||||
{
|
||||
op(*_it); // look how simple
|
||||
|
||||
}
|
||||
string className() {return op.className();}
|
||||
private :
|
||||
eoMonOp<EOT>& op;
|
||||
};
|
||||
|
||||
/** Wrapper for binop: here we use erase method of eoPopulator
|
||||
* but we could also have an embedded selector to select the second parent
|
||||
*/
|
||||
template <class EOT>
|
||||
class eoBinGenOp : public eoGenOp<EOT>
|
||||
{
|
||||
public:
|
||||
eoBinGenOp(eoBinOp<EOT>& _op) : op(_op) {}
|
||||
|
||||
unsigned max_production(void) { return 1; }
|
||||
|
||||
/** do the work: get 2 individuals from the population, modifies
|
||||
only one (it's a eoBinOp) and erases the non-midified one
|
||||
*/
|
||||
void apply(eoPopulator<EOT>& _pop)
|
||||
{
|
||||
EOT& a = *_pop;
|
||||
EOT& b = *++_pop;
|
||||
op(a, b);
|
||||
_pop.erase();
|
||||
}
|
||||
string className() {return op.className();}
|
||||
|
||||
private :
|
||||
eoBinOp<EOT>& op;
|
||||
};
|
||||
|
||||
/** wrapper for eoBinOp with a selector */
|
||||
template <class EOT>
|
||||
class eoSelBinGenOp : public eoGenOp<EOT>
|
||||
{
|
||||
public:
|
||||
eoSelBinGenOp(eoBinOp<EOT>& _op, eoSelectOne<EOT>& _sel) :
|
||||
op(_op), sel(_sel) {}
|
||||
|
||||
unsigned max_production(void) { return 1; }
|
||||
|
||||
void apply(eoPopulator<EOT>& _pop)
|
||||
{ // _pop.source() gets the original population, an eoVecOp can make use of this as well
|
||||
op(*_pop, sel(_pop.source()));
|
||||
}
|
||||
string className() {return op.className();}
|
||||
|
||||
private :
|
||||
eoBinOp<EOT>& op;
|
||||
eoSelectOne<EOT>& sel;
|
||||
};
|
||||
|
||||
|
||||
/** Wrapper for quadop: easy as pie
|
||||
*/
|
||||
template <class EOT>
|
||||
class eoQuadGenOp : public eoGenOp<EOT>
|
||||
{
|
||||
public:
|
||||
eoQuadGenOp(eoQuadOp<EOT>& _op) : op(_op) {}
|
||||
|
||||
unsigned max_production(void) { return 2; }
|
||||
|
||||
void apply(eoPopulator<EOT>& _pop)
|
||||
{
|
||||
EOT& a = *_pop;
|
||||
EOT& b = *++_pop;
|
||||
|
||||
op(a, b);
|
||||
}
|
||||
string className() {return op.className();}
|
||||
|
||||
private :
|
||||
eoQuadOp<EOT>& op;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
88
eo/src/eoGeneralBreeder.h
Normal file
88
eo/src/eoGeneralBreeder.h
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoGeneralBreeder.h
|
||||
// (c) Maarten Keijzer and Marc Schoenauer, 2001
|
||||
/*
|
||||
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: mkeijzer@dhi.dk
|
||||
Marc.Schoenauer@polytechnique.fr
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef eoGeneralBreeder_h
|
||||
#define eoGeneralBreeder_h
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/*****************************************************************************
|
||||
* eoGeneralBreeder: transforms a population using the generalOp construct.
|
||||
*****************************************************************************/
|
||||
|
||||
#include <eoOp.h>
|
||||
#include <eoPopulator.h>
|
||||
|
||||
/**
|
||||
Base class for breeders using generalized operators.
|
||||
*/
|
||||
template<class EOT>
|
||||
class eoGeneralBreeder: public eoBreed<EOT>
|
||||
{
|
||||
public:
|
||||
/** Ctor:
|
||||
*
|
||||
* @param _select a selectoOne, to be used for all selections
|
||||
* @param _op a general operator (will generally be an eoOpContainer)
|
||||
* @param _rate pour howMany, le nbre d'enfants a generer
|
||||
* @param _interpret_as_rate <a href="../../tutorial/html/eoEngine.html#howmany">explanation</a>
|
||||
*/
|
||||
eoGeneralBreeder( eoSelectOne<EOT>& _select, eoGenOp<EOT>& _op,
|
||||
double _rate=1.0, bool _interpret_as_rate = true) :
|
||||
select( _select ), op(_op), howMany(_rate, _interpret_as_rate) {}
|
||||
|
||||
/** The breeder: simply calls the genOp on a selective populator!
|
||||
*
|
||||
* @param _parents the initial population
|
||||
* @param _offspring the resulting population (content -if any- is lost)
|
||||
*/
|
||||
void operator()(const eoPop<EOT>& _parents, eoPop<EOT>& _offspring)
|
||||
{
|
||||
unsigned target = howMany(_parents.size());
|
||||
|
||||
eoSelectivePopulator<EOT> it(_parents, select);
|
||||
|
||||
select.setup(_parents);
|
||||
|
||||
while (it.size() < target)
|
||||
{
|
||||
op(it);
|
||||
}
|
||||
|
||||
swap(_offspring, it);
|
||||
_offspring.resize(target); // you might have generated a few more
|
||||
}
|
||||
|
||||
/// The class name.
|
||||
string className() const { return "eoGeneralBreeder"; }
|
||||
|
||||
private:
|
||||
eoSelectOne<EOT>& select;
|
||||
eoGenOp<EOT>& op;
|
||||
eoHowMany howMany;
|
||||
};
|
||||
|
||||
#endif eoBreeder_h
|
||||
|
||||
|
|
@ -35,11 +35,22 @@ Genetic Operators are used for various purposes
|
|||
|
||||
/** @name Genetic operators
|
||||
|
||||
What is a genetic algorithm without genetic operators? There is a genetic operator hierarchy, with eoOp as father and eoMonOp (monary or unary operator) and eoBinOp and eoQuadraticOp (binary operators) as siblings). Nobody should subclass eoOp, you should subclass eoGeneralOp, eoBinOp, eoQuadraticOp or eoMonOp, those are the ones actually used here. \\#eoOp#s are only printable objects, so if you want to build them from a file, it has to be done in another class, namely factories. Each hierarchy of #eoOp#s should have its own factory, which know how to build them from a description in a file.
|
||||
What is a genetic algorithm without genetic operators?
|
||||
There is a genetic operator hierarchy, with eoOp as father and
|
||||
eoMonOp (monary or unary operator), eoBinOp and eoQuadOp (binary operators)
|
||||
and eoGenOp (any number of inputs and outputs, see eoGenOp.h)
|
||||
as subclasses.
|
||||
Nobody should subclass eoOp, you should subclass eoGenOp, eoBinOp, eoQuadOp
|
||||
or eoMonOp, those are the ones actually used here.
|
||||
|
||||
@author GeNeura Team
|
||||
@version 0.1
|
||||
@see eoOpFactory
|
||||
#eoOp#s are only printable objects, so if you want to build them
|
||||
from a file, it has to be done in another class, namely factories.
|
||||
Each hierarchy of #eoOp#s should have its own factory, which know
|
||||
how to build them from a description in a file.
|
||||
|
||||
@author GeNeura Team, Marten Keijzer and Marc Schoenauer
|
||||
@version 0.9
|
||||
@see eoGenOp.h eoOpFactory
|
||||
*/
|
||||
|
||||
|
||||
|
|
@ -102,17 +113,14 @@ public:
|
|||
virtual string className() const {return "eoBinOp";};
|
||||
};
|
||||
|
||||
// planning the change of name eoQuadraticOp --> eoQuadOp
|
||||
#define eoQuadraticOp eoQuadOp
|
||||
|
||||
/** Quadratic genetic operator: subclasses eoOp, and defines basically the
|
||||
/** Quad genetic operator: subclasses eoOp, and defines basically the
|
||||
operator() with two operands, both can be modified.
|
||||
*/
|
||||
template<class EOType>
|
||||
class eoQuadraticOp: public eoOp<EOType>, public eoBF<EOType&, EOType&, void> {
|
||||
class eoQuadOp: public eoOp<EOType>, public eoBF<EOType&, EOType&, void> {
|
||||
public:
|
||||
/// Ctor
|
||||
eoQuadraticOp()
|
||||
eoQuadOp()
|
||||
:eoOp<EOType>( eoOp<EOType>::quadratic ) {};
|
||||
virtual string className() const {return "eoQuadOp";};
|
||||
};
|
||||
|
|
@ -145,38 +153,5 @@ private:
|
|||
eoQuadOp<EOT> & quadOp;
|
||||
};
|
||||
|
||||
// some forward declarations
|
||||
|
||||
template<class EOT>
|
||||
|
||||
class eoIndiSelector;
|
||||
|
||||
|
||||
template<class EOT>
|
||||
|
||||
class eoInserter;
|
||||
|
||||
|
||||
/**
|
||||
* eGeneralOp: General genetic operator; for objects used to transform sets
|
||||
* of EOs. Nary ("orgy") operators should be derived from this class
|
||||
|
||||
Derived from eoB(inary)F(unction)
|
||||
Applies the genetic operator
|
||||
to a individuals dispensed by an eoIndividualSelector,
|
||||
and puts the results in the eoIndividualInserter.
|
||||
Any number of inputs can be requested and any number of outputs
|
||||
can be produced.
|
||||
*/
|
||||
|
||||
template<class EOT>
|
||||
|
||||
class eoGeneralOp: public eoOp<EOT>, public eoBF<eoIndiSelector<EOT>&, eoInserter<EOT>&, void>
|
||||
{
|
||||
public:
|
||||
/// Ctor that honors its superclass
|
||||
eoGeneralOp(): eoOp<EOT>( eoOp<EOT>::general ) {}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
201
eo/src/eoOpContainer.h
Normal file
201
eo/src/eoOpContainer.h
Normal file
|
|
@ -0,0 +1,201 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoOpContainer.h
|
||||
// (c) Maarten Keijzer and Marc Schoenauer, 2001
|
||||
/*
|
||||
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: mkeijzer@dhi.dk
|
||||
Marc.Schoenauer@polytechnique.fr
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _eoOpContainer_H
|
||||
#define _eoOpContainer_H
|
||||
|
||||
#include <eoGenOp.h>
|
||||
|
||||
/** eoOpContainer is a base class for the sequential and proportional selectors
|
||||
* It takes care of wrapping the other operators,
|
||||
* and deleting stuff that it has allocated
|
||||
*
|
||||
* Warning: all operators are added together with a rate (double)
|
||||
* However, the meaning of this rate will be different in
|
||||
* the differnet instances of eoOpContainer:
|
||||
* an ***absolute*** probability in the sequential version, and
|
||||
* a ***relative*** weight in the proportional version
|
||||
*/
|
||||
template <class EOT>
|
||||
class eoOpContainer : public eoGenOp<EOT>
|
||||
{
|
||||
public :
|
||||
/** Ctor: nothing much to do */
|
||||
eoOpContainer() : max_to_produce(0) {}
|
||||
|
||||
/** Dtor: delete all the GenOps created when wrapping simple ops
|
||||
*/
|
||||
virtual ~eoOpContainer(void)
|
||||
{
|
||||
for (unsigned i = 0; i < owned_genops.size(); ++i)
|
||||
delete owned_genops[i];
|
||||
}
|
||||
|
||||
/** for memory management (doesn't have to be very precise */
|
||||
virtual unsigned max_production(void)
|
||||
{
|
||||
return max_to_produce;
|
||||
}
|
||||
|
||||
/** wraps then add a simple eoMonOp */
|
||||
void add(eoMonOp<EOT>& _op, double _rate)
|
||||
{
|
||||
owned_genops.push_back(new eoMonGenOp<EOT>(_op));
|
||||
ops.push_back(owned_genops.back());
|
||||
rates.push_back(_rate);
|
||||
|
||||
max_to_produce = max(max_to_produce,unsigned(1));
|
||||
}
|
||||
|
||||
/** wraps then add a simple eoBinOp
|
||||
* First case, no selector
|
||||
*/
|
||||
void add(eoBinOp<EOT>& _op, double _rate)
|
||||
{
|
||||
owned_genops.push_back(new eoBinGenOp<EOT>(_op));
|
||||
ops.push_back(owned_genops.back());
|
||||
rates.push_back(_rate);
|
||||
|
||||
max_to_produce = max(max_to_produce,unsigned(1));
|
||||
}
|
||||
|
||||
/** wraps then add a simple eoBinOp
|
||||
* Second case: a sepecific selector
|
||||
*/
|
||||
void add(eoBinOp<EOT>& _op, eoSelectOne<EOT> & _sel, double _rate)
|
||||
{
|
||||
owned_genops.push_back(new eoSelBinGenOp<EOT>(_op, _sel));
|
||||
ops.push_back(owned_genops.back());
|
||||
rates.push_back(_rate);
|
||||
|
||||
max_to_produce = max(max_to_produce,unsigned(1));
|
||||
}
|
||||
|
||||
/** wraps then add a simple eoQuadOp */
|
||||
void add(eoQuadOp<EOT>& _op, double _rate)
|
||||
{
|
||||
owned_genops.push_back(new eoQuadGenOp<EOT>(_op));
|
||||
ops.push_back(owned_genops.back());
|
||||
rates.push_back(_rate);
|
||||
|
||||
max_to_produce = max(max_to_produce,unsigned(2));
|
||||
}
|
||||
|
||||
/** can add any GenOp */
|
||||
void add(eoGenOp<EOT>& _op, double _rate)
|
||||
{
|
||||
ops.push_back(&_op);
|
||||
rates.push_back(_rate);
|
||||
|
||||
max_to_produce = max(max_to_produce,_op.max_production());
|
||||
}
|
||||
|
||||
virtual string className() = 0;
|
||||
|
||||
protected :
|
||||
|
||||
vector<double> rates;
|
||||
vector<eoGenOp<EOT>*> ops;
|
||||
|
||||
private :
|
||||
vector<eoGenOp<EOT>*> owned_genops;
|
||||
unsigned max_to_produce;
|
||||
};
|
||||
|
||||
/** Sequential selection:
|
||||
* note the mark, rewind, unmark cycle
|
||||
* here operators are repeatedly applied on the same individual(s)
|
||||
* not all too elegant, but it sort of works...
|
||||
*/
|
||||
template <class EOT>
|
||||
class eoSequentialOp : public eoOpContainer<EOT>
|
||||
{
|
||||
public :
|
||||
typedef unsigned position_type;
|
||||
|
||||
|
||||
void apply(eoPopulator<EOT>& _pop)
|
||||
{
|
||||
position_type pos = _pop.tellp();
|
||||
|
||||
for (size_t i = 0; i < rates.size(); ++i)
|
||||
{
|
||||
_pop.seekp(pos);
|
||||
|
||||
do
|
||||
{
|
||||
if (eo::rng.flip(rates[i]))
|
||||
{
|
||||
// try
|
||||
// {
|
||||
// apply it to all the guys in the todo list
|
||||
(*ops[i])(_pop);
|
||||
// }
|
||||
// check for out of individuals and do nothing with that...
|
||||
// catch(eoPopulator<EOT>::OutOfIndividuals&)
|
||||
// {
|
||||
// cout << "Warning: not enough individuals to handle\n";
|
||||
// return ;
|
||||
// }
|
||||
}
|
||||
|
||||
if (!_pop.exhausted())
|
||||
++_pop;
|
||||
}
|
||||
while (!_pop.exhausted());
|
||||
}
|
||||
}
|
||||
virtual string className() {return "SequentialOp";}
|
||||
|
||||
private :
|
||||
|
||||
vector<size_t> to_apply;
|
||||
vector<size_t> production;
|
||||
};
|
||||
|
||||
|
||||
/** The proportinoal verions: easy! */
|
||||
template <class EOT>
|
||||
class eoProportionalOp : public eoOpContainer<EOT>
|
||||
{
|
||||
public :
|
||||
|
||||
void apply(eoPopulator<EOT>& _pop)
|
||||
{
|
||||
unsigned i = eo::rng.roulette_wheel(rates);
|
||||
|
||||
try
|
||||
{
|
||||
(*ops[i])(_pop);
|
||||
}
|
||||
catch(eoPopulator<EOT>::OutOfIndividuals&)
|
||||
{}
|
||||
}
|
||||
virtual string className() {return "ProportionalOp";}
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
169
eo/src/eoPopulator.h
Normal file
169
eo/src/eoPopulator.h
Normal file
|
|
@ -0,0 +1,169 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoPopulator.h
|
||||
// (c) Maarten Keijzer and Marc Schoenauer, 2001
|
||||
/*
|
||||
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: mkeijzer@dhi.dk
|
||||
Marc.Schoenauer@polytechnique.fr
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _eoPopulator_H
|
||||
#define _eoPopulator_H
|
||||
|
||||
#include <eoPop.h>
|
||||
#include <eoSelectOne.h>
|
||||
|
||||
template <class EOT>
|
||||
class eoPopulator : public eoPop<EOT>
|
||||
{
|
||||
public :
|
||||
|
||||
eoPopulator(const eoPop<EOT>& _src) : current(begin()), src(_src) {}
|
||||
|
||||
struct OutOfIndividuals {};
|
||||
|
||||
/** a populator behaves like an iterator. Hence the operator*
|
||||
* it returns the current individual -- eventually getting
|
||||
* a new one through the operator++ if at the end
|
||||
*/
|
||||
EOT& operator*(void)
|
||||
{
|
||||
if (current == end())
|
||||
operator++();
|
||||
|
||||
return *current;
|
||||
}
|
||||
|
||||
/** only prefix increment defined
|
||||
* if needed, adds a new individual using the embedded selector
|
||||
* and set the current pointer to the newly inserted individual
|
||||
* otherwise simply increment the current pointer
|
||||
*/
|
||||
eoPopulator& operator++()
|
||||
{
|
||||
if (current == end())
|
||||
{ // get new individual from derived class select()
|
||||
push_back(select());
|
||||
current = end();
|
||||
--current;
|
||||
return *this;
|
||||
}
|
||||
// else
|
||||
++current;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/** mandatory for operators that generate more offspring than parents
|
||||
* if such a thing exists ?
|
||||
*/
|
||||
void insert(const EOT& _eo)
|
||||
{ /* not really efficient, but its nice to have */
|
||||
current = eoPop<EOT>::insert(current, _eo);
|
||||
}
|
||||
|
||||
/** useful for operators that generate less offspring than parents
|
||||
* though there is another way - using a selector *within*
|
||||
* the operator to get the extra parents from outside
|
||||
*/
|
||||
void erase()
|
||||
{
|
||||
current = eoPop<EOT>::erase(current);
|
||||
}
|
||||
|
||||
/** just to make memory mangement more efficient
|
||||
*/
|
||||
void reserve(int how_many)
|
||||
{
|
||||
size_t sz = current - begin();
|
||||
eoPop<EOT>::reserve(size() + how_many);
|
||||
current = begin() + sz;
|
||||
}
|
||||
|
||||
/** can be useful for operators with embedded selectors
|
||||
* e.g. your barin and my beauty -type
|
||||
*/
|
||||
const eoPop<EOT>& source(void) { return src; }
|
||||
|
||||
typedef unsigned position_type;
|
||||
|
||||
/** this is a direct access container: tell position */
|
||||
position_type tellp() { return current - begin(); }
|
||||
/** this is a direct access container: go to position */
|
||||
void seekp(position_type pos) { current = begin() + pos; }
|
||||
/** no more individuals */
|
||||
bool exhausted(void) { return current == end(); }
|
||||
|
||||
protected :
|
||||
/** the pure virtual selection method - will be instanciated in
|
||||
* eoSeqPopulator and eoPropPopulator
|
||||
*/
|
||||
virtual const EOT& select() = 0;
|
||||
eoPop<EOT>::iterator current;
|
||||
const eoPop<EOT>& src;
|
||||
};
|
||||
|
||||
|
||||
/** SeqPopulator: an eoPopulator that sequentially goes through the population
|
||||
is supposed to be used after a batch select of a whole bunch or genitors
|
||||
*/
|
||||
template <class EOT>
|
||||
class eoSeqPopulator : public eoPopulator<EOT>
|
||||
{
|
||||
public :
|
||||
|
||||
eoSeqPopulator(const eoPop<EOT>& _pop) :
|
||||
eoPopulator<EOT>(_pop), src_it(_pop.begin()) {}
|
||||
|
||||
const EOT& select(void)
|
||||
{
|
||||
if (src_it == src.end())
|
||||
{
|
||||
throw OutOfIndividuals();
|
||||
}
|
||||
|
||||
const EOT& res = *src_it++;
|
||||
return res;
|
||||
}
|
||||
|
||||
private :
|
||||
vector<EOT>::const_iterator src_it;
|
||||
};
|
||||
|
||||
|
||||
/** SelectivePopulator an eoPoplator that uses an eoSelectOne to select guys.
|
||||
Supposedly, it is passed the initial population.
|
||||
*/
|
||||
template <class EOT>
|
||||
class eoSelectivePopulator : public eoPopulator<EOT>
|
||||
{
|
||||
public :
|
||||
eoSelectivePopulator(const eoPop<EOT>& _pop, eoSelectOne<EOT>& _sel)
|
||||
: eoPopulator<EOT>(_pop), sel(_sel) {}
|
||||
|
||||
const EOT& select()
|
||||
{
|
||||
return sel(src);
|
||||
}
|
||||
|
||||
private :
|
||||
eoSelectOne<EOT>& sel;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -172,21 +172,21 @@ std::vector<double> rates;
|
|||
//// combined QuadOp
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
/** Quadratic genetic operator: subclasses eoOp, and defines basically the
|
||||
/** Quad genetic operator: subclasses eoOp, and defines basically the
|
||||
operator() with two operands, both can be modified.
|
||||
*/
|
||||
/** COmbined quadratic genetic operator:
|
||||
/** Combined quad genetic operator:
|
||||
* operator() has two operands, both can be modified
|
||||
|
||||
* generic operators are now allowed: there are imbedded into
|
||||
* the corresponding "true" operator
|
||||
*/
|
||||
template <class EOT>
|
||||
class eoPropCombinedQuadOp: public eoQuadraticOp<EOT>
|
||||
class eoPropCombinedQuadOp: public eoQuadOp<EOT>
|
||||
{
|
||||
public:
|
||||
/// Ctor from a true operator
|
||||
eoPropCombinedQuadOp(eoQuadraticOp<EOT> & _first, const double _rate)
|
||||
eoPropCombinedQuadOp(eoQuadOp<EOT> & _first, const double _rate)
|
||||
{
|
||||
ops.push_back(&_first);
|
||||
rates.push_back(_rate);
|
||||
|
|
@ -204,7 +204,7 @@ public:
|
|||
virtual string className() const { return "eoPropCombinedQuadOp"; }
|
||||
|
||||
// addition of a true operator
|
||||
virtual void add(eoQuadraticOp<EOT> & _op, const double _rate, bool _verbose=false)
|
||||
virtual void add(eoQuadOp<EOT> & _op, const double _rate, bool _verbose=false)
|
||||
{
|
||||
ops.push_back(&_op);
|
||||
rates.push_back(_rate);
|
||||
|
|
@ -242,7 +242,7 @@ virtual void add(eoGenericQuadOp<EOT> & _op, const double _rate, bool _verbose=f
|
|||
(*ops[what])(_indi1, _indi2); // apply it
|
||||
}
|
||||
private:
|
||||
std::vector<eoQuadraticOp<EOT>*> ops;
|
||||
std::vector<eoQuadOp<EOT>*> ops;
|
||||
std::vector<double> rates;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
#include <apply.h>
|
||||
|
||||
/** The Simple Genetic Algorithm, following Holland and Goldberg
|
||||
* Needs a selector (class eoSelectOne) a crossover (eoQuadratic,
|
||||
* Needs a selector (class eoSelectOne) a crossover (eoQuad,
|
||||
* i.e. a 2->2 operator) and a mutation with their respective rates,
|
||||
* of course an evaluation function (eoEvalFunc) and a continuator
|
||||
* (eoContinue) which gives the stopping criterion. Performs full
|
||||
|
|
@ -53,7 +53,7 @@ public :
|
|||
// in the one above. Any objection :-) MS
|
||||
eoSGA(
|
||||
eoSelectOne<EOT>& _select,
|
||||
eoQuadraticOp<EOT>& _cross, float _crate,
|
||||
eoQuadOp<EOT>& _cross, float _crate,
|
||||
eoMonOp<EOT>& _mutate, float _mrate,
|
||||
eoEvalFunc<EOT>& _eval,
|
||||
eoContinue<EOT>& _cont)
|
||||
|
|
@ -103,7 +103,7 @@ private :
|
|||
eoContinue<EOT>& cont;
|
||||
eoMonOp<EOT>& mutate;
|
||||
float mutationRate;
|
||||
eoQuadraticOp<EOT>& cross;
|
||||
eoQuadOp<EOT>& cross;
|
||||
float crossoverRate;
|
||||
eoSelectPerc<EOT> select;
|
||||
eoEvalFunc<EOT>& eval;
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ template<class EOT> class eoSGATransform : public eoTransform<EOT>
|
|||
public:
|
||||
|
||||
/// Default constructor.
|
||||
eoSGATransform(eoQuadraticOp<EOT>& _cross, double _cProba,
|
||||
eoSGATransform(eoQuadOp<EOT>& _cross, double _cProba,
|
||||
eoMonOp<EOT>& _mutate, double _mProba)
|
||||
: cross(_cross),
|
||||
crossoverProba(_cProba),
|
||||
|
|
@ -84,7 +84,7 @@ template<class EOT> class eoSGATransform : public eoTransform<EOT>
|
|||
};
|
||||
|
||||
private:
|
||||
eoQuadraticOp<EOT>& cross;
|
||||
eoQuadOp<EOT>& cross;
|
||||
double crossoverProba;
|
||||
eoMonOp<EOT>& mutate;
|
||||
double mutationProba;
|
||||
|
|
@ -102,7 +102,7 @@ template<class EOT> class eoDynSGATransform : public eoTransform<EOT>
|
|||
public:
|
||||
|
||||
/// Default constructor - receives values
|
||||
eoDynSGATransform(eoQuadraticOp<EOT>& _cross, double _cProba,
|
||||
eoDynSGATransform(eoQuadOp<EOT>& _cross, double _cProba,
|
||||
eoMonOp<EOT>& _mutate, double _mProba)
|
||||
: cross(_cross),
|
||||
crossoverProbaHolder(_cProba), crossoverProba(crossoverProbaHolder),
|
||||
|
|
@ -112,7 +112,7 @@ template<class EOT> class eoDynSGATransform : public eoTransform<EOT>
|
|||
/// This constructor receives pointers
|
||||
// these will usually be some eoValueParam<double>.value()
|
||||
// hence the ...Holder data will bever be used in this case
|
||||
eoDynSGATransform(eoQuadraticOp<EOT>& _cross, double* _cProbaRef,
|
||||
eoDynSGATransform(eoQuadOp<EOT>& _cross, double* _cProbaRef,
|
||||
eoMonOp<EOT>& _mutate, double* _mProbaRef)
|
||||
: cross(_cross),
|
||||
crossoverProbaHolder(0), crossoverProba(*_cProbaRef),
|
||||
|
|
@ -154,7 +154,7 @@ private:
|
|||
// difference with eoSGATransform: the operator probabilities
|
||||
// they can be passed by reference or by value.
|
||||
// hence we need here to use a reference, and to eventually store a value
|
||||
eoQuadraticOp<EOT>& cross;
|
||||
eoQuadOp<EOT>& cross;
|
||||
double crossoverProbaHolder; // the value, used only if ctor gets a value
|
||||
double& crossoverProba; // the reference, to be used in operator()
|
||||
eoMonOp<EOT>& mutate;
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ Simply calls a crossover for the object variables,
|
|||
*/
|
||||
|
||||
template <class EOT>
|
||||
class eoEsStdevXOver : public eoQuadraticOp<EOT>
|
||||
class eoEsStdevXOver : public eoQuadOp<EOT>
|
||||
{
|
||||
public :
|
||||
eoEsStdevXOver(eoGenericQuadOp<vector<double> > & _objectXOver,
|
||||
|
|
|
|||
|
|
@ -47,7 +47,10 @@ MS January 25. 2001
|
|||
/** eoUniformMutation --> changes all values of the vector
|
||||
by uniform choice with range epsilon
|
||||
with probability p_change per variable
|
||||
\class eoUniformMutation eoRealOp.h Tutorial/eoRealOp.h
|
||||
\ingroup parameteric
|
||||
*/
|
||||
|
||||
template<class EOT> class eoGenericUniformMutation: public eoGenericMonOp<EOT>
|
||||
{
|
||||
public:
|
||||
|
|
@ -110,6 +113,8 @@ private:
|
|||
|
||||
/** eoDetUniformMutation --> changes exactly k values of the vector
|
||||
by uniform choice with range epsilon
|
||||
\class eoDetUniformMutation eoRealOp.h Tutorial/eoRealOp.h
|
||||
\ingroup parameteric
|
||||
*/
|
||||
|
||||
template<class EOT> class eoGenericDetUniformMutation:
|
||||
|
|
@ -168,10 +173,14 @@ private:
|
|||
};
|
||||
|
||||
|
||||
// two arithmetical crossovers
|
||||
|
||||
/** eoSegmentCrossover --> uniform choice in segment
|
||||
== arithmetical with same value along all coordinates
|
||||
== arithmetical with same value along all coordinates
|
||||
\class eoSegmentCrossover eoRealOp.h Tutorial/eoRealOp.h
|
||||
\ingroup parameteric
|
||||
*/
|
||||
|
||||
template<class EOT> class eoGenericSegmentCrossover: public eoGenericQuadOp<EOT>
|
||||
{
|
||||
public:
|
||||
|
|
@ -257,8 +266,11 @@ protected:
|
|||
};
|
||||
|
||||
/** eoArithmeticCrossover --> uniform choice in hypercube
|
||||
== arithmetical with different values for each coordinate
|
||||
== arithmetical with different values for each coordinate
|
||||
\class eoArithmeticCrossover eoRealOp.h Tutorial/eoRealOp.h
|
||||
\ingroup parameteric
|
||||
*/
|
||||
|
||||
template<class EOT> class eoGenericArithmeticCrossover:
|
||||
public eoGenericQuadOp<EOT>
|
||||
{
|
||||
|
|
@ -354,7 +366,10 @@ protected:
|
|||
|
||||
|
||||
/** eoRealUxOver --> Uniform crossover, also termed intermediate crossover
|
||||
\class eoRealUxOver eoRealOp.h Tutorial/eoRealOp.h
|
||||
\ingroup parameteric
|
||||
*/
|
||||
|
||||
template<class EOT> class eoGenericRealUxOver: public eoGenericQuadOp<EOT>
|
||||
{
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -168,7 +168,7 @@ private:
|
|||
\ingroup parameteric
|
||||
*/
|
||||
|
||||
template<class EOT> class eoSegmentCrossover: public eoQuadraticOp<EOT>
|
||||
template<class EOT> class eoSegmentCrossover: public eoQuadOp<EOT>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
|
@ -259,7 +259,7 @@ protected:
|
|||
\ingroup parameteric
|
||||
*/
|
||||
|
||||
template<class EOT> class eoArithmeticCrossover: public eoQuadraticOp<EOT>
|
||||
template<class EOT> class eoArithmeticCrossover: public eoQuadOp<EOT>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
|
@ -358,7 +358,7 @@ protected:
|
|||
\ingroup parameteric
|
||||
*/
|
||||
|
||||
template<class EOT> class eoRealUxOver: public eoQuadraticOp<EOT>
|
||||
template<class EOT> class eoRealUxOver: public eoQuadOp<EOT>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -30,12 +30,12 @@
|
|||
#define _ga_h
|
||||
|
||||
// all bitstring-specific files
|
||||
#include <ga/eoBin.h>
|
||||
#include <ga/eoBit.h>
|
||||
|
||||
// the operators
|
||||
#include <ga/eoBitOp.h>
|
||||
|
||||
// #include <ga/eoBitOpFactory.h>
|
||||
// #include <ga/eoBitOpFactory.h> to be corrected - thanks someone!
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
|
|
|||
|
|
@ -5,4 +5,4 @@
|
|||
###############################################################################
|
||||
|
||||
libeoincdir = $(includedir)/eo/ga
|
||||
libeoinc_HEADERS = eoBin.h eoBitOp.h eoBitOpFactory.h
|
||||
libeoinc_HEADERS = eoBit.h eoBitOp.h eoBitOpFactory.h
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
eoBin.h
|
||||
eoBit.h
|
||||
(c) GeNeura Team 1998, Marc Schoenauer 2000
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
|
|
@ -24,10 +24,14 @@
|
|||
Added the calls to base class I/O routines that print the fitness
|
||||
Left printing/reading of the size of the bitstring,
|
||||
for backward compatibility, and as it is a general practice in EO
|
||||
|
||||
MS, Feb. 7, 2001
|
||||
replaced all ...Bin... names with ...Bit... names - for bitstring
|
||||
as it was ambiguous with bin...ary things
|
||||
*/
|
||||
|
||||
#ifndef eoBin_h
|
||||
#define eoBin_h
|
||||
#ifndef eoBit_h
|
||||
#define eoBit_h
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
|
@ -43,12 +47,12 @@
|
|||
Various functions for a bitstring representation
|
||||
*/
|
||||
|
||||
/** eoBin: implementation of binary chromosome.
|
||||
\class eoBin eoBin.h ga/eoBin.h
|
||||
/** eoBit: implementation of bitstring chromosome.
|
||||
\class eoBit eoBit.h ga/eoBit.h
|
||||
\ingroup bitstring
|
||||
* based on STL's vector<bool> specialization.
|
||||
*/
|
||||
template <class FitT> class eoBin: public eoFixedLength<FitT, bool>
|
||||
template <class FitT> class eoBit: public eoFixedLength<FitT, bool>
|
||||
{
|
||||
public:
|
||||
|
||||
|
|
@ -56,13 +60,13 @@ template <class FitT> class eoBin: public eoFixedLength<FitT, bool>
|
|||
* (Default) Constructor.
|
||||
* @param size Size of the binary string.
|
||||
*/
|
||||
eoBin(unsigned size = 0, bool value = false):
|
||||
eoBit(unsigned size = 0, bool value = false):
|
||||
eoFixedLength<FitT, bool>(size, value) {}
|
||||
|
||||
/// My class name.
|
||||
string className() const
|
||||
{
|
||||
return "eoBin";
|
||||
return "eoBit";
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -99,4 +103,4 @@ template <class FitT> class eoBin: public eoFixedLength<FitT, bool>
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#endif //eoBin_h
|
||||
#endif //eoBit_h
|
||||
|
|
@ -40,7 +40,7 @@
|
|||
// chrom[i] = (chrom[i]) ? false : true;
|
||||
// we were calling something like
|
||||
// specific_mutate(chrom[i])
|
||||
// all mutation would also be generic ... except those eoBinNext and eoBinPrev
|
||||
// all mutation would also be generic ... except those eoBitNext and eoBitPrev
|
||||
|
||||
// If anybody reads this and want to change that (I'm also testing to see
|
||||
// if someone ever reads the headers :-), drop me a mail
|
||||
|
|
@ -57,19 +57,19 @@
|
|||
#include <algorithm> // swap_ranges
|
||||
#include <utils/eoRNG.h>
|
||||
#include <eoInit.h> // eoMonOp
|
||||
#include <ga/eoBin.h>
|
||||
#include <ga/eoBit.h>
|
||||
|
||||
|
||||
/** eoBinBitFlip --> changes 1 bit
|
||||
\class eoBinBitFlip eoBitOp.h ga/eoBitOp.h
|
||||
/** eoBitFlip --> changes 1 bit
|
||||
\class eoBitBitFlip eoBitOp.h ga/eoBitOp.h
|
||||
\ingroup bitstring
|
||||
*/
|
||||
|
||||
template<class Chrom> class eoBinBitFlip: public eoMonOp<Chrom>
|
||||
template<class Chrom> class eoOneBitFlip: public eoMonOp<Chrom>
|
||||
{
|
||||
public:
|
||||
/// The class name.
|
||||
string className() const { return "eoBinBitFlip"; }
|
||||
string className() const { return "eoOneBitFlip"; }
|
||||
|
||||
/**
|
||||
* Change one bit.
|
||||
|
|
@ -77,9 +77,9 @@ template<class Chrom> class eoBinBitFlip: public eoMonOp<Chrom>
|
|||
*/
|
||||
void operator()(Chrom& chrom)
|
||||
{
|
||||
chrom.invalidate();
|
||||
unsigned i = rng.random(chrom.size());
|
||||
unsigned i = eo::rng.random(chrom.size());
|
||||
chrom[i] = (chrom[i]) ? false : true;
|
||||
chrom.invalidate();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -94,7 +94,7 @@ template<class Chrom> class eoDetBitFlip: public eoMonOp<Chrom>
|
|||
/**
|
||||
* (Default) Constructor.
|
||||
* @param _num_bit The number of bits to change
|
||||
* default is one - equivalent to eoBinBitFlip then
|
||||
* default is one - equivalent to eoOneBitFlip then
|
||||
*/
|
||||
eoDetBitFlip(const unsigned& _num_bit = 1): num_bit(_num_bit) {}
|
||||
|
||||
|
|
@ -107,35 +107,35 @@ template<class Chrom> class eoDetBitFlip: public eoMonOp<Chrom>
|
|||
*/
|
||||
void operator()(Chrom& chrom)
|
||||
{
|
||||
chrom.invalidate();
|
||||
// does not check for duplicate: if someone volunteers ....
|
||||
for (unsigned k=0; k<num_bit; k++)
|
||||
{
|
||||
unsigned i = rng.random(chrom.size());
|
||||
unsigned i = eo::rng.random(chrom.size());
|
||||
chrom[i] = (chrom[i]) ? false : true;
|
||||
}
|
||||
chrom.invalidate();
|
||||
}
|
||||
private:
|
||||
unsigned num_bit;
|
||||
};
|
||||
|
||||
|
||||
/** eoBinMutation --> classical mutation
|
||||
\class eoBinMutation eoBitOp.h ga/eoBitOp.h
|
||||
/** eoBitMutation --> classical mutation
|
||||
\class eoBitMutation eoBitOp.h ga/eoBitOp.h
|
||||
\ingroup bitstring
|
||||
*/
|
||||
|
||||
template<class Chrom> class eoBinMutation: public eoMonOp<Chrom>
|
||||
template<class Chrom> class eoBitMutation: public eoMonOp<Chrom>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* (Default) Constructor.
|
||||
* @param _rate Rate of mutation.
|
||||
*/
|
||||
eoBinMutation(const double& _rate = 0.01): rate(_rate) {}
|
||||
eoBitMutation(const double& _rate = 0.01): rate(_rate) {}
|
||||
|
||||
/// The class name.
|
||||
string className() const { return "eoBinMutation"; }
|
||||
string className() const { return "eoBitMutation"; }
|
||||
|
||||
/**
|
||||
* Mutate a chromosome.
|
||||
|
|
@ -145,7 +145,7 @@ template<class Chrom> class eoBinMutation: public eoMonOp<Chrom>
|
|||
{
|
||||
bool changed_something = false;
|
||||
for (unsigned i = 0; i < chrom.size(); i++)
|
||||
if (rng.flip(rate))
|
||||
if (eo::rng.flip(rate))
|
||||
{
|
||||
chrom[i] = !chrom[i];
|
||||
changed_something = true;
|
||||
|
|
@ -160,16 +160,16 @@ template<class Chrom> class eoBinMutation: public eoMonOp<Chrom>
|
|||
};
|
||||
|
||||
|
||||
/** eoBinInversion: inverts the bits of the chromosome between an interval
|
||||
\class eoBinInversion eoBitOp.h ga/eoBitOp.h
|
||||
/** eoBitInversion: inverts the bits of the chromosome between an interval
|
||||
\class eoBitInversion eoBitOp.h ga/eoBitOp.h
|
||||
\ingroup bitstring
|
||||
*/
|
||||
|
||||
template<class Chrom> class eoBinInversion: public eoMonOp<Chrom>
|
||||
template<class Chrom> class eoBitInversion: public eoMonOp<Chrom>
|
||||
{
|
||||
public:
|
||||
/// The class name.
|
||||
string className() const { return "eoBinInversion"; }
|
||||
string className() const { return "eoBitInversion"; }
|
||||
|
||||
/**
|
||||
* Inverts a range of bits in a binary chromosome.
|
||||
|
|
@ -178,8 +178,8 @@ template<class Chrom> class eoBinInversion: public eoMonOp<Chrom>
|
|||
void operator()(Chrom& chrom)
|
||||
{
|
||||
|
||||
unsigned u1 = rng.random(chrom.size() + 1) , u2;
|
||||
do u2 = rng.random(chrom.size() + 1); while (u1 == u2);
|
||||
unsigned u1 = eo::rng.random(chrom.size() + 1) , u2;
|
||||
do u2 = eo::rng.random(chrom.size() + 1); while (u1 == u2);
|
||||
unsigned r1 = min(u1, u2), r2 = max(u1, u2);
|
||||
|
||||
reverse(chrom.begin() + r1, chrom.begin() + r2);
|
||||
|
|
@ -188,16 +188,16 @@ template<class Chrom> class eoBinInversion: public eoMonOp<Chrom>
|
|||
};
|
||||
|
||||
|
||||
/** eoBinNext --> next binary value
|
||||
\class eoBinNext eoBitOp.h ga/eoBitOp.h
|
||||
/** eoBitNext --> next value when bitstring considered as binary value
|
||||
\class eoBitNext eoBitOp.h ga/eoBitOp.h
|
||||
\ingroup bitstring
|
||||
*/
|
||||
|
||||
template<class Chrom> class eoBinNext: public eoMonOp<Chrom>
|
||||
template<class Chrom> class eoBitNext: public eoMonOp<Chrom>
|
||||
{
|
||||
public:
|
||||
/// The class name.
|
||||
string className() const { return "eoBinNext"; }
|
||||
string className() const { return "eoBitNext"; }
|
||||
|
||||
/**
|
||||
* Change the bit string x to be x+1.
|
||||
|
|
@ -222,16 +222,16 @@ template<class Chrom> class eoBinNext: public eoMonOp<Chrom>
|
|||
};
|
||||
|
||||
|
||||
/** eoBinPrev --> previous binary value
|
||||
\class eoBinPrev eoBitOp.h ga/eoBitOp.h
|
||||
/** eoBitPrev --> previous value when bitstring treated as binary value
|
||||
\class eoBitPrev eoBitOp.h ga/eoBitOp.h
|
||||
\ingroup bitstring
|
||||
*/
|
||||
|
||||
template<class Chrom> class eoBinPrev: public eoMonOp<Chrom>
|
||||
template<class Chrom> class eoBitPrev: public eoMonOp<Chrom>
|
||||
{
|
||||
public:
|
||||
/// The class name.
|
||||
string className() const { return "eoBinPrev"; }
|
||||
string className() const { return "eoBitPrev"; }
|
||||
|
||||
/**
|
||||
* Change the bit string x to be x-1.
|
||||
|
|
@ -256,16 +256,16 @@ template<class Chrom> class eoBinPrev: public eoMonOp<Chrom>
|
|||
};
|
||||
|
||||
|
||||
/** eoBinCrossover --> classic 1-point crossover
|
||||
\class eoBinCrossover eoBitOp.h ga/eoBitOp.h
|
||||
/** eo1PtBitXover --> classic 1-point crossover
|
||||
\class eo1PtBitCrossover eoBitOp.h ga/eoBitOp.h
|
||||
\ingroup bitstring
|
||||
*/
|
||||
|
||||
template<class Chrom> class eoBinCrossover: public eoQuadraticOp<Chrom>
|
||||
template<class Chrom> class eo1PtBitXover: public eoQuadOp<Chrom>
|
||||
{
|
||||
public:
|
||||
/// The class name.
|
||||
string className() const { return "eoBinCrossover"; }
|
||||
string className() const { return "eo1PtBitXover"; }
|
||||
|
||||
/**
|
||||
* 1-point crossover for binary chromosomes.
|
||||
|
|
@ -274,7 +274,7 @@ template<class Chrom> class eoBinCrossover: public eoQuadraticOp<Chrom>
|
|||
*/
|
||||
void operator()(Chrom& chrom1, Chrom& chrom2)
|
||||
{
|
||||
unsigned site = rng.random(min(chrom1.size(), chrom2.size()));
|
||||
unsigned site = eo::rng.random(min(chrom1.size(), chrom2.size()));
|
||||
|
||||
if (!std::equal(chrom1.begin(), chrom1.begin()+site, chrom2.begin()))
|
||||
{
|
||||
|
|
@ -288,22 +288,22 @@ template<class Chrom> class eoBinCrossover: public eoQuadraticOp<Chrom>
|
|||
};
|
||||
|
||||
|
||||
/** eoBinUxOver --> classic Uniform crossover
|
||||
\class eoBinNxOver eoBitOp.h ga/eoBitOp.h
|
||||
/** eoUBitXover --> classic Uniform crossover
|
||||
\class eoUBitXover eoBitOp.h ga/eoBitOp.h
|
||||
\ingroup bitstring
|
||||
*/
|
||||
|
||||
template<class Chrom> class eoBinUxOver: public eoQuadraticOp<Chrom>
|
||||
template<class Chrom> class eoUBitXover: public eoQuadOp<Chrom>
|
||||
{
|
||||
public:
|
||||
/// (Default) Constructor.
|
||||
eoBinUxOver(const float& _preference = 0.5): preference(_preference)
|
||||
eoUBitXover(const float& _preference = 0.5): preference(_preference)
|
||||
{
|
||||
if ( (_preference <= 0.0) || (_preference >= 1.0) )
|
||||
runtime_error("UxOver --> invalid preference");
|
||||
}
|
||||
/// The class name.
|
||||
string className() const { return "eoBinUxOver"; }
|
||||
string className() const { return "eoUBitXover"; }
|
||||
|
||||
/**
|
||||
* Uniform crossover for binary chromosomes.
|
||||
|
|
@ -318,7 +318,7 @@ template<class Chrom> class eoBinUxOver: public eoQuadraticOp<Chrom>
|
|||
bool changed = false;
|
||||
for (unsigned int i=0; i<chrom1.size(); i++)
|
||||
{
|
||||
if (rng.flip(preference))
|
||||
if (eo::rng.flip(preference))
|
||||
{
|
||||
bool tmp = chrom1[i];
|
||||
chrom1[i]=chrom2[i];
|
||||
|
|
@ -337,23 +337,23 @@ template<class Chrom> class eoBinUxOver: public eoQuadraticOp<Chrom>
|
|||
};
|
||||
|
||||
|
||||
/** eoBinNxOver --> n-point crossover
|
||||
\class eoBinNxOver eoBitOp.h ga/eoBitOp.h
|
||||
/** eoNPtsBitXover --> n-point crossover
|
||||
\class eoNPtsBitXover eoBitOp.h ga/eoBitOp.h
|
||||
\ingroup bitstring
|
||||
*/
|
||||
|
||||
template<class Chrom> class eoBinNxOver: public eoQuadraticOp<Chrom>
|
||||
template<class Chrom> class eoNPtsBitXover: public eoQuadOp<Chrom>
|
||||
{
|
||||
public:
|
||||
/// (Default) Constructor.
|
||||
eoBinNxOver(const unsigned& _num_points = 2): num_points(_num_points)
|
||||
eoNPtsBitXover(const unsigned& _num_points = 2): num_points(_num_points)
|
||||
{
|
||||
if (num_points < 1)
|
||||
runtime_error("NxOver --> invalid number of points");
|
||||
}
|
||||
|
||||
/// The class name.
|
||||
string className() const { return "eoBinNxOver"; }
|
||||
string className() const { return "eoNPtsBitXover"; }
|
||||
|
||||
/**
|
||||
* n-point crossover for binary chromosomes.
|
||||
|
|
@ -369,7 +369,7 @@ template<class Chrom> class eoBinNxOver: public eoQuadraticOp<Chrom>
|
|||
|
||||
// select ranges of bits to swap
|
||||
do {
|
||||
unsigned bit = rng.random(max_size) + 1;
|
||||
unsigned bit = eo::rng.random(max_size) + 1;
|
||||
if (points[bit])
|
||||
continue;
|
||||
else
|
||||
|
|
@ -401,16 +401,18 @@ template<class Chrom> class eoBinNxOver: public eoQuadraticOp<Chrom>
|
|||
|
||||
|
||||
|
||||
/** eoBinGxOver --> gene crossover
|
||||
\class eoBinGxOver eoBitOp.h ga/eoBitOp.h
|
||||
/** eoBitGxOver --> Npts crossover when bistring considered
|
||||
as a string of binary-encoded genes (exchanges genes)
|
||||
Is anybody still using it apart from historians ??? :-)
|
||||
\class eoBitGxOver eoBitOp.h ga/eoBitOp.h
|
||||
\ingroup bitstring
|
||||
*/
|
||||
|
||||
template<class Chrom> class eoBinGxOver: public eoQuadraticOp<Chrom>
|
||||
template<class Chrom> class eoBitGxOver: public eoQuadOp<Chrom>
|
||||
{
|
||||
public:
|
||||
/// Constructor.
|
||||
eoBinGxOver(const unsigned _gene_size, const unsigned _num_points = 2):
|
||||
eoBitGxOver(const unsigned _gene_size, const unsigned _num_points = 2):
|
||||
gene_size(_gene_size), num_points(_num_points)
|
||||
{
|
||||
if (gene_size < 1)
|
||||
|
|
@ -420,7 +422,7 @@ template<class Chrom> class eoBinGxOver: public eoQuadraticOp<Chrom>
|
|||
}
|
||||
|
||||
/// The class name
|
||||
string className() const { return "eoBinGxOver"; }
|
||||
string className() const { return "eoBitGxOver"; }
|
||||
|
||||
/**
|
||||
* Gene crossover for binary chromosomes.
|
||||
|
|
@ -436,7 +438,7 @@ template<class Chrom> class eoBinGxOver: public eoQuadraticOp<Chrom>
|
|||
|
||||
// selects genes to swap
|
||||
do {
|
||||
unsigned bit = rng.random(max_genes);
|
||||
unsigned bit = eo::rng.random(max_genes);
|
||||
if (points[bit])
|
||||
continue;
|
||||
else
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@
|
|||
#ifndef _EOBITOPFACTORY_H
|
||||
#define _EOBITOPFACTORY_H
|
||||
|
||||
#include <eoOpFactory.h>
|
||||
#include <eoBitOp.h>
|
||||
#include <eoFactory.h>
|
||||
#include <ga/eoBitOp.h>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
|
@ -36,7 +36,7 @@ on bitstring chromosomes. Only those chromosomes can instantiate the operators
|
|||
that are created here
|
||||
@see eoSelect*/
|
||||
template< class EOT>
|
||||
class eoBitOpFactory: public eoOpFactory<EOT>
|
||||
class eoBitOpFactory: public eoFactory<EOT>
|
||||
{
|
||||
|
||||
public:
|
||||
|
|
@ -64,49 +64,97 @@ public:
|
|||
{
|
||||
eoOp<EOT> * opPtr = NULL;
|
||||
try {
|
||||
opPtr = eoOpFactory<EOT>::make( _is );
|
||||
opPtr = eoFactory<EOT>::make( _is );
|
||||
} catch ( const string& objectTypeStr ) {
|
||||
if ( objectTypeStr == "eoBinRandom") {
|
||||
opPtr = new eoBinRandom<EOT>();
|
||||
}
|
||||
if ( objectTypeStr == "eoBinBitFlip" ) {
|
||||
opPtr = new eoBinBitFlip<EOT>( );
|
||||
opPtr = new eoOneBitFlip<EOT>( );
|
||||
}
|
||||
// handles old operator names as well as new ones
|
||||
if ( objectTypeStr == "eoOneBitFlip" ) {
|
||||
opPtr = new eoOneBitFlip<EOT>( );
|
||||
}
|
||||
|
||||
// Standard BitFilp Mutation
|
||||
if ( objectTypeStr == "eoBinMutation" ) {
|
||||
float rate;
|
||||
_is >> rate;
|
||||
opPtr = new eoBinMutation<EOT>( rate );
|
||||
opPtr = new eoBitMutation<EOT>( rate );
|
||||
}
|
||||
if ( objectTypeStr == "eoBitMutation" ) {
|
||||
float rate;
|
||||
_is >> rate;
|
||||
opPtr = new eoBitMutation<EOT>( rate );
|
||||
}
|
||||
|
||||
// Bit inversion
|
||||
if ( objectTypeStr == "eoBinInversion" ) {
|
||||
opPtr = new eoBinInversion<EOT>( );
|
||||
opPtr = new eoBitInversion<EOT>( );
|
||||
}
|
||||
if ( objectTypeStr == "eoBitInversion" ) {
|
||||
opPtr = new eoBitInversion<EOT>( );
|
||||
}
|
||||
|
||||
// Next binary value
|
||||
if ( objectTypeStr == "eoBinNext" ) {
|
||||
opPtr = new eoBinNext<EOT>( );
|
||||
opPtr = new eoBitNext<EOT>( );
|
||||
}
|
||||
if ( objectTypeStr == "eoBitNext" ) {
|
||||
opPtr = new eoBitNext<EOT>( );
|
||||
}
|
||||
|
||||
// Previous binary value
|
||||
if ( objectTypeStr == "eoBinPrev" ) {
|
||||
opPtr = new eoBinPrev<EOT>( );
|
||||
opPtr = new eoBitPrev<EOT>( );
|
||||
}
|
||||
if ( objectTypeStr == "eoBinNext" ) {
|
||||
opPtr = new eoBinNext<EOT>( );
|
||||
if ( objectTypeStr == "eoBitPrev" ) {
|
||||
opPtr = new eoBitPrev<EOT>( );
|
||||
}
|
||||
|
||||
// 1 point Xover
|
||||
if ( objectTypeStr == "eoBinCrossover" ) {
|
||||
opPtr = new eoBinCrossover<EOT>( );
|
||||
opPtr = new eo1PtBitXover<EOT>( );
|
||||
}
|
||||
if ( objectTypeStr == "eo1PtBitXover" ) {
|
||||
opPtr = new eo1PtBitXover<EOT>( );
|
||||
}
|
||||
|
||||
// Npts Xover
|
||||
if ( objectTypeStr == "eoBinNxOver" ) {
|
||||
unsigned nPoints;
|
||||
_is >> nPoints;
|
||||
opPtr = new eoBinNxOver<EOT>( nPoints );
|
||||
opPtr = new eoNPtsBitXover<EOT>( nPoints );
|
||||
}
|
||||
if ( objectTypeStr == "eoNPtsBitXover" ) {
|
||||
unsigned nPoints;
|
||||
_is >> nPoints;
|
||||
opPtr = new eoNPtsBitXover<EOT>( nPoints );
|
||||
}
|
||||
|
||||
// Gene Xover (obsolete)
|
||||
if ( objectTypeStr == "eoBinGxOver" ) {
|
||||
unsigned geneSize, nPoints;
|
||||
_is >> geneSize >> nPoints;
|
||||
opPtr = new eoBinGxOver<EOT>( geneSize, nPoints );
|
||||
opPtr = new eoBitGxOver<EOT>( geneSize, nPoints );
|
||||
}
|
||||
if ( objectTypeStr == "eoBitGxOver" ) {
|
||||
unsigned geneSize, nPoints;
|
||||
_is >> geneSize >> nPoints;
|
||||
opPtr = new eoBitGxOver<EOT>( geneSize, nPoints );
|
||||
}
|
||||
|
||||
// Uniform Xover
|
||||
if ( objectTypeStr == "eoBinUxOver" ) {
|
||||
float rate;
|
||||
_is >> rate;
|
||||
opPtr = new eoBinUxOver<EOT>( rate );
|
||||
opPtr = new eoUBitXover<EOT>( rate );
|
||||
}
|
||||
if ( objectTypeStr == "eoUBitXover" ) {
|
||||
float rate;
|
||||
_is >> rate;
|
||||
opPtr = new eoUBitXover<EOT>( rate );
|
||||
}
|
||||
|
||||
// nothing read!
|
||||
if ( !opPtr ) { // to be caught by the upper level
|
||||
throw objectTypeStr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,6 @@
|
|||
|
||||
#include <EO.h>
|
||||
#include <eoOp.h>
|
||||
#include <eoInserter.h>
|
||||
#include <eoIndiSelector.h>
|
||||
#include <gp/parse_tree.h>
|
||||
#include <eoInit.h>
|
||||
|
||||
|
|
@ -154,47 +152,47 @@ private :
|
|||
};
|
||||
|
||||
template<class FType, class Node>
|
||||
class eoSubtreeXOver: public eoGeneralOp< eoParseTree<FType, Node> > {
|
||||
class eoSubtreeXOver: public eoQuadOp< eoParseTree<FType, Node> > {
|
||||
public:
|
||||
|
||||
typedef eoParseTree<FType, Node> EoType;
|
||||
|
||||
eoSubtreeXOver( unsigned _max_length)
|
||||
: eoGeneralOp<EoType>(), max_length(_max_length) {};
|
||||
: eoQuadOp<EoType>(), max_length(_max_length) {};
|
||||
|
||||
virtual string className() const { return "eoSubtreeXOver"; };
|
||||
|
||||
/// Dtor
|
||||
virtual ~eoSubtreeXOver () {};
|
||||
|
||||
void operator()(eoIndiSelector<EoType>& _select, eoInserter<EoType>& _insert )
|
||||
void operator()(EoType & _eo1, EoType & _eo2 )
|
||||
{
|
||||
EoType eo1 = _select();
|
||||
const EoType& eo2 = _select();
|
||||
int i = rng.random(_eo1.size());
|
||||
int j = rng.random(_eo2.size());
|
||||
|
||||
int i = rng.random(eo1.size());
|
||||
int j = rng.random(eo2.size());
|
||||
|
||||
eo1[i] = eo2[j]; // insert subtree
|
||||
parse_tree<Node>::subtree tmp = _eo2[j];
|
||||
_eo1[i] = _eo2[j]; // insert subtree
|
||||
_eo2[j]=tmp;
|
||||
|
||||
eo1.pruneTree(max_length);
|
||||
_eo1.pruneTree(max_length);
|
||||
_eo2.pruneTree(max_length);
|
||||
|
||||
eo1.invalidate();
|
||||
_insert(eo1);
|
||||
_eo1.invalidate();
|
||||
_eo2.invalidate();
|
||||
}
|
||||
|
||||
unsigned max_length;
|
||||
};
|
||||
|
||||
template<class FType, class Node>
|
||||
class eoBranchMutation: public eoGeneralOp< eoParseTree<FType, Node> >
|
||||
class eoBranchMutation: public eoMonOp< eoParseTree<FType, Node> >
|
||||
{
|
||||
public:
|
||||
|
||||
typedef eoParseTree<FType, Node> EoType;
|
||||
|
||||
eoBranchMutation(eoInit<EoType>& _init, unsigned _max_length)
|
||||
: eoGeneralOp<EoType>(), max_length(_max_length), initializer(_init)
|
||||
: eoMonOp<EoType>(), max_length(_max_length), initializer(_init)
|
||||
{};
|
||||
|
||||
virtual string className() const { return "eoBranchMutation"; };
|
||||
|
|
@ -202,22 +200,20 @@ public:
|
|||
/// Dtor
|
||||
virtual ~eoBranchMutation() {};
|
||||
|
||||
void operator()(eoIndiSelector<EoType>& _select, eoInserter<EoType>& _insert )
|
||||
void operator()(EoType& _eo1 )
|
||||
{
|
||||
EoType eo1 = _select();
|
||||
int i = rng.random(eo1.size());
|
||||
int i = rng.random(_eo1.size());
|
||||
|
||||
EoType eo2;
|
||||
initializer(eo2);
|
||||
|
||||
int j = rng.random(eo2.size());
|
||||
|
||||
eo1[i] = eo2[j]; // insert subtree
|
||||
_eo1[i] = eo2[j]; // insert subtree
|
||||
|
||||
eo1.pruneTree(max_length);
|
||||
_eo1.pruneTree(max_length);
|
||||
|
||||
eo1.invalidate();
|
||||
_insert(eo1);
|
||||
_eo1.invalidate();
|
||||
}
|
||||
|
||||
private :
|
||||
|
|
|
|||
|
|
@ -153,11 +153,11 @@ class eoExternalBinOp : public eoBinOp<ExternalEO>
|
|||
The function should return true when it changed something, false otherwise
|
||||
*/
|
||||
template <class F, class External, class ExternalEO = eoExternalEO<F, External> >
|
||||
class eoExternalQuadraticOp : public eoQuadraticOp<ExternalEO>
|
||||
class eoExternalQuadOp : public eoQuadOp<ExternalEO>
|
||||
{
|
||||
public :
|
||||
|
||||
eoExternalQuadraticOp(bool (*_quadop)(External&, External&)) : quadop(_quadop) {}
|
||||
eoExternalQuadOp(bool (*_quadop)(External&, External&)) : quadop(_quadop) {}
|
||||
|
||||
void operator()(ExternalEO& eo1, ExternalEO& eo2)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -197,7 +197,6 @@ void eoParser::printOn(ostream& os) const
|
|||
std::string section = p->first;
|
||||
|
||||
printSectionHeader(os, section);
|
||||
|
||||
//print every param with its value
|
||||
for (; p != params.end(); ++p)
|
||||
{
|
||||
|
|
|
|||
359
eo/test/t-eoGenOp.cpp
Normal file
359
eo/test/t-eoGenOp.cpp
Normal file
|
|
@ -0,0 +1,359 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoGenOp.h
|
||||
// (c) Maarten Keijzer and Marc Schoenauer, 2001
|
||||
/*
|
||||
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: mkeijzer@dhi.dk
|
||||
Marc.Schoenauer@polytechnique.fr
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/** test program for the general operator - millenium version!
|
||||
* uses dummy individuals
|
||||
*/
|
||||
#include <eo>
|
||||
#include <eoPopulator.h>
|
||||
#include <eoOpContainer.h>
|
||||
|
||||
struct Dummy : public EO<double>
|
||||
{
|
||||
typedef double Type;
|
||||
Dummy(std::string _s="") : s(_s) {}
|
||||
|
||||
void printOn(ostream & _os) const
|
||||
{
|
||||
EO<double>::printOn(_os);
|
||||
_os << " - " << s ;
|
||||
}
|
||||
|
||||
string s;
|
||||
};
|
||||
|
||||
typedef Dummy EOT;
|
||||
|
||||
unsigned int pSize; // global to be used as marker in the fitness
|
||||
|
||||
// DEFINITIONS of the eoOps
|
||||
class monop : public eoMonOp<EOT>
|
||||
{
|
||||
public :
|
||||
monop(char * _sig){sig=_sig;}
|
||||
void operator()(EOT& _eo)
|
||||
{
|
||||
_eo.s = sig + "(" + _eo.s + ")";
|
||||
_eo.fitness(_eo.fitness()+pSize);
|
||||
}
|
||||
string className() {return sig;}
|
||||
private:
|
||||
string sig;
|
||||
};
|
||||
|
||||
class binop: public eoBinOp<EOT>
|
||||
{
|
||||
public :
|
||||
void operator()(EOT& _eo1, const EOT& _eo2)
|
||||
{
|
||||
_eo1.s = "bin(" + _eo1.s + "," + _eo2.s + ")";
|
||||
double f= (_eo1.fitness()+_eo2.fitness()) * pSize;
|
||||
_eo1.fitness(_eo1.fitness()+f);
|
||||
}
|
||||
string className() {return "binop";}
|
||||
};
|
||||
|
||||
class quadop: public eoQuadOp<EOT>
|
||||
{
|
||||
public :
|
||||
string className() {return "quadop";}
|
||||
void operator()(EOT& a, EOT& b)
|
||||
{
|
||||
EOT oi = a;
|
||||
EOT oj = b;
|
||||
|
||||
a.s = "quad1(" + oi.s + "," + oj.s + ")";
|
||||
b.s = "quad2(" + oj.s + "," + oi.s + ")";
|
||||
double f= (a.fitness()+b.fitness()+2*pSize) * pSize;
|
||||
a.fitness(a.fitness()+f);
|
||||
b.fitness(b.fitness()+f);
|
||||
}
|
||||
};
|
||||
// an eoQuadOp that does nothing
|
||||
class quadClone: public eoQuadOp<EOT>
|
||||
{
|
||||
public :
|
||||
string className() {return "quadclone";}
|
||||
void operator()(EOT& , EOT& ) {}
|
||||
};
|
||||
|
||||
// User defined General Operator... adapted from Marc's example
|
||||
|
||||
class one2threeOp : public eoGenOp<EOT> // :-)
|
||||
{
|
||||
public:
|
||||
unsigned max_production(void) { return 3; }
|
||||
|
||||
void apply(eoPopulator<EOT>& _plop)
|
||||
{
|
||||
EOT& eo = *_plop; // select the guy
|
||||
++_plop; // advance
|
||||
|
||||
_plop.insert("v(" + eo.s + ", 1)");
|
||||
++_plop;
|
||||
_plop.insert("v(" + eo.s + ", 2)");
|
||||
eo.s = "v(" + eo.s + ", 0)"; // only now change the thing
|
||||
// oh right, and invalidate fitnesses
|
||||
}
|
||||
virtual string className() {return "one2threeOp";}
|
||||
};
|
||||
|
||||
|
||||
class two2oneOp : public eoGenOp<EOT> // :-)
|
||||
{
|
||||
public:
|
||||
unsigned max_production(void) { return 1; }
|
||||
|
||||
void apply(eoPopulator<EOT>& _plop)
|
||||
{
|
||||
EOT& eo = *_plop; // select the guy
|
||||
++_plop; // advance
|
||||
EOT& eo2 = *_plop;
|
||||
eo.s = "221(" + eo.s + ", " + eo2.s + ")";
|
||||
_plop.erase();
|
||||
// oh right, and invalidate fitnesses
|
||||
}
|
||||
virtual string className() {return "two2oneOp";}
|
||||
};
|
||||
|
||||
|
||||
// dummy intialization. Re-init if no pSize, resize first if pSize
|
||||
void init(eoPop<Dummy> & _pop, unsigned _pSize)
|
||||
{
|
||||
if (_pSize)
|
||||
{
|
||||
_pop.resize(_pSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw runtime_error("init pop with 0 size");
|
||||
}
|
||||
for (unsigned i=0; i<_pSize; i++)
|
||||
{
|
||||
char s[255];
|
||||
ostrstream os(s, 254);
|
||||
os << i << ends;
|
||||
_pop[i] = Dummy(s);
|
||||
_pop[i].fitness(i);
|
||||
}
|
||||
}
|
||||
|
||||
// ok, now for the real work
|
||||
int the_main(int argc, char **argv)
|
||||
{
|
||||
|
||||
eoParser parser(argc, argv);
|
||||
eoValueParam<unsigned int> parentSizeParam = parser.createParam<unsigned int>(10, "parentSize", "Parent size",'P');
|
||||
pSize = parentSizeParam.value(); // global variable
|
||||
|
||||
eoValueParam<uint32> seedParam(time(0), "seed", "Random number seed", 'S');
|
||||
parser.processParam( seedParam );
|
||||
eo::rng.reseed(seedParam.value());
|
||||
|
||||
// do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED
|
||||
// i.e. in case you need parameters somewhere else, postpone these
|
||||
if (parser.userNeedsHelp())
|
||||
{
|
||||
parser.printHelp(cout);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
////////////////////////////////// define operators
|
||||
monop mon("mon1");
|
||||
monop clone("clone");
|
||||
binop bin;
|
||||
quadop quad;
|
||||
quadClone quadclone;
|
||||
|
||||
// our own operator
|
||||
one2threeOp o2t;
|
||||
two2oneOp t2o;
|
||||
|
||||
|
||||
// a selector
|
||||
eoDetTournamentSelect<EOT> select;
|
||||
// and a recognizable selector for testing the inbedded selector mechanism
|
||||
eoBestSelect<EOT> selectBest;
|
||||
|
||||
// proportional selection between quad and bin
|
||||
// so we either do a quad or a bin
|
||||
eoProportionalOp<EOT> pOp;
|
||||
pOp.add(quad, 0.1);
|
||||
pOp.add(bin, 0.1);
|
||||
|
||||
// sequential selection between pOp and mon
|
||||
eoSequentialOp<EOT> sOp;
|
||||
sOp.add(pOp, 0.9);
|
||||
sOp.add(mon, 0.1);
|
||||
|
||||
// with one2three op
|
||||
eoSequentialOp<EOT> sOp2;
|
||||
sOp2.add(o2t, 1);
|
||||
sOp2.add(quad, 1);
|
||||
|
||||
eoSequentialOp<EOT> sOp3;
|
||||
// sOp3.add(t2o, 1);
|
||||
sOp3.add(bin, 1);
|
||||
sOp3.add(quad, 1);
|
||||
// try adding quads and bins to see what results you'll get
|
||||
|
||||
// now a sequential selection that is a simple "addition"
|
||||
eoSequentialOp<EOT> sOpQuadPlusMon;
|
||||
sOpQuadPlusMon.add(quad, 1);
|
||||
sOpQuadPlusMon.add(mon, 1);
|
||||
|
||||
// this corresponds
|
||||
eoProportionalOp<EOT> pOpSAGLike;
|
||||
pOpSAGLike.add(sOpQuadPlusMon, 0.24);
|
||||
pOpSAGLike.add(quad, 0.56);
|
||||
pOpSAGLike.add(mon, 0.06);
|
||||
pOpSAGLike.add(clone, 0.14);
|
||||
|
||||
// init
|
||||
eoPop<EOT> pop;
|
||||
|
||||
init(pop, pSize);
|
||||
// sort pop so seqPopulator is identical to SelectPopulator(SequentialSelect)
|
||||
pop.sort();
|
||||
cout << "Population initiale\n" << pop << endl;
|
||||
|
||||
// To simulate SGA: first a prop between quadOp and quadClone
|
||||
eoProportionalOp<EOT> pSGAOp;
|
||||
pSGAOp.add(bin, 0.8);
|
||||
pSGAOp.add(quadclone, 0.2);
|
||||
// sequential selection between pSGAOp and mon
|
||||
eoSequentialOp<EOT> virtualSGA;
|
||||
virtualSGA.add(pSGAOp, 1.0);
|
||||
virtualSGA.add(mon, 0.3);
|
||||
|
||||
eoSeqPopulator<EOT> popit(pop); // no selection, a copy of pop
|
||||
|
||||
// until we filled a new population
|
||||
try
|
||||
{
|
||||
while (popit.size() < pop.size())
|
||||
{
|
||||
virtualSGA(popit);
|
||||
}
|
||||
}
|
||||
catch(eoPopulator<EOT>::OutOfIndividuals&)
|
||||
{
|
||||
cout << "Warning: not enough individuals to handle\n";
|
||||
}
|
||||
|
||||
|
||||
swap(pop, popit);
|
||||
|
||||
// ok, now print
|
||||
cout << "Apres virtualSGA \n" << pop << endl;
|
||||
init(pop, pSize);
|
||||
|
||||
cout << "=========================================================\n";
|
||||
cout << "Now the eoSelectPopulator version !" << endl;
|
||||
|
||||
eoSequentialSelect<EOT> seqSelect;
|
||||
// select.init(); should be sorted out: is it the setup method???
|
||||
eoSelectivePopulator<EOT> it_step3(pop, seqSelect);
|
||||
|
||||
while (it_step3.size() < 2*pop.size())
|
||||
{
|
||||
virtualSGA(it_step3);
|
||||
}
|
||||
|
||||
swap(pop, it_step3);
|
||||
|
||||
// ok, now print
|
||||
cout << "Apres SGA-like eoSelectivePopulator\n" << pop << endl;
|
||||
|
||||
cout << "=========================================================\n";
|
||||
cout << "Now the pure addition !" << endl;
|
||||
|
||||
init(pop, pSize);
|
||||
eoSelectivePopulator<EOT> it_step4(pop, seqSelect);
|
||||
while (it_step4.size() < 2*pop.size())
|
||||
{
|
||||
sOpQuadPlusMon(it_step4);
|
||||
}
|
||||
|
||||
swap(pop, it_step4);
|
||||
|
||||
// ok, now print
|
||||
cout << "Apres Quad+Mon ds un eoSelectivePopulator\n" << pop << endl;
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
try
|
||||
{
|
||||
the_main(argc, argv);
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
cout << "Exception: " << e.what() << endl;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
If you want to build an SGA, you will need a copying quad op:
|
||||
|
||||
class quadclone : ...
|
||||
{
|
||||
operator(EOT& a, EOT& b)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Then the SGA operator will look like:
|
||||
|
||||
quadop quad;
|
||||
guadclone clone;
|
||||
|
||||
ProportionalGenOp pOp;
|
||||
pOp.add(quad, 0.8);
|
||||
pOp.add(clone, 0.2); // so 80% xover rate
|
||||
|
||||
SequentialGenOp sOp;
|
||||
sOp.add(pOp, 1,0); // always try a xover (clone 20%)
|
||||
sOp.add(mut, 0.1); // low mutation rate
|
||||
|
||||
will result in an algorithm with:
|
||||
|
||||
p_xover = 0.8
|
||||
p_mut = 0.1;
|
||||
|
||||
p_reproduction = 0.2 * 0.9 = 0.18
|
||||
|
||||
this does not add up to 1 because xover and mutation can be applied to a single indi
|
||||
|
||||
So what do you think?
|
||||
|
||||
*/
|
||||
|
|
@ -13,13 +13,12 @@
|
|||
// the general include for eo
|
||||
|
||||
#include <eo>
|
||||
#include <ga.h>
|
||||
|
||||
// REPRESENTATION
|
||||
//-----------------------------------------------------------------------------
|
||||
// Include the corresponding file
|
||||
#include <ga.h> // bitstring representation & operators
|
||||
// define your individuals
|
||||
typedef eoBin<double> Indi; // A bitstring with fitness double
|
||||
typedef eoBit<double> Indi; // A bitstring with fitness double
|
||||
|
||||
// EVAL
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -112,11 +111,11 @@ void main_function(int argc, char **argv)
|
|||
// The variation operators
|
||||
//////////////////////////////////////
|
||||
// CROSSOVER
|
||||
// 1-point mutation for bitstring
|
||||
eoBinCrossover<Indi> xover;
|
||||
// 1-point crossover for bitstring
|
||||
eo1PtBitXover<Indi> xover;
|
||||
// MUTATION
|
||||
// standard bit-flip mutation for bitstring
|
||||
eoBinMutation<Indi> mutation(P_MUT_PER_BIT);
|
||||
eoBitMutation<Indi> mutation(P_MUT_PER_BIT);
|
||||
|
||||
// STOP
|
||||
// CHECKPOINT
|
||||
|
|
|
|||
|
|
@ -13,11 +13,10 @@
|
|||
// the general include for eo
|
||||
|
||||
#include <eo>
|
||||
#include <es.h>
|
||||
|
||||
// REPRESENTATION
|
||||
//-----------------------------------------------------------------------------
|
||||
// Include the corresponding file
|
||||
#include <es.h> // real-representation & operators
|
||||
// define your individuals
|
||||
typedef eoReal<double> Indi;
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
// Include the corresponding file
|
||||
#include <ga.h> // bitstring representation & operators
|
||||
// define your individuals
|
||||
typedef eoBin<double> Indi; // A bitstring with fitness double
|
||||
typedef eoBit<double> Indi; // A bitstring with fitness double
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** a simple fitness function that computes the number of ones of a bitstring
|
||||
|
|
@ -120,9 +120,9 @@ void main_function(int argc, char **argv)
|
|||
// The variation operators
|
||||
//////////////////////////////////////
|
||||
// standard bit-flip mutation for bitstring
|
||||
eoBinMutation<Indi> mutation(P_MUT_PER_BIT);
|
||||
eoBitMutation<Indi> mutation(P_MUT_PER_BIT);
|
||||
// 1-point mutation for bitstring
|
||||
eoBinCrossover<Indi> xover;
|
||||
eo1PtBitXover<Indi> xover;
|
||||
|
||||
/////////////////////////////////////////
|
||||
// the algorithm
|
||||
|
|
|
|||
|
|
@ -13,13 +13,12 @@
|
|||
|
||||
// the general include for eo
|
||||
#include <eo>
|
||||
#include <ga.h>
|
||||
|
||||
// REPRESENTATION
|
||||
//-----------------------------------------------------------------------------
|
||||
// Include the corresponding file
|
||||
#include <ga.h> // bitstring representation & operators
|
||||
// define your individuals
|
||||
typedef eoBin<double> Indi; // A bitstring with fitness double
|
||||
typedef eoBit<double> Indi; // A bitstring with fitness double
|
||||
|
||||
// EVALFUNC
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -112,11 +111,11 @@ void main_function(int argc, char **argv)
|
|||
//////////////////////////////////////
|
||||
// CROSSOVER
|
||||
// 1-point crossover for bitstring
|
||||
eoBinCrossover<Indi> xover1;
|
||||
eo1PtBitXover<Indi> xover1;
|
||||
// uniform crossover for bitstring
|
||||
eoBinUxOver<Indi> xoverU;
|
||||
eoUBitXover<Indi> xoverU;
|
||||
// 2-pots xover
|
||||
eoBinNxOver<Indi> xover2(2);
|
||||
eoNPtsBitXover<Indi> xover2(2);
|
||||
// Combine them with relative rates
|
||||
eoPropCombinedQuadOp<Indi> xover(xover1, onePointRate);
|
||||
xover.add(xoverU, URate);
|
||||
|
|
@ -124,7 +123,7 @@ void main_function(int argc, char **argv)
|
|||
|
||||
// MUTATION
|
||||
// standard bit-flip mutation for bitstring
|
||||
eoBinMutation<Indi> mutationBitFlip(P_MUT_PER_BIT);
|
||||
eoBitMutation<Indi> mutationBitFlip(P_MUT_PER_BIT);
|
||||
// mutate exactly 1 bit per individual
|
||||
eoDetBitFlip<Indi> mutationOneBit;
|
||||
// Combine them with relative rates
|
||||
|
|
|
|||
|
|
@ -13,11 +13,10 @@
|
|||
|
||||
// the general include for eo
|
||||
#include <eo>
|
||||
#include <es.h>
|
||||
|
||||
// REPRESENTATION
|
||||
//-----------------------------------------------------------------------------
|
||||
// Include the corresponding file
|
||||
#include <es.h> // real-valued representation & operators
|
||||
// define your individuals
|
||||
typedef eoReal<double> Indi;
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
// Include the corresponding file
|
||||
#include <ga.h> // bitstring representation & operators
|
||||
// define your individuals
|
||||
typedef eoBin<double> Indi; // A bitstring with fitness double
|
||||
typedef eoBit<double> Indi; // A bitstring with fitness double
|
||||
|
||||
// EVAL
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -118,11 +118,11 @@ void main_function(int argc, char **argv)
|
|||
//////////////////////////////////////
|
||||
// CROSSOVER
|
||||
// 1-point crossover for bitstring
|
||||
eoBinCrossover<Indi> xover1;
|
||||
eo1PtBitXover<Indi> xover1;
|
||||
// uniform crossover for bitstring
|
||||
eoBinUxOver<Indi> xoverU;
|
||||
eoUBitXover<Indi> xoverU;
|
||||
// 2-pots xover
|
||||
eoBinNxOver<Indi> xover2(2);
|
||||
eoNPtsBitXover<Indi> xover2(2);
|
||||
// Combine them with relative rates
|
||||
eoPropCombinedQuadOp<Indi> xover(xover1, onePointRate);
|
||||
xover.add(xoverU, URate);
|
||||
|
|
@ -130,7 +130,7 @@ void main_function(int argc, char **argv)
|
|||
|
||||
// MUTATION
|
||||
// standard bit-flip mutation for bitstring
|
||||
eoBinMutation<Indi> mutationBitFlip(P_MUT_PER_BIT);
|
||||
eoBitMutation<Indi> mutationBitFlip(P_MUT_PER_BIT);
|
||||
// mutate exactly 1 bit per individual
|
||||
eoDetBitFlip<Indi> mutationOneBit;
|
||||
// Combine them with relative rates
|
||||
|
|
|
|||
|
|
@ -10,7 +10,11 @@ double real_value(const std::vector<double>& _ind)
|
|||
{
|
||||
double sum = 0;
|
||||
for (unsigned i = 0; i < _ind.size(); i++)
|
||||
sum += _ind[i] * _ind[i];
|
||||
{
|
||||
if ( (_ind[i]<0) || (_ind[i]>1) )
|
||||
cout << "Sorti des bornes: " << _ind[i] << " ";
|
||||
sum += _ind[i] * _ind[i];
|
||||
}
|
||||
return -sum;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,16 +14,15 @@
|
|||
|
||||
// the general include for eo
|
||||
#include <eo>
|
||||
#include <ga.h>
|
||||
|
||||
// EVAL
|
||||
#include "binary_value.h"
|
||||
|
||||
// REPRESENTATION
|
||||
//-----------------------------------------------------------------------------
|
||||
// Include the corresponding file
|
||||
#include <ga.h> // bitstring representation & operators
|
||||
// define your genotype and fitness types
|
||||
typedef eoBin<double> Indi;
|
||||
typedef eoBit<double> Indi;
|
||||
|
||||
// the main_function: nothing changed(!), except variable initialization
|
||||
void main_function(int argc, char **argv)
|
||||
|
|
@ -201,11 +200,11 @@ void main_function(int argc, char **argv)
|
|||
//////////////////////////////////////
|
||||
// CROSSOVER
|
||||
// 1-point crossover for bitstring
|
||||
eoBinCrossover<Indi> xover1;
|
||||
eo1PtBitXover<Indi> xover1;
|
||||
// uniform crossover for bitstring
|
||||
eoBinUxOver<Indi> xoverU;
|
||||
eoUBitXover<Indi> xoverU;
|
||||
// 2-pots xover
|
||||
eoBinNxOver<Indi> xover2(2);
|
||||
eoNPtsBitXover<Indi> xover2(2);
|
||||
// Combine them with relative rates
|
||||
eoPropCombinedQuadOp<Indi> xover(xover1, onePointRate);
|
||||
xover.add(xoverU, URate);
|
||||
|
|
@ -213,7 +212,7 @@ void main_function(int argc, char **argv)
|
|||
|
||||
// MUTATION
|
||||
// standard bit-flip mutation for bitstring
|
||||
eoBinMutation<Indi> mutationBitFlip(pMutPerBit);
|
||||
eoBitMutation<Indi> mutationBitFlip(pMutPerBit);
|
||||
// mutate exactly 1 bit per individual
|
||||
eoDetBitFlip<Indi> mutationOneBit;
|
||||
// Combine them with relative rates
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
// Include the corresponding file
|
||||
#include <ga.h> // bitstring representation & operators
|
||||
// define your genotype and fitness types
|
||||
typedef eoBin<eoMinimizingFitness> Indi;
|
||||
typedef eoBit<eoMinimizingFitness> Indi;
|
||||
|
||||
// the main_function: nothing changed(!), except variable initialization
|
||||
void main_function(int argc, char **argv)
|
||||
|
|
@ -210,11 +210,11 @@ void main_function(int argc, char **argv)
|
|||
//////////////////////////////////////
|
||||
// CROSSOVER
|
||||
// 1-point crossover for bitstring
|
||||
eoBinCrossover<Indi> xover1;
|
||||
eo1PtBitXover<Indi> xover1;
|
||||
// uniform crossover for bitstring
|
||||
eoBinUxOver<Indi> xoverU;
|
||||
eoUBitXover<Indi> xoverU;
|
||||
// 2-pots xover
|
||||
eoBinNxOver<Indi> xover2(2);
|
||||
eoNPtsBitXover<Indi> xover2(2);
|
||||
// Combine them with relative rates
|
||||
eoPropCombinedQuadOp<Indi> xover(xover1, onePointRate);
|
||||
xover.add(xoverU, URate);
|
||||
|
|
@ -222,7 +222,7 @@ void main_function(int argc, char **argv)
|
|||
|
||||
// MUTATION
|
||||
// standard bit-flip mutation for bitstring
|
||||
eoBinMutation<Indi> mutationBitFlip(pMutPerBit);
|
||||
eoBitMutation<Indi> mutationBitFlip(pMutPerBit);
|
||||
// mutate exactly 1 bit per individual
|
||||
eoDetBitFlip<Indi> mutationOneBit;
|
||||
// Combine them with relative rates
|
||||
|
|
@ -314,6 +314,9 @@ void main_function(int argc, char **argv)
|
|||
gnuMonitor.add(bestStat);
|
||||
gnuMonitor.add(averageStat);
|
||||
|
||||
// send a scaling command to gnuplot
|
||||
gnuMonitor.gnuplotCommand("set yrange [0:500]");
|
||||
|
||||
// a specific plot monitor for FDC
|
||||
// first into a file (it adds everything ti itself
|
||||
eoFDCFileSnapshot<Indi> fdcFileSnapshot(fdcStat);
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="Mozilla/4.75 [en] (X11; U; Linux 2.2.17-21mdk i686) [Netscape]">
|
||||
<meta name="GENERATOR" content="cpp2html Marc Schoenauer">
|
||||
<title>FirstBitEA.cpp</title>
|
||||
<!-- Changed by: Marc Schoenauer, 28-Nov-2000 -->
|
||||
<!-- Changed by: Marc Schoenauer, 28-Nov-2000 -->
|
||||
</head>
|
||||
<body text="#000000" bgcolor="#C3C2B4" link="#0000EE" vlink="#551A8B" alink="#FF0000">
|
||||
<a href="eoLesson2.html">Back to Lesson 2</a> - <a href="eoTutorial.html">Tutorial
|
||||
|
|
@ -16,319 +16,345 @@ documentation</a></font>
|
|||
<center>
|
||||
<h1>
|
||||
<font color="#FF0000">FirstBitEA.cpp</font></h1></center>
|
||||
Click on the figure to see the corresponding code.
|
||||
<br>In the code, the <a href="eoTutorial.html#colors">colors are meaningfull</a>
|
||||
<br>The actual code is in boldface and the comment in normal face.
|
||||
<br><img SRC="EA_tutorial.jpg" USEMAP="#Map" ><map NAME="Map"><!-- Init --><area SHAPE="rect" HREF="#init" COORDS="14,31,135,70"><area SHAPE="rect" HREF="#eval" COORDS="14,110,135,150"><!-- main loop --><area SHAPE="rect" HREF="#representation" COORDS="170,110,295,150"><area SHAPE="rect" HREF="#output" COORDS="280,45,480,70"><area SHAPE="rect" HREF="#stop" COORDS="348,110,430,150"><area SHAPE="rect" HREF="#select" COORDS="495,110,615,150"><area SHAPE="rect" HREF="#representation" COORDS="495,190,615,230"><area SHAPE="rect" HREF="#crossover" COORDS="495,265,625,287"><area SHAPE="rect" HREF="#mutation" COORDS="495,287,625,305"><area SHAPE="rect" HREF="#representation" COORDS="240,270,465,310"><area SHAPE="rect" HREF="#eval" COORDS="170,270,295,310"><area SHAPE="rect" HREF="#replace" COORDS="170,190,295,230"><!-- Center of loop --><area SHAPE="rect" HREF="#generation" COORDS="310,160,485,260"><!-- 4 bottom lines --><area SHAPE="rect" HREF="#operators" COORDS="15,350,260,370"><area SHAPE="rect" HREF="#representation" COORDS="270,350,460,370"><area SHAPE="rect" HREF="#engine" COORDS="15,377,400,397"><area SHAPE="rect" HREF="#eval" COORDS="15,403,230,423"><area SHAPE="rect" HREF="#checkpoint" COORDS="15,430,221,450"><area SHAPE="rect" HREF="#stop" COORDS="221,430,345,450"><area SHAPE="rect" HREF="#stat" COORDS="375,430,445,450"><area SHAPE="rect" HREF="#parametres" COORDS="0,358,278,378"></map>
|
||||
<br><a NAME="start"></a>
|
||||
Click on the figure to see the corresponding code.<br>
|
||||
In the code, the <a href="eoTutorial.html#colors">colors are meaningfull</a><br>
|
||||
The actual code is in boldface and the comment in normal face.
|
||||
<br><img SRC="EA_tutorial.jpg" USEMAP="#Map" >
|
||||
<map NAME="Map">
|
||||
<!-- Init -->
|
||||
<area SHAPE="rect" HREF="#init" COORDS="14,31,135,70">
|
||||
<area SHAPE="rect" HREF="#eval" COORDS="14,110,135,150">
|
||||
<!-- main loop -->
|
||||
<area SHAPE="rect" HREF="#representation" COORDS="170,110,295,150">
|
||||
<area SHAPE="rect" HREF="#output" COORDS="280,45,480,70">
|
||||
<area SHAPE="rect" HREF="#stop" COORDS="348,110,430,150">
|
||||
<area SHAPE="rect" HREF="#select" COORDS="495,110,615,150">
|
||||
<area SHAPE="rect" HREF="#representation" COORDS="495,190,615,230">
|
||||
<area SHAPE="rect" HREF="#crossover" COORDS="495,265,625,287">
|
||||
<area SHAPE="rect" HREF="#mutation" COORDS="495,287,625,305">
|
||||
<area SHAPE="rect" HREF="#representation" COORDS="240,270,465,310">
|
||||
<area SHAPE="rect" HREF="#eval" COORDS="170,270,295,310">
|
||||
<area SHAPE="rect" HREF="#replace" COORDS="170,190,295,230">
|
||||
<!-- Center of loop -->
|
||||
<area SHAPE="rect" HREF="#generation" COORDS="310,160,485,260">
|
||||
<!-- 4 bottom lines -->
|
||||
<area SHAPE="rect" HREF="#operators" COORDS="15,350,260,370">
|
||||
<area SHAPE="rect" HREF="#representation" COORDS="270,350,460,370">
|
||||
<area SHAPE="rect" HREF="#engine" COORDS="15,377,400,397">
|
||||
<area SHAPE="rect" HREF="#eval" COORDS="15,403,230,423">
|
||||
<area SHAPE="rect" HREF="#checkpoint" COORDS="15,430,221,450">
|
||||
<area SHAPE="rect" HREF="#stop" COORDS="221,430,345,450">
|
||||
<area SHAPE="rect" HREF="#stat" COORDS="375,430,445,450">
|
||||
<area SHAPE="rect" HREF="#parametres" COORDS="0,358,278,378">
|
||||
</map>
|
||||
<br>
|
||||
<A NAME="start"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr NOSAVE>
|
||||
<td NOSAVE><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#993300">// FirstBitEA.cpp</font></tt>
|
||||
<br><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#993300">//*</font></tt>
|
||||
<br><tt><font color="#993300">// Still an instance of a VERY simple Bitstring
|
||||
Genetic Algorithm </font></tt>
|
||||
<br><tt><font color="#993300">// (see FirstBitGA.cpp) but now with
|
||||
Breeder - and Combined Ops</font></tt>
|
||||
<br><tt><font color="#993300">//</font></tt>
|
||||
<br><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#993300">// standard includes</font></tt>
|
||||
<br><tt><font color="#993300"><b>#include <stdexcept> </b>// runtime_error </font></tt>
|
||||
<br><tt><font color="#993300"><b>#include <iostream>
|
||||
</b>// cout</font></tt>
|
||||
<br><tt><font color="#993300"><b>#include <strstream> </b>// ostrstream,
|
||||
istrstream</font></tt>
|
||||
<br><tt><font color="#993300">// the general include for eo</font></tt>
|
||||
<br><b><tt><font color="#993300">#include <eo></font></tt></b></td>
|
||||
<td NOSAVE><tt><font color="#993300">
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
// FirstBitEA.cpp<br>
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
//*<br>
|
||||
// Still an instance of a VERY simple Bitstring Genetic Algorithm <br>
|
||||
// (see FirstBitGA.cpp) but now with Breeder - and Combined Ops<br>
|
||||
//<br>
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
// standard includes<br>
|
||||
<b>#include <stdexcept> </b>// runtime_error <br>
|
||||
<b>#include <iostream> </b>// cout<br>
|
||||
<b>#include <strstream> </b>// ostrstream, istrstream<br>
|
||||
// the general include for eo<br>
|
||||
<b>#include <eo></b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="representation"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFFFCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#999900">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#999900">// Include the corresponding file </font></tt>
|
||||
<br><tt><font color="#999900"><b>#include <ga.h></b>
|
||||
// bitstring representation & operators </font></tt>
|
||||
<br><tt><font color="#999900">// define your individuals</font></tt>
|
||||
<br><tt><font color="#999900"><b>typedef eoBin<double> Indi; </b>//
|
||||
A bitstring with fitness double</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="evalfunc"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#CC0000">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#CC0000">// a simple fitness function that computes
|
||||
the number of ones of a bitstring</font></tt>
|
||||
<br><tt><font color="#CC0000">// Now in a separate file, and declared as
|
||||
binary_value(const vector<bool> &)</font></tt>
|
||||
<br><b><tt><font color="#CC0000">#include "binary_value.h"</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="general"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><b><tt><font color="#993300">void main_function(int argc, char **argv)</font></tt></b>
|
||||
<br><b><tt><font color="#993300">{</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="parametres"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#3366FF"><b> const unsigned int SEED = 42; </b>//
|
||||
seed for random number generator</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const unsigned int T_SIZE = 3; </b>//
|
||||
size for tournament selection</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const unsigned int VEC_SIZE = 8;
|
||||
</b>// Number of bits in genotypes</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const unsigned int POP_SIZE = 20;
|
||||
</b>// Size of population</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const unsigned int MAX_GEN = 500;
|
||||
</b>// Maximum number of generation before STOP</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const float CROSS_RATE = 0.8; </b>//
|
||||
Crossover rate</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const double P_MUT_PER_BIT = 0.01;
|
||||
</b>// probability of bit-flip mutation</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const float MUT_RATE = 1.0; </b>//
|
||||
mutation rate</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>// some parameters for chosing
|
||||
among different operators</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const double onePointRate = 0.5;
|
||||
</b>// rate for 1-pt Xover</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const double twoPointsRate = 0.5;
|
||||
</b>// rate for 2-pt Xover</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const double URate = 0.5;
|
||||
</b>// rate for Uniform Xover</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const double bitFlipRate = 0.5;
|
||||
</b>// rate for bit-flip mutation</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const double oneBitRate = 0.5;
|
||||
</b>// rate for one-bit mutation</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="general"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993300"><b> </b>//////////////////////////</font></tt>
|
||||
<br><tt><font color="#993300"><b> </b>// Random seed</font></tt>
|
||||
<br><tt><font color="#993300"><b> </b>//////////////////////////</font></tt>
|
||||
<br><tt><font color="#993300"><b> </b>//reproducible random seed:
|
||||
if you don't change SEED above, </font></tt>
|
||||
<br><tt><font color="#993300"><b> </b>// you'll aways get the same
|
||||
result, NOT a random run</font></tt>
|
||||
<br><b><tt><font color="#993300"> rng.reseed(SEED);</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="eval"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#CC0000"><b> </b>/////////////////////////////</font></tt>
|
||||
<br><tt><font color="#CC0000"><b> </b>// Fitness function</font></tt>
|
||||
<br><tt><font color="#CC0000"><b> </b>////////////////////////////</font></tt>
|
||||
<br><tt><font color="#CC0000"><b> </b>// Evaluation: from a plain
|
||||
C++ fn to an EvalFunc Object</font></tt>
|
||||
<br><tt><font color="#CC0000"><b> </b>// you need to give the full
|
||||
description of the function</font></tt>
|
||||
<br><b><tt><font color="#CC0000"> eoEvalFuncPtr<Indi, double, const
|
||||
vector<bool>& > eval( binary_value );</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="init"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993399"><b> </b>////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>// Initilisation of population</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>// based on boolean_generator
|
||||
class (see utils/rnd_generator.h)</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoInitFixedLength<Indi, boolean_generator> </font></tt></b>
|
||||
<br><b><tt><font color="#993399"> random(VEC_SIZE,
|
||||
boolean_generator());</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>// Initialization of the population</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoPop<Indi> pop(POP_SIZE, random);</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>// and evaluate it in one line</font></tt>
|
||||
<br><tt><font color="#993399"><b> apply<Indi>(eval, pop); </b>//
|
||||
STL syntax</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="output"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#3366FF"><b> </b>// sort pop before printing
|
||||
it!</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> pop.sort();</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b>// Print (sorted) intial population
|
||||
(raw printout)</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> cout << "Initial Population"
|
||||
<< endl;</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> cout << pop;</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="engine"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#009900"><b> </b>/////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#009900"><b> </b>// selection and replacement</font></tt>
|
||||
<br><tt><font color="#009900"><b> </b>////////////////////////////////////</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="select"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#009900"><b> </b>// The robust tournament selection</font></tt>
|
||||
<br><tt><font color="#009900"><b> eoDetTournamentSelect<Indi> selectOne(T_SIZE);
|
||||
</b>// T_SIZE in [2,POP_SIZE]</font></tt>
|
||||
<br><a NAME="select_encapsulate"></a><tt><font color="#009900"><b> </b>//
|
||||
is now encapsulated in a eoSelectPerc (entage)</font></tt>
|
||||
<br><tt><font color="#009900"><b> eoSelectPerc<Indi> select(selectOne);</b>//
|
||||
by default rate==1</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="replace"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#009900"><b> </b>// And we now have the full
|
||||
slection/replacement - though with </font></tt>
|
||||
<br><tt><font color="#009900"><b> </b>// no replacement (== generational
|
||||
replacement) at the moment :-)</font></tt>
|
||||
<br><b><tt><font color="#009900"> eoNoReplacement<Indi> replace; </font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="operators"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993399"><b> </b>//////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>// The variation operators</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>//////////////////////////////////////</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="crossover"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993399"><b> </b>// 1-point crossover for bitstring</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoBinCrossover<Indi> xover1;</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>// uniform crossover for bitstring</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoBinUxOver<Indi> xoverU;</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>// 2-pots xover</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoBinNxOver<Indi> xover2(2);</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>// Combine them with relative
|
||||
rates</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoPropCombinedQuadOp<Indi> xover(xover1,
|
||||
onePointRate);</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> xover.add(xoverU, URate);</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> xover.add(xover2, twoPointsRate,
|
||||
true);</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="mutation"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<a NAME="representation"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFFFCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<br><tt><font color="#993399"><b> </b>// standard bit-flip mutation
|
||||
for bitstring</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoBinMutation<Indi> mutationBitFlip(P_MUT_PER_BIT);</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>// mutate exactly 1 bit per
|
||||
individual</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoDetBitFlip<Indi> mutationOneBit; </font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>// Combine them with relative
|
||||
rates</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoPropCombinedMonOp<Indi> mutation(mutationBitFlip,
|
||||
bitFlipRate);</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> mutation.add(mutationOneBit, oneBitRate,
|
||||
true);</font></tt></b>
|
||||
<p><a NAME="transform"></a><tt><font color="#993399"><b> </b>// The operators
|
||||
are encapsulated into an eoTRansform object</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoSGATransform<Indi> transform(xover,
|
||||
CROSS_RATE, mutation, MUT_RATE);</font></tt></b></td>
|
||||
<tt><font color="#999900">
|
||||
<b>#include <ga.h></b><br>
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
// define your individuals<br>
|
||||
<b>typedef eoBit<double> Indi; </b>// A bitstring with fitness double<br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="stop"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<a NAME="evalfunc"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>
|
||||
<tt><font color="#CC0000">
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
// a simple fitness function that computes the number of ones of a bitstring<br>
|
||||
// Now in a separate file, and declared as binary_value(const vector<bool> &)<br>
|
||||
<b>#include "binary_value.h"</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="checkpoint"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<a NAME="general"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#3366FF"><b> </b>//////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>// termination conditions: use
|
||||
more than one</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>/////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>// stop after MAX_GEN generations</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> eoGenContinue<Indi> genCont(MAX_GEN);</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b>// do MIN_GEN gen., then stop
|
||||
after STEADY_GEN gen. without improvement</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> eoSteadyFitContinue<Indi> steadyCont(MIN_GEN,
|
||||
STEADY_GEN);</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b>// stop when fitness reaches
|
||||
a target (here VEC_SIZE)</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> eoFitContinue<Indi> fitCont(0);</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b>// do stop when one of the above
|
||||
says so</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> eoCombinedContinue<Indi> continuator(genCont);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> continuator.add(steadyCont);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> continuator.add(fitCont);</font></tt></b></td>
|
||||
<td>
|
||||
<tt><font color="#993300">
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
<b>void main_function(int argc, char **argv)</b><br>
|
||||
<b>{</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="generation"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<a NAME="parametres"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#FF6666"><b> </b>/////////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#FF6666"><b> </b>// the algorithm</font></tt>
|
||||
<br><tt><font color="#FF6666"><b> </b>////////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#FF6666"><b> </b>// Easy EA requires </font></tt>
|
||||
<br><tt><font color="#FF6666"><b> </b>// selection, transformation,
|
||||
eval, replacement, and stopping criterion</font></tt>
|
||||
<br><b><tt><font color="#FF6666"> eoEasyEA<Indi> gga(continuator,
|
||||
eval, select, transform, replace);</font></tt></b>
|
||||
<br><tt><font color="#FF6666"><b> </b>// Apply algo to pop - that's
|
||||
it!</font></tt>
|
||||
<br><b><tt><font color="#FF6666"> gga(pop);</font></tt></b>
|
||||
<br> </td>
|
||||
<td>
|
||||
<tt><font color="#3366FF">
|
||||
<b> const unsigned int SEED = 42; </b>// seed for random number generator<br>
|
||||
<b> const unsigned int T_SIZE = 3; </b>// size for tournament selection<br>
|
||||
<b> const unsigned int VEC_SIZE = 8; </b>// Number of bits in genotypes<br>
|
||||
<b> const unsigned int POP_SIZE = 20; </b>// Size of population<br>
|
||||
<b> const unsigned int MAX_GEN = 500; </b>// Maximum number of generation before STOP<br>
|
||||
<b> const float CROSS_RATE = 0.8; </b>// Crossover rate<br>
|
||||
<b> const double P_MUT_PER_BIT = 0.01; </b>// probability of bit-flip mutation<br>
|
||||
<b> const float MUT_RATE = 1.0; </b>// mutation rate<br>
|
||||
<b> </b>// some parameters for chosing among different operators<br>
|
||||
<b> const double onePointRate = 0.5; </b>// rate for 1-pt Xover<br>
|
||||
<b> const double twoPointsRate = 0.5; </b>// rate for 2-pt Xover<br>
|
||||
<b> const double URate = 0.5; </b>// rate for Uniform Xover<br>
|
||||
<b> const double bitFlipRate = 0.5; </b>// rate for bit-flip mutation<br>
|
||||
<b> const double oneBitRate = 0.5; </b>// rate for one-bit mutation<br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="output"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<a NAME="general"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#3366FF"><b> </b>// Print (sorted) intial population</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> pop.sort();</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> cout << "FINAL Population\n"
|
||||
<< pop << endl;</font></tt></b></td>
|
||||
<td>
|
||||
<tt><font color="#993300">
|
||||
<b> </b>//////////////////////////<br>
|
||||
<b> </b>// Random seed<br>
|
||||
<b> </b>//////////////////////////<br>
|
||||
<b> </b>//reproducible random seed: if you don't change SEED above, <br>
|
||||
<b> </b>// you'll aways get the same result, NOT a random run<br>
|
||||
<b> rng.reseed(SEED);</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="general"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<a NAME="eval"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#993300">}</font></tt></b>
|
||||
<br><tt><font color="#993300">// A main that catches the exceptions</font></tt>
|
||||
<br><b><tt><font color="#993300">int main(int argc, char **argv)</font></tt></b>
|
||||
<br><b><tt><font color="#993300">{</font></tt></b>
|
||||
<br><b><tt><font color="#993300">#ifdef _MSC_VER</font></tt></b>
|
||||
<br><tt><font color="#993300"><b> </b>// rng.reseed(42);</font></tt>
|
||||
<br><b><tt><font color="#993300"> int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> flag
|
||||
|= _CRTDBG_LEAK_CHECK_DF;</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> _CrtSetDbgFlag(flag);</font></tt></b>
|
||||
<br><tt><font color="#993300">// _CrtSetBreakAlloc(100);</font></tt>
|
||||
<br><b><tt><font color="#993300">#endif</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> try</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> {</font></tt></b>
|
||||
<br><b><tt><font color="#993300">
|
||||
main_function(argc, argv);</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> }</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> catch(exception&
|
||||
e)</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> {</font></tt></b>
|
||||
<br><b><tt><font color="#993300">
|
||||
cout << "Exception: " << e.what() << '\n';</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> }</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> return 1;</font></tt></b>
|
||||
<br><b><tt><font color="#993300">}</font></tt></b></td>
|
||||
<td>
|
||||
<tt><font color="#CC0000">
|
||||
<b> </b>/////////////////////////////<br>
|
||||
<b> </b>// Fitness function<br>
|
||||
<b> </b>////////////////////////////<br>
|
||||
<b> </b>// Evaluation: from a plain C++ fn to an EvalFunc Object<br>
|
||||
<b> </b>// you need to give the full description of the function<br>
|
||||
<b> eoEvalFuncPtr<Indi, double, const vector<bool>& > eval( binary_value );</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="init"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#993399">
|
||||
<b> </b>////////////////////////////////<br>
|
||||
<b> </b>// Initilisation of population<br>
|
||||
<b> </b>////////////////////////////////<br>
|
||||
<b> </b>// based on boolean_generator class (see utils/rnd_generator.h)<br>
|
||||
<b> eoInitFixedLength<Indi, boolean_generator> </b><br>
|
||||
<b> random(VEC_SIZE, boolean_generator());</b><br>
|
||||
<b> </b>// Initialization of the population<br>
|
||||
<b> eoPop<Indi> pop(POP_SIZE, random);</b><br>
|
||||
<b> </b>// and evaluate it in one line<br>
|
||||
<b> apply<Indi>(eval, pop); </b>// STL syntax<br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="output"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#3366FF">
|
||||
<b> </b>// sort pop before printing it!<br>
|
||||
<b> pop.sort();</b><br>
|
||||
<b> </b>// Print (sorted) intial population (raw printout)<br>
|
||||
<b> cout << "Initial Population" << endl;</b><br>
|
||||
<b> cout << pop;</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="engine"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#009900">
|
||||
<b> </b>/////////////////////////////////////<br>
|
||||
<b> </b>// selection and replacement<br>
|
||||
<b> </b>////////////////////////////////////<br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="select"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#009900">
|
||||
<b> </b>// The robust tournament selection<br>
|
||||
<b> eoDetTournamentSelect<Indi> selectOne(T_SIZE); </b>// T_SIZE in [2,POP_SIZE]<br>
|
||||
<a NAME="select_encapsulate"></a>
|
||||
<b> </b>// is now encapsulated in a eoSelectPerc (entage)<br>
|
||||
<b> eoSelectPerc<Indi> select(selectOne);</b>// by default rate==1<br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="replace"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#009900">
|
||||
<b> </b>// And we now have the full slection/replacement - though with <br>
|
||||
<b> </b>// no replacement (== generational replacement) at the moment :-)<br>
|
||||
<b> eoNoReplacement<Indi> replace; </b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="operators"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#993399">
|
||||
<b> </b>//////////////////////////////////////<br>
|
||||
<b> </b>// The variation operators<br>
|
||||
<b> </b>//////////////////////////////////////<br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="crossover"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#993399">
|
||||
<b> </b>// 1-point crossover for bitstring<br>
|
||||
<b> eo1PtBitXover<Indi> xover1;</b><br>
|
||||
<b> </b>// uniform crossover for bitstring<br>
|
||||
<b> eoUBitXover<Indi> xoverU;</b><br>
|
||||
<b> </b>// 2-pots xover<br>
|
||||
<b> eoNPtsBitXover<Indi> xover2(2);</b><br>
|
||||
<b> </b>// Combine them with relative rates<br>
|
||||
<b> eoPropCombinedQuadOp<Indi> xover(xover1, onePointRate);</b><br>
|
||||
<b> xover.add(xoverU, URate);</b><br>
|
||||
<b> xover.add(xover2, twoPointsRate, true);</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="mutation"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#993399">
|
||||
<b> </b><br>
|
||||
<b> </b>// standard bit-flip mutation for bitstring<br>
|
||||
<b> eoBitMutation<Indi> mutationBitFlip(P_MUT_PER_BIT);</b><br>
|
||||
<b> </b>// mutate exactly 1 bit per individual<br>
|
||||
<b> eoDetBitFlip<Indi> mutationOneBit; </b><br>
|
||||
<b> </b>// Combine them with relative rates<br>
|
||||
<b> eoPropCombinedMonOp<Indi> mutation(mutationBitFlip, bitFlipRate);</b><br>
|
||||
<b> mutation.add(mutationOneBit, oneBitRate, true);</b><br>
|
||||
<b> </b><br>
|
||||
<a NAME="transform"></a>
|
||||
<b> </b>// The operators are encapsulated into an eoTRansform object<br>
|
||||
<b> eoSGATransform<Indi> transform(xover, CROSS_RATE, mutation, MUT_RATE);</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="stop"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#3366FF">
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="checkpoint"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#3366FF">
|
||||
<b> </b>//////////////////////////////////////<br>
|
||||
<b> </b>// termination conditions: use more than one<br>
|
||||
<b> </b>/////////////////////////////////////<br>
|
||||
<b> </b>// stop after MAX_GEN generations<br>
|
||||
<b> eoGenContinue<Indi> genCont(MAX_GEN);</b><br>
|
||||
<b> </b>// do MIN_GEN gen., then stop after STEADY_GEN gen. without improvement<br>
|
||||
<b> eoSteadyFitContinue<Indi> steadyCont(MIN_GEN, STEADY_GEN);</b><br>
|
||||
<b> </b>// stop when fitness reaches a target (here VEC_SIZE)<br>
|
||||
<b> eoFitContinue<Indi> fitCont(0);</b><br>
|
||||
<b> </b>// do stop when one of the above says so<br>
|
||||
<b> eoCombinedContinue<Indi> continuator(genCont);</b><br>
|
||||
<b> continuator.add(steadyCont);</b><br>
|
||||
<b> continuator.add(fitCont);</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="generation"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#FF6666">
|
||||
<b> </b>/////////////////////////////////////////<br>
|
||||
<b> </b>// the algorithm<br>
|
||||
<b> </b>////////////////////////////////////////<br>
|
||||
<b> </b>// Easy EA requires <br>
|
||||
<b> </b>// selection, transformation, eval, replacement, and stopping criterion<br>
|
||||
<b> eoEasyEA<Indi> gga(continuator, eval, select, transform, replace);</b><br>
|
||||
<b> </b>// Apply algo to pop - that's it!<br>
|
||||
<b> gga(pop);</b><br>
|
||||
<b> </b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="output"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#3366FF">
|
||||
<b> </b>// Print (sorted) intial population<br>
|
||||
<b> pop.sort();</b><br>
|
||||
<b> cout << "FINAL Population\n" << pop << endl;</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="general"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#993300">
|
||||
<b>}</b><br>
|
||||
// A main that catches the exceptions<br>
|
||||
<b>int main(int argc, char **argv)</b><br>
|
||||
<b>{</b><br>
|
||||
<b>#ifdef _MSC_VER</b><br>
|
||||
<b> </b>// rng.reseed(42);<br>
|
||||
<b> int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);</b><br>
|
||||
<b> flag |= _CRTDBG_LEAK_CHECK_DF;</b><br>
|
||||
<b> _CrtSetDbgFlag(flag);</b><br>
|
||||
// _CrtSetBreakAlloc(100);<br>
|
||||
<b>#endif</b><br>
|
||||
<b> try</b><br>
|
||||
<b> {</b><br>
|
||||
<b> main_function(argc, argv);</b><br>
|
||||
<b> }</b><br>
|
||||
<b> catch(exception& e)</b><br>
|
||||
<b> {</b><br>
|
||||
<b> cout << "Exception: " << e.what() << '\n';</b><br>
|
||||
<b> }</b><br>
|
||||
<b> return 1;</b><br>
|
||||
<b>}</b><br>
|
||||
</font></font></font></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<hr WIDTH="100%"><a href="eoLesson2.html">Back to Lesson 2</a> - <a href="eoTutorial.html">Tutorial
|
||||
main page </a>- <a href="eoTopDown.html">Algorithm-Based</a> - <a href="eoBottomUp.html">Component-Based
|
||||
page</a> - <a href="eoProgramming.html">Programming hints</a> - <font face="Arial,Helvetica"><a href="../../doc/html/index.html">EO
|
||||
|
|
@ -336,8 +362,8 @@ documentation</a></font>
|
|||
<hr>
|
||||
<address>
|
||||
<a href="mailto:marc.schoenauer@polytechnique.fr">Marc Schoenauer</a></address>
|
||||
|
||||
<br><!-- Created: Nov 2000 --><!-- hhmts start -->Last modified: Sun Nov
|
||||
19 22:26:27 2000<!-- hhmts end -->
|
||||
<br><!-- Created: Nov 2000 --><!-- hhmts start -->Last
|
||||
modified: Sun Nov 19 22:26:27 2000
|
||||
<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="Mozilla/4.75 [en] (X11; U; Linux 2.2.17-21mdk i686) [Netscape]">
|
||||
<meta name="GENERATOR" content="Mozilla/4.76 [en] (X11; U; Linux 2.2.17-21mdksmp i686) [Netscape]">
|
||||
<title>FirstBitGA.html</title>
|
||||
<!-- Changed by: Marc Schoenauer, 29-Nov-2000 -->
|
||||
</head>
|
||||
|
|
@ -15,7 +15,7 @@ documentation</a></font>
|
|||
<hr WIDTH="100%"><!-- -------------- End of header ------------------ --><!-- ----------------------------------------------- -->
|
||||
<center>
|
||||
<h1>
|
||||
<font color="#FF0000">FirstBitGA.html</font></h1></center>
|
||||
<font color="#FF0000">Code for FirstBitGA</font></h1></center>
|
||||
Click on the figure to see the corresponding code.
|
||||
<br>In the code, the <a href="eoTutorial.html#colors">colors are meaningfull</a>
|
||||
<br>The actual code is in boldface and the comment in normal face.
|
||||
|
|
@ -44,12 +44,10 @@ istrstream</font></tt>
|
|||
<a NAME="representation"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFFFCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#999900">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#999900">// Include the corresponding file</font></tt>
|
||||
<br><tt><font color="#999900"><b>#include <ga.h></b>
|
||||
// bitstring representation & operators</font></tt>
|
||||
<td><b><tt><font color="#999900">#include <ga.h></font></tt></b><br>
|
||||
<tt><font color="#999900">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#999900">// define your individuals</font></tt>
|
||||
<br><tt><font color="#999900"><b>typedef eoBin<double> Indi;
|
||||
<br><tt><font color="#999900"><b>typedef eoBit<double> Indi;
|
||||
</b>// A bitstring with fitness double</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
|
@ -216,8 +214,8 @@ is needed</font></tt></td>
|
|||
<a NAME="crossover"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993399"><b> </b>// 1-point mutation for bitstring</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoBinCrossover<Indi> xover;</font></tt></b></td>
|
||||
<td><tt><font color="#993399"><b> </b>// 1-point crossover for bitstring</font></tt>
|
||||
<br><b><tt><font color="#993399"> eo1PtBitXover<Indi> xover;</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="mutation"></a>
|
||||
|
|
@ -226,10 +224,10 @@ is needed</font></tt></td>
|
|||
<td>
|
||||
<br><tt><font color="#993399"><b> </b>// standard bit-flip mutation
|
||||
for bitstring</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoBinMutation<Indi> mutation(P_MUT_PER_BIT);</font></tt></b></td>
|
||||
<br><b><tt><font color="#993399"> eoBitMutation<Indi> mutation(P_MUT_PER_BIT);</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="checkpoint"></a>
|
||||
<a NAME="stop"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#3366FF"><b> </b>//////////////////////////////////////</font></tt>
|
||||
|
|
|
|||
|
|
@ -34,9 +34,8 @@ Breeder - and Combined Ops</font></tt>
|
|||
<br><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#993300">// standard includes</font></tt>
|
||||
<br><tt><font color="#993300"><b>#include <stdexcept> </b>// runtime_error </font></tt>
|
||||
<br><tt><font color="#993300"><b>#include <iostream>
|
||||
</b>//
|
||||
cout</font></tt>
|
||||
<br><tt><font color="#993300"><b>#include <iostream>
|
||||
</b>// cout</font></tt>
|
||||
<br><tt><font color="#993300"><b>#include <strstream> </b>// ostrstream,
|
||||
istrstream</font></tt>
|
||||
<br><tt><font color="#993300">// the general include for eo</font></tt>
|
||||
|
|
@ -46,10 +45,8 @@ istrstream</font></tt>
|
|||
<a NAME="representation"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFFFCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#999900">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#999900">// Include the corresponding file </font></tt>
|
||||
<br><tt><font color="#999900"><b>#include <es.h></b>
|
||||
// real-representation & operators </font></tt>
|
||||
<td><tt><font color="#999900"><b>#include <es.h></b></font></tt><br>
|
||||
<tt><font color="#999900">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#999900">// define your individuals</font></tt>
|
||||
<br><b><tt><font color="#999900">typedef eoReal<double> Indi; </font></tt></b></td>
|
||||
</tr>
|
||||
|
|
@ -81,16 +78,12 @@ seed for random number generator</font></tt>
|
|||
<br><tt><font color="#3366FF"><b> const unsigned int T_SIZE = 3; </b>//
|
||||
size for tournament selection</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const unsigned int VEC_SIZE = 8;
|
||||
</b>//
|
||||
Number of object variables in genotypes</font></tt>
|
||||
</b>// Number of object variables in genotypes</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const unsigned int POP_SIZE = 20;
|
||||
</b>//
|
||||
Size of population</font></tt>
|
||||
</b>// Size of population</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const unsigned int MAX_GEN = 500;
|
||||
</b>//
|
||||
Maximum number of generation before STOP</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const unsigned int MIN_GEN = 10;
|
||||
|
||||
</b>// Maximum number of generation before STOP</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const unsigned int MIN_GEN = 10;
|
||||
</b>// Minimum number of generation before ...</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const unsigned int STEADY_GEN =
|
||||
50; </b>// stop after STEADY_GEN gen. without improvelent</font></tt>
|
||||
|
|
@ -105,17 +98,13 @@ SIGMA = 0.3; </b> // std dev.
|
|||
for normal mutation</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>// some parameters for chosing
|
||||
among different operators</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const double segmentRate = 0.5;
|
||||
|
||||
<br><tt><font color="#3366FF"><b> const double segmentRate = 0.5;
|
||||
</b>// relative weight for 1-pt Xover</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const double arithmeticRate = 0.5;
|
||||
</b>//
|
||||
relative weight for 2-pt Xover</font></tt>
|
||||
</b>// relative weight for 2-pt Xover</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const double uniformMutRate = 0.5;
|
||||
</b>//
|
||||
relative weight for bit-flip mutation</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const double detMutRate = 0.5;
|
||||
|
||||
</b>// relative weight for bit-flip mutation</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const double detMutRate = 0.5;
|
||||
</b>// relative weight for one-bit mutation</font></tt>
|
||||
<br><tt><font color="#3366FF"> <b>const double normalMutRate = 0.5;</b>
|
||||
// relative weight for normal mutation</font></tt></td>
|
||||
|
|
@ -193,8 +182,8 @@ it!</font></tt>
|
|||
<tr>
|
||||
<td><tt><font color="#009900"><b> </b>// The robust tournament selection</font></tt>
|
||||
<br><b><tt><font color="#009900"> eoDetTournamentSelect<Indi> selectOne(T_SIZE);</font></tt></b>
|
||||
<br><a NAME="select_encapsulate"></a><tt><font color="#009900">// is now
|
||||
encapsulated in a eoSelectPerc (entage)</font></tt>
|
||||
<br><a NAME="select_encapsulate"></a><tt><font color="#009900"><b> </b>//
|
||||
is now encapsulated in a eoSelectPerc (entage)</font></tt>
|
||||
<br><tt><font color="#009900"><b> eoSelectPerc<Indi> select(selectOne);</b>//
|
||||
by default rate==1</font></tt></td>
|
||||
</tr>
|
||||
|
|
@ -307,7 +296,8 @@ eval, select, transform, replace);</font></tt></b>
|
|||
it!</font></tt>
|
||||
<br><b><tt><font color="#FF6666"> cout << "\n
|
||||
Here we go\n\n";</font></tt></b>
|
||||
<br><b><tt><font color="#FF6666"> gga(pop);</font></tt></b></td>
|
||||
<br><b><tt><font color="#FF6666"> gga(pop);</font></tt></b>
|
||||
<br> </td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="output"></a>
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="Mozilla/4.75 [en] (X11; U; Linux 2.2.17-21mdk i686) [Netscape]">
|
||||
<title>../FirstRealGA.html</title>
|
||||
<!-- Changed by: Marc Schoenauer, 29-Nov-2000 -->
|
||||
<meta name="GENERATOR" content="cpp2html Marc Schoenauer">
|
||||
<title>FirstRealGA.html</title>
|
||||
<!-- Changed by: Marc Schoenauer, 29-Nov-2000 -->
|
||||
</head>
|
||||
<body text="#000000" bgcolor="#C3C2B4" link="#0000EE" vlink="#551A8B" alink="#FF0000">
|
||||
<a href="eoLesson1.html">Back to Lesson 1</a> - <a href="eoTutorial.html">Tutorial
|
||||
|
|
@ -15,294 +15,327 @@ documentation</a></font>
|
|||
<hr WIDTH="100%"><!-- -------------- End of header ------------------ --><!-- ----------------------------------------------- -->
|
||||
<center>
|
||||
<h1>
|
||||
<font color="#FF0000">../FirstRealGA.html</font></h1></center>
|
||||
Click on the figure to see the corresponding code.
|
||||
<br>In the code, the <a href="eoTutorial.html#colors">colors are meaningfull</a>
|
||||
<br>The actual code is in boldface and the comment in normal face.
|
||||
<br><img SRC="EA_tutorial.jpg" USEMAP="#Map" ><map NAME="Map"><!-- Init --><area SHAPE="rect" HREF="#init" COORDS="14,31,135,70"><area SHAPE="rect" HREF="#eval" COORDS="14,110,135,150"><!-- main loop --><area SHAPE="rect" HREF="#representation" COORDS="170,110,295,150"><area SHAPE="rect" HREF="#output" COORDS="280,45,480,70"><area SHAPE="rect" HREF="#stop" COORDS="348,110,430,150"><area SHAPE="rect" HREF="#select" COORDS="495,110,615,150"><area SHAPE="rect" HREF="#representation" COORDS="495,190,615,230"><area SHAPE="rect" HREF="#crossover" COORDS="495,265,625,287"><area SHAPE="rect" HREF="#mutation" COORDS="495,287,625,305"><area SHAPE="rect" HREF="#representation" COORDS="240,270,465,310"><area SHAPE="rect" HREF="#eval" COORDS="170,270,295,310"><area SHAPE="rect" HREF="#replace" COORDS="170,190,295,230"><!-- Center of loop --><area SHAPE="rect" HREF="#generation" COORDS="310,160,485,260"><!-- 4 bottom lines --><area SHAPE="rect" HREF="#operators" COORDS="15,350,260,370"><area SHAPE="rect" HREF="#representation" COORDS="270,350,460,370"><area SHAPE="rect" HREF="#engine" COORDS="15,377,400,397"><area SHAPE="rect" HREF="#eval" COORDS="15,403,230,423"><area SHAPE="rect" HREF="#checkpoint" COORDS="15,430,221,450"><area SHAPE="rect" HREF="#stop" COORDS="221,430,345,450"><area SHAPE="rect" HREF="#stat" COORDS="375,430,445,450"><area SHAPE="rect" HREF="#parametres" COORDS="0,358,278,378"></map>
|
||||
<br><a NAME="start"></a>
|
||||
<font color="#FF0000">Code for FirstRealGA</font></h1></center>
|
||||
Click on the figure to see the corresponding code.<br>
|
||||
In the code, the <a href="eoTutorial.html#colors">colors are meaningfull</a><br>
|
||||
The actual code is in boldface and the comment in normal face.
|
||||
<br><img SRC="EA_tutorial.jpg" USEMAP="#Map" >
|
||||
<map NAME="Map">
|
||||
<!-- Init -->
|
||||
<area SHAPE="rect" HREF="#init" COORDS="14,31,135,70">
|
||||
<area SHAPE="rect" HREF="#eval" COORDS="14,110,135,150">
|
||||
<!-- main loop -->
|
||||
<area SHAPE="rect" HREF="#representation" COORDS="170,110,295,150">
|
||||
<area SHAPE="rect" HREF="#output" COORDS="280,45,480,70">
|
||||
<area SHAPE="rect" HREF="#stop" COORDS="348,110,430,150">
|
||||
<area SHAPE="rect" HREF="#select" COORDS="495,110,615,150">
|
||||
<area SHAPE="rect" HREF="#representation" COORDS="495,190,615,230">
|
||||
<area SHAPE="rect" HREF="#crossover" COORDS="495,265,625,287">
|
||||
<area SHAPE="rect" HREF="#mutation" COORDS="495,287,625,305">
|
||||
<area SHAPE="rect" HREF="#representation" COORDS="240,270,465,310">
|
||||
<area SHAPE="rect" HREF="#eval" COORDS="170,270,295,310">
|
||||
<area SHAPE="rect" HREF="#replace" COORDS="170,190,295,230">
|
||||
<!-- Center of loop -->
|
||||
<area SHAPE="rect" HREF="#generation" COORDS="310,160,485,260">
|
||||
<!-- 4 bottom lines -->
|
||||
<area SHAPE="rect" HREF="#operators" COORDS="15,350,260,370">
|
||||
<area SHAPE="rect" HREF="#representation" COORDS="270,350,460,370">
|
||||
<area SHAPE="rect" HREF="#engine" COORDS="15,377,400,397">
|
||||
<area SHAPE="rect" HREF="#eval" COORDS="15,403,230,423">
|
||||
<area SHAPE="rect" HREF="#checkpoint" COORDS="15,430,221,450">
|
||||
<area SHAPE="rect" HREF="#stop" COORDS="221,430,345,450">
|
||||
<area SHAPE="rect" HREF="#stat" COORDS="375,430,445,450">
|
||||
<area SHAPE="rect" HREF="#parametres" COORDS="0,358,278,378">
|
||||
</map>
|
||||
<br>
|
||||
<A NAME="start"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr NOSAVE>
|
||||
<td NOSAVE><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#993300">// FirstRealGA.cpp</font></tt>
|
||||
<br><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#993300">//*</font></tt>
|
||||
<br><tt><font color="#993300">// An instance of a VERY simple Real-coded
|
||||
Genetic Algorithm</font></tt>
|
||||
<br><tt><font color="#993300">//</font></tt>
|
||||
<br><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#993300">// standard includes</font></tt>
|
||||
<br><tt><font color="#993300"><b>#include <stdexcept> </b>// runtime_error </font></tt>
|
||||
<br><tt><font color="#993300"><b>#include <iostream>
|
||||
</b>// cout</font></tt>
|
||||
<br><tt><font color="#993300"><b>#include <strstream> </b>// ostrstream,
|
||||
istrstream</font></tt>
|
||||
<br><tt><font color="#993300">// the general include for eo</font></tt>
|
||||
<br><b><tt><font color="#993300">#include <eo></font></tt></b></td>
|
||||
<td NOSAVE><tt><font color="#993300">
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
// FirstRealGA.cpp<br>
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
//*<br>
|
||||
// An instance of a VERY simple Real-coded Genetic Algorithm<br>
|
||||
//<br>
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
// standard includes<br>
|
||||
<b>#include <stdexcept> </b>// runtime_error <br>
|
||||
<b>#include <iostream> </b>// cout<br>
|
||||
<b>#include <strstream> </b>// ostrstream, istrstream<br>
|
||||
// the general include for eo<br>
|
||||
<b>#include <eo></b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="representation"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFFFCC" NOSAVE >
|
||||
<a NAME="representation"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFFFCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#999900">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#999900">// Include the corresponding file</font></tt>
|
||||
<br><tt><font color="#999900"><b>#include <es.h></b>
|
||||
// real-representation & operators</font></tt>
|
||||
<br><tt><font color="#999900">// define your individuals</font></tt>
|
||||
<br><b><tt><font color="#999900">typedef eoReal<double> Indi;</font></tt></b></td>
|
||||
<td>
|
||||
<tt><font color="#999900">
|
||||
<b>#include <es.h></b><br>
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
// define your individuals<br>
|
||||
<b> typedef eoReal<double> Indi;</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#CC0000">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#CC0000">// a simple fitness function that computes
|
||||
the euclidian norm of a real vector</font></tt>
|
||||
<br><tt><font color="#CC0000">// @param _indi
|
||||
A real-valued individual </font></tt>
|
||||
<br><a NAME="evalfunc"></a><b><tt><font color="#CC0000">double real_value(const
|
||||
Indi & _indi)</font></tt></b>
|
||||
<br><b><tt><font color="#CC0000">{</font></tt></b>
|
||||
<br><b><tt><font color="#CC0000"> double sum = 0;</font></tt></b>
|
||||
<br><b><tt><font color="#CC0000"> for (unsigned i = 0; i < _indi.size();
|
||||
i++)</font></tt></b>
|
||||
<br><b><tt><font color="#CC0000">
|
||||
sum += _indi[i]*_indi[i];</font></tt></b>
|
||||
<br><tt><font color="#CC0000"><b> return (-sum);
|
||||
</b>// maximizing only</font></tt>
|
||||
<br><b><tt><font color="#CC0000">}</font></tt></b></td>
|
||||
<td>
|
||||
<tt><font color="#CC0000">
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
// a simple fitness function that computes the euclidian norm of a real vector<br>
|
||||
// @param _indi A real-valued individual <br>
|
||||
<a name="evalfunc"></a>
|
||||
<b>double real_value(const Indi & _indi)</b><br>
|
||||
<b>{</b><br>
|
||||
<b> double sum = 0;</b><br>
|
||||
<b> for (unsigned i = 0; i < _indi.size(); i++)</b><br>
|
||||
<b> sum += _indi[i]*_indi[i];</b><br>
|
||||
<b> return (-sum); </b>// maximizing only<br>
|
||||
<b>}</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="general"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<a NAME="general"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><b><tt><font color="#993300">void main_function(int argc, char **argv)</font></tt></b>
|
||||
<br><b><tt><font color="#993300">{</font></tt></b></td>
|
||||
<td>
|
||||
<tt><font color="#993300">
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
<b>void main_function(int argc, char **argv)</b><br>
|
||||
<b>{</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="parametres"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<a NAME="parametres"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#3366FF"><b> </b>// all parameters are hard-coded!</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const unsigned int SEED = 42; </b>//
|
||||
seed for random number generator</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const unsigned int VEC_SIZE = 8;
|
||||
</b>// Number of object variables in genotypes</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const unsigned int POP_SIZE = 20;
|
||||
</b>// Size of population</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const unsigned int T_SIZE = 3; </b>//
|
||||
size for tournament selection</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const unsigned int MAX_GEN = 500;
|
||||
</b>// Maximum number of generation before STOP</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const float CROSS_RATE = 0.8; </b>//
|
||||
Crossover rate</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const double EPSILON = 0.01;
|
||||
</b>// range for real uniform mutation</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const float MUT_RATE = 0.5;
|
||||
</b>// mutation rate</font></tt></td>
|
||||
<td>
|
||||
<tt><font color="#3366FF">
|
||||
<b> </b>// all parameters are hard-coded!<br>
|
||||
<b> const unsigned int SEED = 42; </b>// seed for random number generator<br>
|
||||
<b> const unsigned int VEC_SIZE = 8; </b>// Number of object variables in genotypes<br>
|
||||
<b> const unsigned int POP_SIZE = 20; </b>// Size of population<br>
|
||||
<b> const unsigned int T_SIZE = 3; </b>// size for tournament selection<br>
|
||||
<b> const unsigned int MAX_GEN = 500; </b>// Maximum number of generation before STOP<br>
|
||||
<b> const float CROSS_RATE = 0.8; </b>// Crossover rate<br>
|
||||
<b> const double EPSILON = 0.01; </b>// range for real uniform mutation<br>
|
||||
<b> const float MUT_RATE = 0.5; </b>// mutation rate<br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="general"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<a NAME="general"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td><a NAME="random"></a><tt><font color="#993300"><b> </b>//////////////////////////</font></tt>
|
||||
<br><tt><font color="#993300"><b> </b>// Random seed</font></tt>
|
||||
<br><tt><font color="#993300"><b> </b>//////////////////////////</font></tt>
|
||||
<br><tt><font color="#993300"><b> </b>//reproducible random seed:
|
||||
if you don't change SEED above, </font></tt>
|
||||
<br><tt><font color="#993300"><b> </b>// you'll aways get the same
|
||||
result, NOT a random run</font></tt>
|
||||
<br><b><tt><font color="#993300"> rng.reseed(SEED);</font></tt></b></td>
|
||||
<td>
|
||||
<tt><font color="#993300">
|
||||
<a NAME="random"></a>
|
||||
<b> </b>//////////////////////////<br>
|
||||
<b> </b>// Random seed<br>
|
||||
<b> </b>//////////////////////////<br>
|
||||
<b> </b>//reproducible random seed: if you don't change SEED above, <br>
|
||||
<b> </b>// you'll aways get the same result, NOT a random run<br>
|
||||
<b> rng.reseed(SEED);</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="eval"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<a NAME="eval"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#CC0000"><b> </b>/////////////////////////////</font></tt>
|
||||
<br><tt><font color="#CC0000"><b> </b>// Fitness function</font></tt>
|
||||
<br><tt><font color="#CC0000"><b> </b>////////////////////////////</font></tt>
|
||||
<br><tt><font color="#CC0000"><b> </b>// Evaluation: from a plain
|
||||
C++ fn to an EvalFunc Object</font></tt>
|
||||
<br><b><tt><font color="#CC0000"> eoEvalFuncPtr<Indi> eval(
|
||||
real_value );</font></tt></b></td>
|
||||
<td>
|
||||
<tt><font color="#CC0000">
|
||||
<b> </b>/////////////////////////////<br>
|
||||
<b> </b>// Fitness function<br>
|
||||
<b> </b>////////////////////////////<br>
|
||||
<b> </b>// Evaluation: from a plain C++ fn to an EvalFunc Object<br>
|
||||
<b> eoEvalFuncPtr<Indi> eval( real_value );</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="init"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<a NAME="init"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993399"><b> </b>////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>// Initilisation of population</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>// declare the population</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoPop<Indi> pop;</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>// fill it!</font></tt>
|
||||
<br><b><tt><font color="#993399"> for (unsigned int igeno=0; igeno<POP_SIZE;
|
||||
igeno++)</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> {</font></tt></b>
|
||||
<br><tt><font color="#993399"><b>
|
||||
Indi v;
|
||||
</b>// void individual, to be filled</font></tt>
|
||||
<br><b><tt><font color="#993399">
|
||||
for (unsigned ivar=0; ivar<VEC_SIZE; ivar++)</font></tt></b>
|
||||
<br><b><tt><font color="#993399">
|
||||
{</font></tt></b>
|
||||
<br><tt><font color="#993399"><b>
|
||||
double r = 2*rng.uniform() - 1; </b>// new value, random in [-1,1)</font></tt>
|
||||
<br><tt><font color="#993399"><b>
|
||||
v.push_back(r);
|
||||
</b>// append that random value to v</font></tt>
|
||||
<br><b><tt><font color="#993399">
|
||||
}</font></tt></b>
|
||||
<br><tt><font color="#993399"><b>
|
||||
eval(v);
|
||||
</b>// evaluate it</font></tt>
|
||||
<br><b><tt><font color="#993399">
|
||||
pop.push_back(v);
|
||||
</font></tt></b><tt><font color="#993399">// and put it in the population</font></tt>
|
||||
<br><b><tt><font color="#993399"> }</font></tt></b></td>
|
||||
<td>
|
||||
<tt><font color="#993399">
|
||||
<b> </b>////////////////////////////////<br>
|
||||
<b> </b>// Initilisation of population<br>
|
||||
<b> </b>////////////////////////////////<br>
|
||||
<b> </b>// declare the population<br>
|
||||
<b> eoPop<Indi> pop;</b><br>
|
||||
<b> </b>// fill it!<br>
|
||||
<b> for (unsigned int igeno=0; igeno<POP_SIZE; igeno++)</b><br>
|
||||
<b> {</b><br>
|
||||
<b> Indi v; </b>// void individual, to be filled<br>
|
||||
<b> for (unsigned ivar=0; ivar<VEC_SIZE; ivar++)</b><br>
|
||||
<b> {</b><br>
|
||||
<b> double r = 2*rng.uniform() - 1; </b>// new value, random in [-1,1)<br>
|
||||
<b> v.push_back(r); </b>// append that random value to v<br>
|
||||
<b> }</b><br>
|
||||
<b> eval(v); </b>// evaluate it<br>
|
||||
<b> pop.push_back(v); </b>// and put it in the population<br>
|
||||
<b> }</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="output"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<a NAME="output"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#3366FF"><b> </b>// sort pop before printing
|
||||
it!</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> pop.sort();</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b>// Print (sorted) intial population
|
||||
(raw printout)</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> cout << "Initial Population"
|
||||
<< endl;</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> cout << pop;</font></tt></b></td>
|
||||
<td>
|
||||
<tt><font color="#3366FF">
|
||||
<b> </b>// sort pop before printing it!<br>
|
||||
<b> pop.sort();</b><br>
|
||||
<b> </b>// Print (sorted) intial population (raw printout)<br>
|
||||
<b> cout << "Initial Population" << endl;</b><br>
|
||||
<b> cout << pop;</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="engine"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE >
|
||||
<a NAME="engine"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#009900"><b> </b>/////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#009900"><b> </b>// selection and replacement</font></tt>
|
||||
<br><tt><font color="#009900"><b> </b>////////////////////////////////////</font></tt></td>
|
||||
<td>
|
||||
<tt><font color="#009900">
|
||||
<b> </b>/////////////////////////////////////<br>
|
||||
<b> </b>// selection and replacement<br>
|
||||
<b> </b>////////////////////////////////////<br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="select"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE >
|
||||
<a NAME="select"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#009900"><b> </b>// The robust tournament selection</font></tt>
|
||||
<br><tt><font color="#009900"><b> eoDetTournamentSelect<Indi> select(T_SIZE);
|
||||
</b>// T_SIZE in [2,POP_SIZE]</font></tt></td>
|
||||
<td>
|
||||
<tt><font color="#009900">
|
||||
<b> </b>// The robust tournament selection<br>
|
||||
<b> eoDetTournamentSelect<Indi> select(T_SIZE); </b>// T_SIZE in [2,POP_SIZE]<br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="replace"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE >
|
||||
<a NAME="replace"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#009900"><b> </b>// eoSGA uses generational replacement
|
||||
by default</font></tt>
|
||||
<br><tt><font color="#009900"><b> </b>// so no replacement procedure
|
||||
has to be given</font></tt></td>
|
||||
<td>
|
||||
<tt><font color="#009900">
|
||||
<b> </b>// eoSGA uses generational replacement by default<br>
|
||||
<b> </b>// so no replacement procedure has to be given<br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="stop"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<a NAME="stop"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>
|
||||
<tt><font color="#3366FF">
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="checkpoint"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<a NAME="checkpoint"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#3366FF"><b> </b>//////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>// termination condition</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>/////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>// stop after MAX_GEN generations</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> eoGenContinue<Indi> continuator(MAX_GEN);</font></tt></b>
|
||||
<br> </td>
|
||||
<td>
|
||||
<tt><font color="#3366FF">
|
||||
<b> </b>//////////////////////////////////////<br>
|
||||
<b> </b>// termination condition<br>
|
||||
<b> </b>/////////////////////////////////////<br>
|
||||
<b> </b>// stop after MAX_GEN generations<br>
|
||||
<b> eoGenContinue<Indi> continuator(MAX_GEN);</b><br>
|
||||
<b> </b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="operators"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<a NAME="operators"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993399"><b> </b>//////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>// The variation operators</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>//////////////////////////////////////</font></tt></td>
|
||||
<td>
|
||||
<tt><font color="#993399">
|
||||
<b> </b>//////////////////////////////////////<br>
|
||||
<b> </b>// The variation operators<br>
|
||||
<b> </b>//////////////////////////////////////<br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="mutation"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<a NAME="mutation"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993399"><b> </b>// offspring(i) uniformly chosen
|
||||
in [parent(i)-epsilon, parent(i)+epsilon]</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoUniformMutation<Indi>
|
||||
mutation(EPSILON); </font></tt></b></td>
|
||||
<td>
|
||||
<tt><font color="#993399">
|
||||
<b> </b>// offspring(i) uniformly chosen in [parent(i)-epsilon, parent(i)+epsilon]<br>
|
||||
<b> eoUniformMutation<Indi> mutation(EPSILON); </b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="crossover"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<a NAME="crossover"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993399"><b> </b>// offspring(i) is a linear
|
||||
combination of parent(i)</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoArithmeticCrossover<Indi> xover;</font></tt></b></td>
|
||||
<td>
|
||||
<tt><font color="#993399">
|
||||
<b> </b>// offspring(i) is a linear combination of parent(i)<br>
|
||||
<b> eoArithmeticCrossover<Indi> xover;</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="generation"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<a NAME="generation"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#FF6666"><b> </b>/////////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#FF6666"><b> </b>// the algorithm</font></tt>
|
||||
<br><tt><font color="#FF6666"><b> </b>////////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#FF6666"><b> </b>// standard Generational GA
|
||||
requires</font></tt>
|
||||
<br><tt><font color="#FF6666"><b> </b>// selection, evaluation, crossover
|
||||
and mutation, stopping criterion</font></tt>
|
||||
<p><b><tt><font color="#FF6666"> eoSGA<Indi> gga(select, xover,
|
||||
CROSS_RATE, mutation, MUT_RATE, </font></tt></b>
|
||||
<br><b><tt><font color="#FF6666">
|
||||
eval, continuator);</font></tt></b>
|
||||
<br><tt><font color="#FF6666"><b> </b>// Apply algo to pop - that's
|
||||
it!</font></tt>
|
||||
<br><b><tt><font color="#FF6666"> gga(pop);</font></tt></b>
|
||||
<br> </td>
|
||||
<td>
|
||||
<tt><font color="#FF6666">
|
||||
<b> </b>/////////////////////////////////////////<br>
|
||||
<b> </b>// the algorithm<br>
|
||||
<b> </b>////////////////////////////////////////<br>
|
||||
<b> </b>// standard Generational GA requires<br>
|
||||
<b> </b>// selection, evaluation, crossover and mutation, stopping criterion<br>
|
||||
<b> </b><br>
|
||||
<b> eoSGA<Indi> gga(select, xover, CROSS_RATE, mutation, MUT_RATE, </b><br>
|
||||
<b> eval, continuator);</b><br>
|
||||
<b> </b>// Apply algo to pop - that's it!<br>
|
||||
<b> gga(pop);</b><br>
|
||||
<b> </b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="final_output"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<a NAME="final_output"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#3366FF"><b> </b>// Print (sorted) intial population</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> pop.sort();</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> cout << "FINAL Population\n"
|
||||
<< pop << endl;</font></tt></b></td>
|
||||
<td>
|
||||
<tt><font color="#3366FF">
|
||||
<b> </b>// Print (sorted) intial population<br>
|
||||
<b> pop.sort();</b><br>
|
||||
<b> cout << "FINAL Population\n" << pop << endl;</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="main"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<a NAME="main"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#993300">}</font></tt></b>
|
||||
<br><tt><font color="#993300">// A main that catches the exceptions</font></tt>
|
||||
<br><b><tt><font color="#993300">int main(int argc, char **argv)</font></tt></b>
|
||||
<br><b><tt><font color="#993300">{</font></tt></b>
|
||||
<br><b><tt><font color="#993300">#ifdef _MSC_VER</font></tt></b>
|
||||
<br><tt><font color="#993300"><b> </b>// rng.reseed(42);</font></tt>
|
||||
<br><b><tt><font color="#993300"> int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> flag
|
||||
|= _CRTDBG_LEAK_CHECK_DF;</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> _CrtSetDbgFlag(flag);</font></tt></b>
|
||||
<br><tt><font color="#993300">// _CrtSetBreakAlloc(100);</font></tt>
|
||||
<br><b><tt><font color="#993300">#endif</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> try</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> {</font></tt></b>
|
||||
<br><b><tt><font color="#993300">
|
||||
main_function(argc, argv);</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> }</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> catch(exception&
|
||||
e)</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> {</font></tt></b>
|
||||
<br><b><tt><font color="#993300">
|
||||
cout << "Exception: " << e.what() << '\n';</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> }</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> return 1;</font></tt></b>
|
||||
<br><b><tt><font color="#993300">}</font></tt></b></td>
|
||||
<td>
|
||||
<tt><font color="#993300">
|
||||
<b>}</b><br>
|
||||
// A main that catches the exceptions<br>
|
||||
<b>int main(int argc, char **argv)</b><br>
|
||||
<b>{</b><br>
|
||||
<b>#ifdef _MSC_VER</b><br>
|
||||
<b> </b>// rng.reseed(42);<br>
|
||||
<b> int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);</b><br>
|
||||
<b> flag |= _CRTDBG_LEAK_CHECK_DF;</b><br>
|
||||
<b> _CrtSetDbgFlag(flag);</b><br>
|
||||
// _CrtSetBreakAlloc(100);<br>
|
||||
<b>#endif</b><br>
|
||||
<b> try</b><br>
|
||||
<b> {</b><br>
|
||||
<b> main_function(argc, argv);</b><br>
|
||||
<b> }</b><br>
|
||||
<b> catch(exception& e)</b><br>
|
||||
<b> {</b><br>
|
||||
<b> cout << "Exception: " << e.what() << '\n';</b><br>
|
||||
<b> }</b><br>
|
||||
<b> return 1;</b><br>
|
||||
<b>}</b><br>
|
||||
</font></font></font></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<hr WIDTH="100%"><a href="eoLesson1.html">Back to Lesson 1</a> - <a href="eoTutorial.html">Tutorial
|
||||
main page </a>- <a href="eoTopDown.html">Algorithm-Based</a> - <a href="eoBottomUp.html">Component-Based
|
||||
page</a> - <a href="eoProgramming.html">Programming hints</a> - <font face="Arial,Helvetica"><a href="../../doc/html/index.html">EO
|
||||
|
|
@ -310,8 +343,8 @@ documentation</a></font>
|
|||
<hr>
|
||||
<address>
|
||||
<a href="mailto:marc.schoenauer@polytechnique.fr">Marc Schoenauer</a></address>
|
||||
|
||||
<br><!-- Created: Nov 2000 --><!-- hhmts start -->Last modified: Sun Nov
|
||||
19 08:31:29 2000<!-- hhmts end -->
|
||||
<br><!-- Created: Nov 2000 --><!-- hhmts start -->Last
|
||||
modified: Sun Nov 19 08:31:29 2000
|
||||
<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="Mozilla/4.75 [en] (X11; U; Linux 2.2.17-21mdk i686) [Netscape]">
|
||||
<meta name="GENERATOR" content="Mozilla/4.75 [en] (X11; U; Linux 2.2.17-21mdksmp i686) [Netscape]">
|
||||
<title>Differences</title>
|
||||
</head>
|
||||
<body text="#000000" link="#0000EE" vlink="#551A8B" alink="#FF0000" background="beige009.jpg">
|
||||
|
|
@ -57,15 +57,11 @@ the parameter for the mutation).</li>
|
|||
</tr>
|
||||
|
||||
<tr>
|
||||
<td BGCOLOR="#F0C6B7"><font face="Courier New,Courier"><font color="#FFFF00">#include
|
||||
<es.h></font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#FFFF00">typedef eoReal<double>
|
||||
Indi;</font></font></td>
|
||||
<td BGCOLOR="#F0C6B7"><font face="Courier New,Courier"><font color="#FFFF00">#include <es.h><br>
|
||||
typedef eoReal<double> Indi;</font></font></td>
|
||||
|
||||
<td BGCOLOR="#F0C6B7"><font face="Courier New,Courier"><font color="#FFFF00">#include
|
||||
<ga.h></font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#FFFF00">typedef eoBin<double>
|
||||
Indi;</font></font></td>
|
||||
<td BGCOLOR="#F0C6B7"><font face="Courier New,Courier"><font color="#FFFF00">#include <ga.h><br>
|
||||
typedef eoBit<double> Indi;</font></font></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
|
|
@ -230,15 +226,15 @@ mutation(EPSILON);</font></font>
|
|||
<br><font face="Courier New,Courier"><font color="#CC33CC">eoArithmeticCrossover<Indi>
|
||||
xover;</font></font></td>
|
||||
|
||||
<td BGCOLOR="#F0C6B7"><font face="Courier New,Courier"><font color="#CC33CC">eoBinMutation<Indi>
|
||||
<td BGCOLOR="#F0C6B7"><font face="Courier New,Courier"><font color="#CC33CC">eoBitMutation<Indi>
|
||||
mutation(P_MUT_PER_BIT);</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC">eoBinCrossover<Indi>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC">eo1PtBitXover<Indi>
|
||||
xover;</font></font></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td BGCOLOR="#C3C2B4">
|
||||
<br><font face="Courier New,Courier"><font color="#FF6666">eoSGA<Indi>
|
||||
<font face="Courier New,Courier"><font color="#FF6666">eoSGA<Indi>
|
||||
gga(select, xover, CROSS_RATE,</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#FF6666">
|
||||
mutation, MUT_RATE, eval, continuator);</font></font>
|
||||
|
|
@ -255,11 +251,10 @@ code removed]</font></font>
|
|||
<br><font face="Courier New,Courier"><font color="#993300">}</font></font></td>
|
||||
|
||||
<td BGCOLOR="#C3C2B4">
|
||||
<br><font face="Courier New,Courier"><font color="#FF6666">eoSGA<Indi>
|
||||
<font face="Courier New,Courier"><font color="#FF6666">eoSGA<Indi>
|
||||
gga(select, xover, CROSS_RATE,</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#FF6666">
|
||||
mutation, MUT_RATE,</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#FF6666">eval, continuator);</font></font>
|
||||
mutation, MUT_RATE, eval, continuator);</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#FF6666">gga(pop);</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#3366FF">pop.sort();</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#3366FF">cout <<
|
||||
|
|
|
|||
|
|
@ -63,11 +63,8 @@ the number of ones of a bitstring</font></tt>
|
|||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFFFCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#999900">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#999900">// Include the corresponding file</font></tt>
|
||||
<br><tt><font color="#999900"><b>#include <ga.h></b>
|
||||
// bitstring representation & operators</font></tt>
|
||||
<br><tt><font color="#999900">// define your genotype and fitness types</font></tt>
|
||||
<br><b><tt><font color="#999900">typedef eoBin<double> Indi;</font></tt></b></td>
|
||||
<br><b><tt><font color="#999900">typedef eoBit<double> Indi;</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="general"></a>
|
||||
|
|
@ -314,6 +311,7 @@ of initializatio of the population</font></tt></td>
|
|||
<tr>
|
||||
<td><tt><font color="#009900"><b> </b>// The robust tournament selection</font></tt>
|
||||
<br><tt><font color="#009900"><b> eoDetTournamentSelect<Indi> selectOne(tSize);
|
||||
|
||||
</b>// tSize in [2,POPSIZE]</font></tt>
|
||||
<br><tt><font color="#009900"><b> </b>// is now encapsulated in a
|
||||
eoSelectPerc (entage)</font></tt>
|
||||
|
|
@ -346,11 +344,11 @@ replace; </font></tt></b></td>
|
|||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993399"><b> </b>// 1-point crossover for bitstring</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoBinCrossover<Indi> xover1;</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> eo1PtBitXover<Indi> xover1;</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>// uniform crossover for bitstring</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoBinUxOver<Indi> xoverU;</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> eoUBitXover<Indi> xoverU;</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>// 2-pots xover</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoBinNxOver<Indi> xover2(2);</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> eoNPtsBitXover<Indi> xover2(2);</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>// Combine them with relative
|
||||
rates</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoPropCombinedQuadOp<Indi> xover(xover1,
|
||||
|
|
@ -365,7 +363,7 @@ true);</font></tt></b></td>
|
|||
<tr>
|
||||
<td><tt><font color="#993399"><b> </b>// standard bit-flip mutation
|
||||
for bitstring</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoBinMutation<Indi> mutationBitFlip(pMutPerBit);</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> eoBitMutation<Indi> mutationBitFlip(pMutPerBit);</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>// mutate exactly 1 bit per
|
||||
individual</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoDetBitFlip<Indi> mutationOneBit; </font></tt></b>
|
||||
|
|
|
|||
124
eo/tutorial/html/eoCheckPoint.html
Normal file
124
eo/tutorial/html/eoCheckPoint.html
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="Mozilla/4.76 [en] (X11; U; Linux 2.2.17-21mdksmp i686) [Netscape]">
|
||||
<title>Variation Operators</title>
|
||||
</head>
|
||||
<body text="#000000" link="#0000EF" vlink="#51188E" alink="#FF0000" background="beige009.jpg">
|
||||
<b><font color="#FF0000">General</font></b>: <a href="eoTopDown.html">Algorithm-Based</a>
|
||||
- <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">Programming
|
||||
hints</a> - <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font></font></b>
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<br><b><font color="#FF0000">Local</font></b>: <a href="#introduction">Introduction</a>
|
||||
- <a href="#continuator">Continuators</a> - <a href="#combined_continue">Combined
|
||||
continuators</a> - <a href="#checkpoint">Checkpoints</a> - <a href="#statistic">Statistics</a>
|
||||
- <a href="#monitor">Monitors</a> - <a href="#updater">Updaters</a>
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<center>
|
||||
<h1>
|
||||
<b><font color="#CC0000">CheckPointing</font></b></h1></center>
|
||||
<a NAME="introduction"></a><b><font color="#000099"><font size=+2>What
|
||||
is Checkpointing about?</font></font></b>
|
||||
<br>Evolutionary Algorithms are ticked
|
||||
<p><b><font color="#FF0000">EO classes described in this page</font></b>:
|
||||
<ul>
|
||||
<li>
|
||||
<b><font color="#FF0000">Base classes</font></b>: eoCheckPoint, eoContinue,
|
||||
eoStat, eoSortedStat, eoMonitor, eoUpdater</li>
|
||||
|
||||
<li>
|
||||
<b><font color="#FF0000">Derived classes</font></b>: eoCombinedContinue,</li>
|
||||
|
||||
<li>
|
||||
<b><font color="#FF0000">Related classes</font></b>: eoGnuPlot</li>
|
||||
</ul>
|
||||
|
||||
<br>
|
||||
<p>
|
||||
<hr WIDTH="100%"><a NAME="continuator"></a><b><font color="#000099"><font size=+1>Continuators:</font></font></b>
|
||||
<br>
|
||||
<p>Continuators are functors that compute stopping critera. They receive
|
||||
a population and return a boolean value which is set to false only when
|
||||
some stopping vriterion is met. All algorithms in EO have a loop that goes
|
||||
<b><font color="#993300">while(continuator(pop)
|
||||
{ ... }<tt> </tt></font></b>which means that the algorithm stops only when
|
||||
the continuator returns <b><font color="#993300">false</font></b>.
|
||||
<p><b><font color="#FF0000">Interface</font></b>:
|
||||
<br>
|
||||
<p><b><font color="#FF0000">Using a continuator</font></b>:
|
||||
<br>You can find an first example of using a continuator in the code for
|
||||
<a href="FirstBitGA.html#stop">FirstBitEA</a> in <a href="eoLesson2.html#tour">Lesson2</a>.
|
||||
<br>If you want to find out how it is used inside an algorithm, go and
|
||||
see for instance in eoSGA, the simplest EA within EO.
|
||||
<p><a NAME="writing_continuator"></a><b><font color="#FF0000">Writing a
|
||||
continuator:</font></b>
|
||||
<br>There are only two things to modify in the <a href="../Templates/continuator.tmpl">template
|
||||
class definitions</a> provided (apart from the name of the class you are
|
||||
creating!)
|
||||
<ul>
|
||||
<li>
|
||||
The <font color="#FF6600">constructor</font>, where you pass to the object
|
||||
any useful parameter (see the private data at end of class definition).</li>
|
||||
|
||||
<li>
|
||||
The <font color="#FF6600">operator()</font> method, which performs the
|
||||
actual test on the population.</li>
|
||||
</ul>
|
||||
Don't forget to <b><font color="#FF6600">return</font></b> <b><font color="#FF6600">false</font></b>
|
||||
when the stopping criterion <b><font color="#FF6600">is met!</font></b>
|
||||
<p>
|
||||
<hr WIDTH="100%"><a NAME="combined_continue"></a><b><font color="#000099"><font size=+1>Combining
|
||||
continuators:</font></font></b>
|
||||
<p>
|
||||
<hr WIDTH="100%"><a NAME="checkpoint"></a><b><font color="#000099"><font size=+1>CheckPoints:</font></font></b>
|
||||
<p><b><font color="#FF0000">Interface</font></b>:
|
||||
<p><b><font color="#FF0000">Using a checkpoint</font></b>: An eoCheckPoint
|
||||
being an eoContinue, its usage is exactly the same. However, an eoCheckPoint
|
||||
will actually do many more things than an eoContinue before returning its
|
||||
boolean result as an eoContinue.
|
||||
<p><a NAME="writing_checkpoint"></a><b><font color="#FF0000">Writing a
|
||||
checkpoint:</font></b>
|
||||
<br>This is something you should never have to do. However, should you
|
||||
fell you have to do it, please do - and send us both the reasons that lead
|
||||
you to that (wqhat is it you couldn't do with existing eoCheckPoint), and
|
||||
the resulting code, of course.
|
||||
<br>
|
||||
<hr WIDTH="100%"><a NAME="statistic"></a><b><font color="#000099"><font size=+1>Statistics:</font></font></b>
|
||||
<p><b><font color="#FF0000">Interface</font></b>:
|
||||
<p><b><font color="#FF0000">Using statistics</font></b>:
|
||||
<p><a NAME="writing_statistic"></a><b><font color="#FF0000">Writing a statitic</font></b>:
|
||||
<br>
|
||||
<hr WIDTH="100%"><a NAME="monitor"></a><b><font color="#000099"><font size=+1>Monitors:</font></font></b>
|
||||
<p><b><font color="#FF0000">Interface</font></b>:
|
||||
<p><b><font color="#FF0000">Using monitors</font></b>:
|
||||
<p><a NAME="writing_monitor"></a><b><font color="#FF0000">Writing a monitor</font></b>:
|
||||
<p>
|
||||
<hr WIDTH="100%"><a NAME="updater"></a><b><font color="#000099"><font size=+1>Updater:</font></font></b>
|
||||
<p><b><font color="#FF0000">Interface</font></b>:
|
||||
<p><b><font color="#FF0000">Using updaters</font></b>:
|
||||
<p><a NAME="writing_updater"></a><b><font color="#FF0000">Writing an updater</font></b>:
|
||||
<br>
|
||||
<p>
|
||||
<hr WIDTH="100%"><b><font color="#FF0000">Local</font></b>: <a href="#introduction">Introduction</a>
|
||||
- <a href="#continuator">Continuators</a> - <a href="#combined_continue">Combined
|
||||
continuators</a> - <a href="#checkpoint">Checkpoints</a> - <a href="#statistic">Statistics</a>
|
||||
- <a href="#monitor">Monitors</a> - <a href="#updater">Updaters</a>
|
||||
<br>
|
||||
<hr WIDTH="100%"><b><font color="#FF0000">General</font></b>: <a href="eoTopDown.html">Algorithm-Based</a>
|
||||
- <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">Programming
|
||||
hints</a> -<b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font></font></b>
|
||||
<br>
|
||||
<hr>
|
||||
<address>
|
||||
<a href="mailto:Marc.Schoenauer@polytechnique.fr">Marc Schoenauer</a></address>
|
||||
|
||||
<br><!-- Created: Mon Oct 30 07:27:13 CET 2000 --><!-- hhmts start -->Last
|
||||
modified: Fri Dec. 8 2000 <!-- hhmts end -->
|
||||
<br>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -159,12 +159,9 @@ paradigm).
|
|||
<p><b><font color="#FF0000">Note</font></b>: some procedures for selecting
|
||||
a single individual require some pre-processing of the whole population
|
||||
that takes place before any selection, and will be repeated identically
|
||||
for every individual. The encapsulation of an <font color="#009900">eoSelectOne</font>
|
||||
into an <font color="#009900">eoSelectMany</font> allows to call such technical
|
||||
processing only once through a call to the setup method of class <font color="#009900">eoSelectOne</font>.
|
||||
This method does nothing by default, but is implemented for instance in
|
||||
eoProportionalSelect (the roulette wheel-selection) to compute only once
|
||||
the total of the fitnesses of all individuals in the population.
|
||||
for every individual. The encapsulation of an into an allows
|
||||
to call such technical processing only once through the use of method setup
|
||||
of class . This method does nothing by default, but is mandatory
|
||||
<br>
|
||||
<hr WIDTH="50%">
|
||||
<br><b><font color="#000099">eoSelect: </font><font color="#FF0000">Other
|
||||
|
|
@ -244,8 +241,6 @@ and you can probably guess what each of them actually does :-)</li>
|
|||
|
||||
<br>
|
||||
<p>
|
||||
<br>
|
||||
<br>
|
||||
<p>Available <font color="#FF6600">instances of eoMergeReduce</font> replacement
|
||||
include
|
||||
<ul>
|
||||
|
|
@ -315,9 +310,7 @@ size. Available instances of <b><tt><font color="#009900">eoSurviveAndDieReplace
|
|||
are limited todayto the <b><tt><font color="#009900">eoDeterministicSaDReplacement</font></tt></b>,
|
||||
the that uses a deterministic MergeReduce.</li>
|
||||
|
||||
<br>
|
||||
<p>
|
||||
<p><b><font color="#FF0000">Note</font></b>: The basic use (and initial
|
||||
<p><br><b><font color="#FF0000">Note</font></b>: The basic use (and initial
|
||||
motivation) for <b><tt><font color="#009900">eoSurviveAndDie</font></tt></b>
|
||||
takes 2 arguments, an eoMergeReduce and a number of surviving parents.
|
||||
It starts by copying the best parents to the new populations, then merges
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="Mozilla/4.75 [en] (X11; U; Linux 2.2.17-21mdk i686) [Netscape]">
|
||||
<meta name="GENERATOR" content="Mozilla/4.76 [en] (X11; U; Linux 2.2.17-21mdksmp i686) [Netscape]">
|
||||
<title>Tutorial: Lesson 1</title>
|
||||
</head>
|
||||
<body text="#000000" link="#0000EE" vlink="#551A8B" alink="#FF0000" background="beige009.jpg">
|
||||
|
|
@ -94,30 +94,34 @@ tour below. You might prefer to go directly to the <a href="#exercise1">exercise
|
|||
all C-like code, the file starts with include directives (<a href="FirstBitGA.html#start">Bit</a>
|
||||
- <a href="FirstRealGA.html#start">Real</a>). Apart from standard includes,
|
||||
the specific file to include is </font><b><font color="#FF6600">eo</font></b><font color="#000000">:
|
||||
this is a file that contains the list of the most important EO files.</font></li>
|
||||
this is a file that contains the list of the all important representation-independent
|
||||
EO files.</font></li>
|
||||
|
||||
<br>
|
||||
<li>
|
||||
<b><font color="#999900">Representation</font></b><font color="#000000">:
|
||||
you need to declare the type of individuals you will be handling. First,
|
||||
include some header files where these are defined: </font><b><tt><font color="#999900">ga.h</font></tt></b><font color="#000000">
|
||||
for bitstring, </font><b><tt><font color="#999900">es.h</font></tt></b><font color="#000000">
|
||||
for real-valued genotypes.<br>
|
||||
Then a </font><b><tt><font color="#993300">typedef</font></tt></b><font color="#000000">
|
||||
directive will allow one to handle the abstract </font><b><tt><font color="#993300">Indi</font></tt></b><font color="#000000">
|
||||
all around in the main code. Remember that all evolution-related objects
|
||||
you will need are templatized w.r.t. the type of individuals.</font></li>
|
||||
you then have to declare the type of individuals you will be handling.
|
||||
All evolution-related objects you will need are templatized w.r.t. the
|
||||
type of individuals.</font></li>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<a href="FirstBitGA.html#representation">Bit</a> You say here that you
|
||||
will be handling <b><font face="Arial,Helvetica"><a href="../../doc/html/class_eobin.html">Bitstring
|
||||
<a href="FirstBitGA.html#representation">Bit</a> You first need to include
|
||||
the representation-dependent file <b><tt><font color="#993300"><font size=+1>ga.h</font></font></tt></b>,
|
||||
containing the bitstring representation and operators. More details about
|
||||
<a href="eoRepresentation.html#bitstring">what is available for bitstrings
|
||||
here</a>.<br>
|
||||
You then say that you will be handling <b><font face="Arial,Helvetica"><a href="../../doc/html/class_eobin.html">Bitstring
|
||||
genotypes</a></font></b>, whose fitness is a double. This makes Indi derive
|
||||
from the <a href="eoProgramming.html#STL">STL class</a> <font color="#993300">vector<bool></font></li>
|
||||
|
||||
<li>
|
||||
<a href="FirstRealGA.html#representation">Real</a> You say here that you
|
||||
will be handling <b><font face="Arial,Helvetica"><a href="../../doc/html/class_eoreal.html">Real-valued
|
||||
<a href="FirstRealGA.html#representation">Real</a> You first need to include
|
||||
the representation-dependent file <b><tt><font color="#993300"><font size=+1>es.h</font></font></tt></b>,
|
||||
containing the bitstring representation and operators. More details about
|
||||
<a href="eoRepresentation.html#real">what is available for real-values
|
||||
here</a>.<br>
|
||||
You then say that you will be handling <b><font face="Arial,Helvetica"><a href="../../doc/html/class_eoreal.html">Real-valued
|
||||
genotypes</a></font></b>, whose fitness is a double. This makes Indi derive
|
||||
from the <a href="eoProgramming.html#STL">STL class</a> <font color="#993300">vector<double></font></li>
|
||||
|
||||
|
|
@ -238,8 +242,8 @@ corresponding pages</a>, or to their respective documentation pages.</font></li>
|
|||
<br>
|
||||
<ul>
|
||||
<li>
|
||||
<a href="FirstBitGA.html#operators">Bit</a> The crossover <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/class_eobincrossover.html">eoBinCrossover</a></font></font></b>
|
||||
is the standard <font color="#CC33CC">1-point crossover</font>, and <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/class_eobinmutation.html">eoBinMutation</a></font></font></b>
|
||||
<a href="FirstBitGA.html#operators">Bit</a> The crossover <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/class_eobincrossover.html">eo1PtBitXover</a></font></font></b>
|
||||
is the standard <font color="#CC33CC">1-point crossover</font>, and <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/class_eobinmutation.html">eoBitMutation</a></font></font></b>
|
||||
is the standard <font color="#FF6600">bit-flip mutation</font> that randomly
|
||||
flips all bits with a given probability <b><tt>P_MUT_PER_BIT.</tt></b></li>
|
||||
|
||||
|
|
|
|||
|
|
@ -67,7 +67,13 @@ argument is a <a href="binary_value.html">vector<bool></a> or a <a href="real
|
|||
and not an unknown type. This will allow to use the same file for any EO
|
||||
object that is a sub-class of the corresponding STL vector class.</font></li>
|
||||
|
||||
<p><br><b><font color="#FF0000">Note:</font></b> <font color="#000000">Also,
|
||||
<br>
|
||||
<p>
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
<p><b><font color="#FF0000">Note:</font></b> <font color="#000000">Also,
|
||||
a non-templatized fitness can be </font><b><font color="#FF6600">compiled
|
||||
separately</font></b><font color="#000000"> (not done here) into an object
|
||||
file once and for all (<a href="eoProgramming.html#templates">remember</a>
|
||||
|
|
@ -82,8 +88,14 @@ have to declare 3 template arguments: the type of EO object it will be
|
|||
applied to, the return type and the type of argument the function actually
|
||||
requires.</font></li>
|
||||
|
||||
<p><br><b><font color="#FF0000">Note:</font></b> <font color="#000000">In
|
||||
the previous files (<a href="FirstBitGA.html#eval">Bit</a> - <a href="FirstRealGA.html#eval">Real</a>)
|
||||
<br>
|
||||
<p>
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
<p><b><font color="#FF0000">Note:</font></b> <font color="#000000">In the
|
||||
previous files (<a href="FirstBitGA.html#eval">Bit</a> - <a href="FirstRealGA.html#eval">Real</a>)
|
||||
, the last 2 types were deduced from the first (2nd argument = fitness
|
||||
type of EO object, third = first).</font>
|
||||
<br>
|
||||
|
|
@ -105,7 +117,13 @@ You can also use different initializers and call them in turn through the
|
|||
call to <a href="../../doc/html/class_eopop.html#a2">pop.append()</a> function
|
||||
(see <a href="#exercise2">Exercise 2</a>).</font></li>
|
||||
|
||||
<p><br><b><font color="#FF0000">Note</font><font color="#CC33CC">: </font></b><font color="#000000">Don't
|
||||
<br>
|
||||
<p>
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
<p><b><font color="#FF0000">Note</font><font color="#CC33CC">: </font></b><font color="#000000">Don't
|
||||
forget to </font><b><font color="#CC0000">evaluate the population</font></b><font color="#000000">:
|
||||
the eoPop has no idea of the eval function, so it has to be done from outside!!!</font>
|
||||
<br>
|
||||
|
|
|
|||
|
|
@ -6,10 +6,12 @@
|
|||
<title>EO Programming guide</title>
|
||||
</head>
|
||||
<body text="#000000" link="#0000EE" vlink="#551A8B" alink="#FF0000" background="beige009.jpg">
|
||||
<b><font color="#CC0000">General: </font></b><a href="eoTutorial.html">Tutorial
|
||||
<b><font color="#CC0000">General: </font></b><a href="http://www.eeaax.polytechnique.fr/EO/eo/tutorial/html/eoTutorial.html">Tutorial
|
||||
main page </a>-
|
||||
<a href="eoTopDown.html">Algorithm-Based</a> - <a href="eoBottomUp.html">Component-Based</a>
|
||||
- <a href="eoProgramming.html">Programming hints</a> - <font face="Arial,Helvetica"><a href="../../doc/html/index.html">EO
|
||||
<a href="http://www.eeaax.polytechnique.fr/EO/eo/tutorial/html/eoTopDown.html">Algorithm-Based</a>
|
||||
- <a href="http://www.eeaax.polytechnique.fr/EO/eo/tutorial/html/eoBottomUp.html">Component-Based</a>
|
||||
- <a href="http://www.eeaax.polytechnique.fr/EO/eo/tutorial/html/eoProgramming.html">Programming
|
||||
hints</a> - <font face="Arial,Helvetica"><a href="http://www.eeaax.polytechnique.fr/EO/eo/doc/html/index.html">EO
|
||||
documentation</a></font>
|
||||
<br>
|
||||
<hr WIDTH="100%"><b><font color="#CC0000">Local: </font></b><a href="#templates">Templates</a>
|
||||
|
|
@ -32,14 +34,15 @@ naming variables in algebra: you can write a lot of equations involving
|
|||
some variable $x$ without knowing even it if will be an integer or a float
|
||||
(or a matrix or ...). The main basic type that is templatized in EO is
|
||||
the fitness: an EO object is some object which has a fitness of some type
|
||||
F that can be anything. The definition for that is (see <font face="Arial,Helvetica"><a href="../../doc/html/EO.h-source.html">EO.h</a></font>)
|
||||
F that can be anything. The definition for that is (see <font face="Arial,Helvetica"><a href="http://www.eeaax.polytechnique.fr/EO/eo/doc/html/EO.h-source.html">EO.h</a></font>)
|
||||
<p><b><tt><font color="#999900">template<F> class EO</font></tt></b>
|
||||
<p>The idea is that, later in your code, you can declare for instance as
|
||||
in <a href="FirstBitGA.html#representation">FirstBitGA.cpp</a>
|
||||
<p><b><tt><font color="#999900">typedef eoBin<double> Genotype;</font></tt></b>
|
||||
<p>meaning that in that file, you will manipulate as <b><tt><font color="#999900">Genotype</font></tt></b>
|
||||
objects that are EO objects <font color="#000000">whose </font><b><font color="#FF6600">fitness</font></b><font color="#000000">
|
||||
is a </font><font color="#FF6600"><b>double</b>.</font>
|
||||
<p>The idea is that, later in your code, you can define a class as follows
|
||||
(see for instance <a href="http://www.eeaax.polytechnique.fr/EO/eo/doc/eoBin.h-source.html">eoBin.h</a>
|
||||
<p><b><tt><font color="#999900">template<F> class eoBin : public EO<F></font></tt></b>
|
||||
<br><b><tt><font color="#999900">{ ... code for eoBin };</font></tt></b>
|
||||
<p>and then use it in your application as
|
||||
<p><b><tt><font color="#999900">eoBin<double> myeoBin;</font></tt></b>
|
||||
<p>declares an object of type eoBin which has as fitness a double.
|
||||
<p>Whereas the advantages are obvious (writing generic reusable code instead
|
||||
of having to rewrite the same pieces of code for different types), there
|
||||
are some drawbacks: namely, it makes some of the compiler error messages
|
||||
|
|
@ -68,13 +71,12 @@ a hierarchy of functions with defaults behaviors and specialized sub-functions</
|
|||
<li>
|
||||
...</li>
|
||||
</ul>
|
||||
Functors are so intimately linked to EO that a base class (<b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/class_eofunctorbase.html">eoFunctorBase</a></font></font></b>)
|
||||
Functors are so intimately linked to EO that a base class (<b><font face="Arial,Helvetica"><font size=+1><a href="http://www.eeaax.polytechnique.fr/EO/eo/doc/html/class_eofunctorbase.html">eoFunctorBase</a></font></font></b>)
|
||||
has been designed to hold all functors. This base class is itself divided
|
||||
into three derived class. These classes tell you immediately what kind
|
||||
of arguments the <b><tt><font color="#993300">operator()</font></tt></b>
|
||||
method requires and what kind of result it produces. See <a href="#notations">EO
|
||||
conventions</a>,
|
||||
and the <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/class_eofunctorbase.html">inheritance
|
||||
conventions</a>, and the <b><font face="Arial,Helvetica"><font size=+1><a href="http://www.eeaax.polytechnique.fr/EO/eo/doc/html/class_eofunctorbase.html">inheritance
|
||||
diagram of class eoFunctorBase</a>.</font></font></b>
|
||||
<br>For a more complete introduction to functors, with detailed discussion,
|
||||
go to the <a href="http://www.sgi.com/Technology/STL/functors.html">STL
|
||||
|
|
@ -83,7 +85,7 @@ paradigm is borrowed from there.
|
|||
<p><b><font color="#FF0000">Functors:</font><font color="#000099"> Example:</font></b>
|
||||
<p>The following is a basic example of how to program and use a functor
|
||||
object: First code the class:
|
||||
<p><b><tt><font color="#993300">class MyClass</font></tt></b>
|
||||
<p><b><tt><font color="#993300">class MyFunctor</font></tt></b>
|
||||
<br><b><tt><font color="#993300">{ ...</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> void operator()(ArgType
|
||||
arg)</font></tt></b>
|
||||
|
|
@ -94,10 +96,10 @@ arg)</font></tt></b>
|
|||
<br><tt><font color="#993300"><b>}; </b>// end of class declaration</font></tt>
|
||||
<p>Then use it later in the code :
|
||||
<p><b><tt><font color="#993300">ArgType myArgument;</font></tt></b>
|
||||
<br><tt><font color="#993300"><b>MyClass myObject; </b>
|
||||
// myObject is an object of class MyClass ...</font></tt>
|
||||
<br><tt><font color="#993300"><b>myObject(myArgument);</b> // calls
|
||||
operator() of myObject acting on myArgument ...</font></tt>
|
||||
<br><tt><font color="#993300"><b>MyFunctor myFunctorInstance; </b>
|
||||
// myFunctorInstance is an object of class MyFUnctor ...</font></tt>
|
||||
<br><tt><font color="#993300"><b>myFunctorInstance(myArgument);</b>
|
||||
// calls operator() of myFunctorInstance acting on myArgument ...</font></tt>
|
||||
<br>
|
||||
<p><b><font color="#FF0000">Functors:</font><font color="#000099"> The
|
||||
three basic classes:</font></b>
|
||||
|
|
@ -116,7 +118,7 @@ method.</font>
|
|||
is for arity-zero functors, i.e. their </font><b><tt><font color="#993300">operator()</font></tt></b><font color="#000000">
|
||||
method does not require any argument. It has a single template parameter,
|
||||
the return type of the </font><b><tt><font color="#993300">operator()</font></tt></b><font color="#000000">
|
||||
method. For instance, </font> <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/class_eomonitor.html">eoMonitor</a></font></font></b> <font color="#000000">
|
||||
method. For instance, </font> <b><font face="Arial,Helvetica"><font size=+1><a href="http://www.eeaax.polytechnique.fr/EO/eo/doc/html/class_eomonitor.html">eoMonitor</a></font></font></b> <font color="#000000">
|
||||
are </font><b><tt><font color="#FF6600">eoF</font></tt></b><font color="#000000">'s
|
||||
that return an </font><b><tt><font color="#993300">eoMonitor &</font></tt></b><font color="#000000">.</font></li>
|
||||
|
||||
|
|
@ -125,7 +127,7 @@ that return an </font><b><tt><font color="#993300">eoMonitor &</font></tt></
|
|||
is for unary functors, i.e. their </font><b><tt><font color="#993300">operator()</font></tt></b><font color="#000000">
|
||||
method requires one argument. It has two template parameters, the type
|
||||
of the argument and the return type of the </font><b><tt><font color="#993300">operator()</font></tt></b><font color="#000000">
|
||||
method. For instance, </font> <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/class_eomonop.html">eoMonOp</a></font></font></b>'s<font color="#000000">
|
||||
method. For instance, </font> <b><font face="Arial,Helvetica"><font size=+1><a href="http://www.eeaax.polytechnique.fr/EO/eo/doc/html/class_eomonop.html">eoMonOp</a></font></font></b>'s<font color="#000000">
|
||||
are </font><b><tt><font color="#FF6600">eoUF</font></tt></b><font color="#000000">'s
|
||||
that take as argument an </font><b><tt><font color="#993300">EOT &</font></tt></b><font color="#000000">
|
||||
and return </font><b><tt><font color="#993300">void</font></tt></b><font color="#000000">
|
||||
|
|
@ -136,14 +138,14 @@ and return </font><b><tt><font color="#993300">void</font></tt></b><font color="
|
|||
is for binary functors, i.e. their </font><b><tt><font color="#993300">operator()</font></tt></b><font color="#000000">
|
||||
method requires two arguments. It has three template parameters, the types
|
||||
of the arguments and the return type of the </font><b><tt><font color="#993300">operator()</font></tt></b><font color="#000000">
|
||||
method. For instance, </font> <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/class_eobinop.html">eoBinOp</a></font></font></b>'s<font color="#000000">
|
||||
method. For instance, </font> <b><font face="Arial,Helvetica"><font size=+1><a href="http://www.eeaax.polytechnique.fr/EO/eo/doc/html/class_eobinop.html">eoBinOp</a></font></font></b>'s<font color="#000000">
|
||||
are </font><b><tt><font color="#FF6600">eoBF</font></tt></b><font color="#000000">'s
|
||||
that take as arguments a </font><b><tt><font color="#993300">const EOT
|
||||
&</font></tt></b><font color="#000000"> and an </font><b><tt><font color="#993300">EOT
|
||||
&</font></tt></b><font color="#000000">, and return </font><b><tt><font color="#993300">void</font></tt></b><font color="#000000">
|
||||
.</font></li>
|
||||
</ul>
|
||||
<font color="#000000">Now go back to the </font><b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/class_eofunctorbase.html">inheritance
|
||||
<font color="#000000">Now go back to the </font><b><font face="Arial,Helvetica"><font size=+1><a href="http://www.eeaax.polytechnique.fr/EO/eo/doc/html/class_eofunctorbase.html">inheritance
|
||||
diagram of class eoFunctorBase</a></font></font></b><font color="#000000">,
|
||||
and guess the interface for all functors!</font>
|
||||
<p><b><font color="#FF0000">Note</font></b><font color="#000000">: for
|
||||
|
|
@ -151,7 +153,7 @@ obvious simplicity reasons, we very often omit the reference to the </font><b><t
|
|||
e.g. when we say above:</font>
|
||||
<ul>
|
||||
<li>
|
||||
<b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/class_eomonop.html">eoMonOp</a></font></font></b>'s<font color="#000000">
|
||||
<b><font face="Arial,Helvetica"><font size=+1><a href="http://www.eeaax.polytechnique.fr/EO/eo/doc/html/class_eomonop.html">eoMonOp</a></font></font></b>'s<font color="#000000">
|
||||
are </font><b><tt><font color="#FF6600">eoUF</font></tt></b><font color="#000000">'s
|
||||
that take as argument an </font><b><tt><font color="#993300">EOT &</font></tt></b><font color="#000000">
|
||||
and return </font><b><tt><font color="#993300">void</font></tt></b></li>
|
||||
|
|
@ -159,7 +161,7 @@ and return </font><b><tt><font color="#993300">void</font></tt></b></li>
|
|||
<font color="#000000">it actually means</font>
|
||||
<ul>
|
||||
<li>
|
||||
<b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/class_eomonop.html">eoMonOp</a></font></font></b>'s<font color="#000000">
|
||||
<b><font face="Arial,Helvetica"><font size=+1><a href="http://www.eeaax.polytechnique.fr/EO/eo/doc/html/class_eomonop.html">eoMonOp</a></font></font></b>'s<font color="#000000">
|
||||
are </font><b><tt><font color="#FF6600">eoUF</font></tt></b><font color="#000000">'s,
|
||||
their </font><b><tt><font color="#993300">operator()</font></tt></b><font color="#000000">
|
||||
method takes as argument an </font><b><tt><font color="#993300">EOT &</font></tt></b><font color="#000000">
|
||||
|
|
@ -228,8 +230,8 @@ and the data manipulation listed above for vectors can be applied to list.</font
|
|||
<br><font color="#000000">This simple container allows you to hold two
|
||||
data types together. It is very handy for temporary data handling. Assuming
|
||||
p is a </font><b><tt><font color="#993300">pair<AtomType1, AtomType2></font></tt></b><font color="#000000">,
|
||||
</font><b><tt><font color="#993300">p.first()</font></tt></b><font color="#000000">
|
||||
and </font><b><tt><font color="#993300">p.second()</font></tt></b><font color="#000000">
|
||||
</font><b><tt><font color="#993300">p.first</font></tt></b><font color="#000000">
|
||||
and </font><b><tt><font color="#993300">p.second</font></tt></b><font color="#000000">
|
||||
refer to the encapsulated data, of respective types </font><b><tt><font color="#993300">AtomType1</font></tt></b><font color="#000000">
|
||||
and
|
||||
</font><b><tt><font color="#993300">AtomType2</font></tt></b>
|
||||
|
|
@ -307,7 +309,7 @@ numbers who look random (w.r.t. some statistical criteria).
|
|||
to ensure reproducibility of the results across different platforms, EO
|
||||
has its own RNG, the ``<font color="#FF6600">Mersenne Twister</font>''
|
||||
random number generator MT19937 (thanks to <font color="#FF0000">Takuji
|
||||
Nishimura</font>, see <font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/eorng_h-source.html">eoRNG.h</a></font></font>
|
||||
Nishimura</font>, see <font face="Arial,Helvetica"><font size=+1><a href="http://www.eeaax.polytechnique.fr/EO/eo/doc/html/eorng_h-source.html">eoRNG.h</a></font></font>
|
||||
comments).
|
||||
<p>Though you can define and use as many RNGs as you wish in EO, the library
|
||||
also provides you with a global RNG termed <b><tt><font color="#993300">eo::rng</font></tt></b>.
|
||||
|
|
@ -322,22 +324,22 @@ purposes</li>
|
|||
random numbers are computed starting from a seed - starting from the same
|
||||
seed will lead to the same series of pseudo-random numbers, and hence to
|
||||
the same results of the algorithms. All examples in this tutorial will
|
||||
use the RNG seeding procedure, see e.g. in <a href="FirstBitGA.html#random">Lesson1</a>.</li>
|
||||
use the RNG seeding procedure, see e.g. in <a href="http://www.eeaax.polytechnique.fr/EO/eo/tutorial/html/FirstBitGA.html#random">Lesson1</a>.</li>
|
||||
|
||||
<li>
|
||||
to simulate "true" random runs, you can just seed the RNG with a machine-clock
|
||||
related number, e.g. calling time(0), as done for instance in <a href="SecondBitEA.html#random">Lesson3</a>
|
||||
related number, e.g. calling time(0), as done for instance in <a href="http://www.eeaax.polytechnique.fr/EO/eo/tutorial/html/SecondBitEA.html#random">Lesson3</a>
|
||||
(and after).</li>
|
||||
</ul>
|
||||
As RNGs produce, by definition, integers that are uniformly distributed
|
||||
between 0 and some maximal number, EO provides you with random numbers
|
||||
following <b><font color="#FF6600">different probability distribution</font></b>
|
||||
(e.g. floating point following <font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/class_eorng.html#a8">normal
|
||||
distribution</a></font></font>). See the <a href="../../doc/html/class_eorng.html">complete
|
||||
(e.g. floating point following <font face="Arial,Helvetica"><font size=+1><a href="http://www.eeaax.polytechnique.fr/EO/eo/doc/html/class_eorng.html#a8">normal
|
||||
distribution</a></font></font>). See the <a href="http://www.eeaax.polytechnique.fr/EO/eo/doc/html/class_eorng.html">complete
|
||||
list of RNG primitives</a>.
|
||||
<p>EO also provides <a href="../../doc/html/rnd_generators_h-source.html">random_generators</a>
|
||||
<p>EO also provides <a href="http://www.eeaax.polytechnique.fr/EO/eo/doc/html/rnd_generators_h-source.html">random_generators</a>
|
||||
that can be used in STL call to generate series of random numbers, as in
|
||||
<a href="eoInit.html">eoPop
|
||||
<a href="http://www.eeaax.polytechnique.fr/EO/eo/tutorial/html/eoInit.html">eoPop
|
||||
initializers</a>.
|
||||
<p><b><font color="#FF0000">Note</font></b>: the <b><tt><font color="#993300">eo::</font></tt></b>
|
||||
prefix indicates that it is in a separate C++ namespace, to avoid collision
|
||||
|
|
@ -370,13 +372,7 @@ myfunction(unsigned </font><font color="#FF6600">_popSize</font><font color="#99
|
|||
The initialization parameters of constructors should be named from the
|
||||
names of the variables they are used to initialize, e.g.</li>
|
||||
|
||||
<br>
|
||||
<p>
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
<p><b><tt><font color="#993300">class eoMyClass</font></tt></b>
|
||||
<p><br><b><tt><font color="#993300">class eoMyClass</font></tt></b>
|
||||
<br><b><tt><font color="#993300">{</font></tt></b>
|
||||
<br><b><tt><font color="#993300">public:</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> eoMyClass(unsigned _popSize):</font><font color="#FF6600">popSize(_popSize)</font><font color="#993300">{...}</font></tt></b>
|
||||
|
|
@ -392,8 +388,8 @@ above).</li>
|
|||
The name of the EO template should be EOT. This allows quick understanding
|
||||
of the inheritance diagrams for <a href="#functors">functors</a>. and immediate
|
||||
perception of the arguments and return types of the functors oeprator()
|
||||
method (as in <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/class_eomonop.html">eoMonOp</a></font></font></b>
|
||||
or <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/class_eobinop.html">eoBinOp</a></font></font></b>).</li>
|
||||
method (as in <b><font face="Arial,Helvetica"><font size=+1><a href="http://www.eeaax.polytechnique.fr/EO/eo/doc/html/class_eomonop.html">eoMonOp</a></font></font></b>
|
||||
or <b><font face="Arial,Helvetica"><font size=+1><a href="http://www.eeaax.polytechnique.fr/EO/eo/doc/html/class_eobinop.html">eoBinOp</a></font></font></b>).</li>
|
||||
|
||||
<br>
|
||||
<li>
|
||||
|
|
@ -407,9 +403,11 @@ Blabla</li>
|
|||
numbers</a> - <a href="#notations">EO programming style</a>
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<br><b><font color="#CC0000">General: </font></b><a href="eoTutorial.html">Tutorial
|
||||
main page </a>- <a href="eoTopDown.html">Algorithm-Based</a> - <a href="eoBottomUp.html">Component-Based</a>
|
||||
- <a href="eoProgramming.html">Programming hints</a> - <font face="Arial,Helvetica"><a href="../../doc/html/index.html">EO
|
||||
<br><b><font color="#CC0000">General: </font></b><a href="http://www.eeaax.polytechnique.fr/EO/eo/tutorial/html/eoTutorial.html">Tutorial
|
||||
main page </a>- <a href="http://www.eeaax.polytechnique.fr/EO/eo/tutorial/html/eoTopDown.html">Algorithm-Based</a>
|
||||
- <a href="http://www.eeaax.polytechnique.fr/EO/eo/tutorial/html/eoBottomUp.html">Component-Based</a>
|
||||
- <a href="http://www.eeaax.polytechnique.fr/EO/eo/tutorial/html/eoProgramming.html">Programming
|
||||
hints</a> - <font face="Arial,Helvetica"><a href="http://www.eeaax.polytechnique.fr/EO/eo/doc/html/index.html">EO
|
||||
documentation</a></font>
|
||||
<br>
|
||||
<hr>
|
||||
|
|
|
|||
|
|
@ -157,8 +157,8 @@ rather than when you have something urgent to code :-)</li>
|
|||
|
||||
<hr WIDTH="100%"><a NAME="install"></a><b><font color="#000099"><font size=+1>Before
|
||||
you start</font></font></b>
|
||||
<p>You should of course have downloaded and installed the developement version of the whole <a href="http://www.eeaax.polytechnique.fr/EO/">EO
|
||||
library</a>. Be careful that the tutorial examples will not work with earlier versions of EO, such as the ones that you can find on the <a href="http://eodev.sourceforge.net/">official site</a>.
|
||||
<p>You should of course have downloaded and installed the whole <a href="http://www.sourceforge.net/projects/eodev">EO
|
||||
library</a> (how did you get this file if not???).
|
||||
<br>So we'll assume that you are now in the Tutorial directory, and that
|
||||
your prompt looks something like
|
||||
<p><b><tt><font color="#FF6666">(myname@myhost) EOdir/Tutorial %</font></tt></b>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue