warning hunting
This commit is contained in:
parent
9aaafc2cdb
commit
0363af1289
13 changed files with 153 additions and 145 deletions
|
|
@ -40,31 +40,32 @@
|
|||
template <class EOT>
|
||||
class eoDetTournamentInserter : public eoSteadyStateInserter<EOT>
|
||||
{
|
||||
public :
|
||||
|
||||
eoDetTournamentInserter(eoEvalFunc<EOT>& _eval, unsigned _t_size) : t_size(_t_size), eoSteadyStateInserter<EOT>(_eval)
|
||||
{
|
||||
if (t_size < 2)
|
||||
{ // warning, error?
|
||||
t_size = 2;
|
||||
}
|
||||
}
|
||||
|
||||
eoInserter<EOT>& operator()(const EOT& _eot)
|
||||
{
|
||||
EOT& eo = inverse_deterministic_tournament<EOT>(pop(), t_size);
|
||||
eo = _eot; // overwrite loser of tournament
|
||||
|
||||
eo.invalidate(); // This line should probably be removed when all genetic operators do this themselves
|
||||
eval(eo); // Evaluate after insert
|
||||
return *this;
|
||||
}
|
||||
|
||||
string className(void) const { return "eoDetTournamentInserter"; }
|
||||
|
||||
private :
|
||||
|
||||
unsigned t_size;
|
||||
public :
|
||||
|
||||
eoDetTournamentInserter(eoEvalFunc<EOT>& _eval, unsigned _t_size):
|
||||
eoSteadyStateInserter<EOT>(_eval),
|
||||
t_size(_t_size)
|
||||
{
|
||||
if (t_size < 2)
|
||||
{ // warning, error?
|
||||
t_size = 2;
|
||||
}
|
||||
}
|
||||
|
||||
eoInserter<EOT>& operator()(const EOT& _eot)
|
||||
{
|
||||
EOT& eo = inverse_deterministic_tournament<EOT>(pop(), t_size);
|
||||
eo = _eot; // overwrite loser of tournament
|
||||
|
||||
eo.invalidate(); // This line should probably be removed when all genetic operators do this themselves
|
||||
eval(eo); // Evaluate after insert
|
||||
return *this;
|
||||
}
|
||||
|
||||
string className(void) const { return "eoDetTournamentInserter"; }
|
||||
|
||||
private :
|
||||
unsigned t_size;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -35,14 +35,14 @@ class eoGOpBreeder: public eoMonPopOp<EOT>
|
|||
* @param pop The population to be transformed.
|
||||
*/
|
||||
void operator()(eoPop<EOT>& _pop)
|
||||
{
|
||||
int size = _pop.size();
|
||||
|
||||
{
|
||||
unsigned size = _pop.size();
|
||||
|
||||
for (unsigned i = 0; i < size; i++)
|
||||
{ // and the one liner
|
||||
opSel.selectOp()(selector.bind(_pop,size).bias(i), inserter.bind(_pop));
|
||||
}
|
||||
{ // and the one liner
|
||||
opSel.selectOp()(selector.bind(_pop,size).bias(i), inserter.bind(_pop));
|
||||
}
|
||||
}
|
||||
|
||||
/// The class name.
|
||||
string className() const { return "eoGOpBreeder"; }
|
||||
|
|
|
|||
|
|
@ -56,9 +56,9 @@ public:
|
|||
}
|
||||
|
||||
/*
|
||||
Add any kind of operator to the operator mix,
|
||||
@param _op operator, one of eoMonOp, eoBinOp, eoQuadraticOp or eoGeneralOp
|
||||
@param _rate the rate at which it should be applied, it should be a probability
|
||||
Add any kind of operator to the operator mix,
|
||||
@param _op operator, one of eoMonOp, eoBinOp, eoQuadraticOp or eoGeneralOp
|
||||
@param _rate the rate at which it should be applied, it should be a probability
|
||||
|
||||
*/
|
||||
virtual ID addOp( eoOp<EOT>& _op, float _rate );
|
||||
|
|
@ -66,12 +66,12 @@ public:
|
|||
|
||||
/** Retrieve the operator using its integer handle
|
||||
@param _id The id number. Should be a valid id, or an exception
|
||||
will be thrown
|
||||
will be thrown
|
||||
@return a reference of the operator corresponding to that id.
|
||||
*/
|
||||
virtual eoOp<EOT>& getOp( ID _id )
|
||||
{
|
||||
return *operator[](_id);
|
||||
return *operator[](_id);
|
||||
}
|
||||
|
||||
///
|
||||
|
|
@ -81,7 +81,7 @@ public:
|
|||
///
|
||||
virtual eoOp<EOT>* Op()
|
||||
{
|
||||
return &selectOp();
|
||||
return &selectOp();
|
||||
}
|
||||
|
||||
/// Select an operator from the operators present here
|
||||
|
|
@ -109,70 +109,70 @@ private :
|
|||
/* Implementation of longish functions defined above */
|
||||
|
||||
template <class EOT>
|
||||
inline eoOpSelector<EOT>::ID eoGOpSelector<EOT>::addOp( eoOp<EOT>& _op, float _arg )
|
||||
inline eoOpSelector<EOT>::ID eoGOpSelector<EOT>::addOp( eoOp<EOT>& _op,
|
||||
float _arg )
|
||||
{
|
||||
|
||||
eoGeneralOp<EOT>* op;
|
||||
|
||||
if (_op.getType() == eoOp<EOT>::general)
|
||||
eoGeneralOp<EOT>* op;
|
||||
|
||||
if (_op.getType() == eoOp<EOT>::general)
|
||||
{
|
||||
op = static_cast<eoGeneralOp<EOT>*>(&_op);
|
||||
op = static_cast<eoGeneralOp<EOT>*>(&_op);
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
// if it's not a general op, it's a "old" op; create a wrapped op from it
|
||||
// and keep it on a list to delete them afterwards
|
||||
// will use auto_ptr when they're readily available
|
||||
// if it's not a general op, it's a "old" op; create a wrapped op from it
|
||||
// and keep it on a list to delete them afterwards
|
||||
// will use auto_ptr when they're readily available
|
||||
|
||||
switch(_op.getType())
|
||||
{
|
||||
case eoOp<EOT>::unary :
|
||||
op= new eoWrappedMonOp<EOT>(static_cast<eoMonOp<EOT>&>(_op));
|
||||
break;
|
||||
case eoOp<EOT>::binary :
|
||||
op = new eoWrappedBinOp<EOT>(static_cast<eoBinOp<EOT>&>(_op));
|
||||
break;
|
||||
case eoOp<EOT>::quadratic :
|
||||
op = new eoWrappedQuadraticOp<EOT>(static_cast<eoQuadraticOp<EOT>&>(_op));
|
||||
break;
|
||||
}
|
||||
ownOpList.push_back( op );
|
||||
}
|
||||
|
||||
// Now 'op' is a general operator, either because '_op' was one or
|
||||
// because we wrapped it in an appropriate wrapper in the code above.
|
||||
|
||||
switch(_op.getType())
|
||||
{
|
||||
case eoOp<EOT>::unary :
|
||||
op= new eoWrappedMonOp<EOT>(static_cast<eoMonOp<EOT>&>(_op));
|
||||
break;
|
||||
case eoOp<EOT>::binary :
|
||||
op = new eoWrappedBinOp<EOT>(static_cast<eoBinOp<EOT>&>(_op));
|
||||
break;
|
||||
case eoOp<EOT>::quadratic :
|
||||
op = new eoWrappedQuadraticOp<EOT>(static_cast<eoQuadraticOp<EOT>&>(_op));
|
||||
break;
|
||||
}
|
||||
ownOpList.push_back( op );
|
||||
}
|
||||
|
||||
// Now 'op' is a general operator, either because '_op' was one or
|
||||
// because we wrapped it in an appropriate wrapper in the code above.
|
||||
|
||||
iterator result = find(begin(), end(), (eoGeneralOp<EOT>*) 0); // search for nullpointer
|
||||
iterator result = find(begin(), end(), (eoGeneralOp<EOT>*) 0); // search for nullpointer
|
||||
|
||||
if (result == end())
|
||||
{
|
||||
push_back(op);
|
||||
rates.push_back(_arg);
|
||||
return size();
|
||||
}
|
||||
// else
|
||||
if (result == end())
|
||||
{
|
||||
push_back(op);
|
||||
rates.push_back(_arg);
|
||||
return size();
|
||||
}
|
||||
// else
|
||||
|
||||
*result = op;
|
||||
ID id = result - begin();
|
||||
rates[id] = _arg;
|
||||
return id;
|
||||
*result = op;
|
||||
ID id = result - begin();
|
||||
rates[id] = _arg;
|
||||
return id;
|
||||
}
|
||||
|
||||
template <class EOT>
|
||||
inline void eoGOpSelector<EOT>::deleteOp( ID _id )
|
||||
{
|
||||
eoGeneralOp<EOT>* op = operator[](_id);
|
||||
eoGeneralOp<EOT>* op = operator[](_id);
|
||||
|
||||
operator[](_id) = 0;
|
||||
rates[_id] = 0.0;
|
||||
operator[](_id) = 0;
|
||||
rates[_id] = 0.0;
|
||||
|
||||
// check oplist and clear it there too.
|
||||
// check oplist and clear it there too.
|
||||
|
||||
list< eoGeneralOp<EOT>* >::iterator it = find(ownOpList.begin(), ownOpList.end(), op);
|
||||
list< eoGeneralOp<EOT>* >::iterator it = find(ownOpList.begin(), ownOpList.end(), op);
|
||||
|
||||
if(it != ownOpList.end())
|
||||
if(it != ownOpList.end())
|
||||
{
|
||||
ownOpList.erase(it);
|
||||
ownOpList.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,29 +35,29 @@
|
|||
template <class EOT>
|
||||
class eoSequentialGOpSel : public eoGOpSelector<EOT>
|
||||
{
|
||||
public :
|
||||
|
||||
virtual ~eoSequentialGOpSel(void) {}
|
||||
|
||||
virtual eoGeneralOp<EOT>& selectOp()
|
||||
{
|
||||
combined.clear();
|
||||
|
||||
for (int i = 0; i < size(); ++i)
|
||||
{
|
||||
if (operator[](i) == 0)
|
||||
continue;
|
||||
|
||||
if (rng.flip(getRates()[i]))
|
||||
combined.addOp(operator[](i));
|
||||
}
|
||||
|
||||
return combined;
|
||||
}
|
||||
|
||||
private :
|
||||
|
||||
eoCombinedOp<EOT> combined;
|
||||
public :
|
||||
|
||||
virtual ~eoSequentialGOpSel(void) {}
|
||||
|
||||
virtual eoGeneralOp<EOT>& selectOp()
|
||||
{
|
||||
combined.clear();
|
||||
|
||||
for (unsigned i = 0; i < size(); ++i)
|
||||
{
|
||||
if (operator[](i) == 0)
|
||||
continue;
|
||||
|
||||
if (rng.flip(getRates()[i]))
|
||||
combined.addOp(operator[](i));
|
||||
}
|
||||
|
||||
return combined;
|
||||
}
|
||||
|
||||
private :
|
||||
|
||||
eoCombinedOp<EOT> combined;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -40,12 +40,13 @@
|
|||
template <class EOT>
|
||||
class eoSteadyStateInserter : public eoPopInserter<EOT>
|
||||
{
|
||||
public :
|
||||
eoSteadyStateInserter(eoEvalFunc<EOT>& _eval) : eval(_eval) , eoPopInserter<EOT>() {}
|
||||
|
||||
protected :
|
||||
|
||||
eoEvalFunc<EOT>& eval;
|
||||
public :
|
||||
eoSteadyStateInserter(eoEvalFunc<EOT>& _eval):
|
||||
eoPopInserter<EOT>(),
|
||||
eval(_eval) {}
|
||||
|
||||
protected :
|
||||
eoEvalFunc<EOT>& eval;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -41,35 +41,36 @@
|
|||
template <class EOT>
|
||||
class eoStochTournamentInserter : public eoSteadyStateInserter<EOT>
|
||||
{
|
||||
public :
|
||||
public :
|
||||
|
||||
eoStochTournamentInserter(eoEvalFunc<EOT>& _eval, double _t_rate):
|
||||
eoSteadyStateInserter<EOT>(_eval), t_rate(_t_rate)
|
||||
{
|
||||
if (t_rate < 0.5)
|
||||
{ // warning, error?
|
||||
t_rate = 0.55;
|
||||
}
|
||||
|
||||
eoStochTournamentInserter(eoEvalFunc<EOT>& _eval, double _t_rate) : t_rate(_t_rate), eoSteadyStateInserter<EOT>(_eval)
|
||||
{
|
||||
if (t_rate < 0.5)
|
||||
{ // warning, error?
|
||||
t_rate = 0.55;
|
||||
}
|
||||
|
||||
if (t_rate >= 1.0)
|
||||
{
|
||||
t_rate = 0.99; // 1.0 would mean deterministic tournament
|
||||
}
|
||||
}
|
||||
if (t_rate >= 1.0)
|
||||
{
|
||||
t_rate = 0.99; // 1.0 would mean deterministic tournament
|
||||
}
|
||||
}
|
||||
|
||||
eoInserter<EOT>& operator()(const EOT& _eot)
|
||||
{
|
||||
EOT& eo = inverse_stochastic_tournament<EOT>(pop(), t_rate);
|
||||
eo = _eot; // overwrite loser of tournament
|
||||
eoInserter<EOT>& operator()(const EOT& _eot)
|
||||
{
|
||||
EOT& eo = inverse_stochastic_tournament<EOT>(pop(), t_rate);
|
||||
eo = _eot; // overwrite loser of tournament
|
||||
|
||||
eo.invalidate();
|
||||
eval(eo); // Evaluate after insert
|
||||
return *this;
|
||||
}
|
||||
eo.invalidate();
|
||||
eval(eo); // Evaluate after insert
|
||||
return *this;
|
||||
}
|
||||
|
||||
string className(void) const { return "eoStochTournamentInserter"; }
|
||||
string className(void) const { return "eoStochTournamentInserter"; }
|
||||
|
||||
private :
|
||||
double t_rate;
|
||||
private :
|
||||
double t_rate;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -47,7 +47,6 @@ int the_main(int argc, char **argv)
|
|||
eoParser parser(argc, argv);
|
||||
|
||||
// Define Parameters
|
||||
eoValueParam<unsigned>& chrom_size = parser.createParam(unsigned(2), "chrom-size", "Chromosome size");
|
||||
eoValueParam<double> rate(0.01, "mutationRatePerBit", "Initial value for mutation rate per bit");
|
||||
eoValueParam<double> factor(0.99, "mutationFactor", "Decrease factor for mutation rate");
|
||||
eoValueParam<uint32> seed(time(0), "seed", "Random number seed");
|
||||
|
|
@ -183,4 +182,4 @@ int main(int argc, char **argv)
|
|||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,10 @@
|
|||
// t-eoEasyEA.cpp
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __GNUG__
|
||||
// to avoid long name warnings
|
||||
#pragma warning(disable:4786)
|
||||
|
||||
#endif // __GNUG__
|
||||
|
||||
#include <eo>
|
||||
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ int main()
|
|||
eoExternalBinOp<FitnessType, External> cross1(UserDefBinCrossover);
|
||||
eoExternalQuadraticOp<FitnessType, External> cross2(UserDefQuadCrossover);
|
||||
|
||||
eoExternalEvalFunc<FitnessType, External> eval(UserDefEvalFunc);
|
||||
// eoExternalEvalFunc<FitnessType, External> eval(UserDefEvalFunc);
|
||||
|
||||
EoType eo1 = init();
|
||||
EoType eo2 = init();
|
||||
|
|
@ -124,4 +124,4 @@ int main()
|
|||
cross2(eo1,eo2);
|
||||
|
||||
return 1;
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -25,8 +25,10 @@
|
|||
|
||||
//-----------------------------------------------------------------------------//
|
||||
|
||||
#ifndef __GNUG__
|
||||
// to avoid long name warnings
|
||||
#pragma warning(disable:4786)
|
||||
#endif // __GNUG__
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
|
|
|||
|
|
@ -41,7 +41,6 @@ int the_main(int argc, char **argv)
|
|||
eoParser parser(argc, argv);
|
||||
|
||||
// Define Parameters
|
||||
eoValueParam<unsigned>& chrom_size = parser.createParam(unsigned(2), "chrom-size", "Chromosome size");
|
||||
eoValueParam<double> rate(0.01, "mutationRatePerBit", "Initial value for mutation rate per bit");
|
||||
eoValueParam<double> factor(0.99, "mutationFactor", "Decrease factor for mutation rate");
|
||||
eoValueParam<uint32> seed(time(0), "seed", "Random number seed");
|
||||
|
|
@ -120,4 +119,4 @@ int main(int argc, char **argv)
|
|||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,8 +24,10 @@
|
|||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __GNUG__
|
||||
// to avoid long name warnings
|
||||
#pragma warning(disable:4786)
|
||||
#endif // __GNUG__
|
||||
|
||||
#include <ga/eoBin.h> // eoBin, eoPop, eoBreeder
|
||||
#include <eoPop.h>
|
||||
|
|
|
|||
|
|
@ -24,8 +24,10 @@
|
|||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __GNUG__
|
||||
// to avoid long name warnings
|
||||
#pragma warning(disable:4786)
|
||||
#endif // __GNUG__
|
||||
|
||||
#include <ga/eoBin.h> // eoBin, eoPop, eoBreeder
|
||||
#include <eoPop.h>
|
||||
|
|
|
|||
Reference in a new issue