warning hunting

This commit is contained in:
gustavo 2000-05-25 11:03:00 +00:00
commit 0363af1289
13 changed files with 153 additions and 145 deletions

View file

@ -40,31 +40,32 @@
template <class EOT> template <class EOT>
class eoDetTournamentInserter : public eoSteadyStateInserter<EOT> class eoDetTournamentInserter : public eoSteadyStateInserter<EOT>
{ {
public : public :
eoDetTournamentInserter(eoEvalFunc<EOT>& _eval, unsigned _t_size) : t_size(_t_size), eoSteadyStateInserter<EOT>(_eval) eoDetTournamentInserter(eoEvalFunc<EOT>& _eval, unsigned _t_size):
{ eoSteadyStateInserter<EOT>(_eval),
if (t_size < 2) t_size(_t_size)
{ // warning, error? {
t_size = 2; if (t_size < 2)
} { // warning, error?
} t_size = 2;
}
eoInserter<EOT>& operator()(const EOT& _eot) }
{
EOT& eo = inverse_deterministic_tournament<EOT>(pop(), t_size); eoInserter<EOT>& operator()(const EOT& _eot)
eo = _eot; // overwrite loser of tournament {
EOT& eo = inverse_deterministic_tournament<EOT>(pop(), t_size);
eo.invalidate(); // This line should probably be removed when all genetic operators do this themselves eo = _eot; // overwrite loser of tournament
eval(eo); // Evaluate after insert
return *this; 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 : string className(void) const { return "eoDetTournamentInserter"; }
unsigned t_size; private :
unsigned t_size;
}; };
#endif #endif

View file

@ -35,14 +35,14 @@ class eoGOpBreeder: public eoMonPopOp<EOT>
* @param pop The population to be transformed. * @param pop The population to be transformed.
*/ */
void operator()(eoPop<EOT>& _pop) void operator()(eoPop<EOT>& _pop)
{ {
int size = _pop.size(); unsigned size = _pop.size();
for (unsigned i = 0; i < size; i++) for (unsigned i = 0; i < size; i++)
{ // and the one liner { // and the one liner
opSel.selectOp()(selector.bind(_pop,size).bias(i), inserter.bind(_pop)); opSel.selectOp()(selector.bind(_pop,size).bias(i), inserter.bind(_pop));
}
} }
}
/// The class name. /// The class name.
string className() const { return "eoGOpBreeder"; } string className() const { return "eoGOpBreeder"; }

View file

@ -56,9 +56,9 @@ public:
} }
/* /*
Add any kind of operator to the operator mix, Add any kind of operator to the operator mix,
@param _op operator, one of eoMonOp, eoBinOp, eoQuadraticOp or eoGeneralOp @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 @param _rate the rate at which it should be applied, it should be a probability
*/ */
virtual ID addOp( eoOp<EOT>& _op, float _rate ); virtual ID addOp( eoOp<EOT>& _op, float _rate );
@ -66,12 +66,12 @@ public:
/** Retrieve the operator using its integer handle /** Retrieve the operator using its integer handle
@param _id The id number. Should be a valid id, or an exception @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. @return a reference of the operator corresponding to that id.
*/ */
virtual eoOp<EOT>& getOp( ID _id ) virtual eoOp<EOT>& getOp( ID _id )
{ {
return *operator[](_id); return *operator[](_id);
} }
/// ///
@ -81,7 +81,7 @@ public:
/// ///
virtual eoOp<EOT>* Op() virtual eoOp<EOT>* Op()
{ {
return &selectOp(); return &selectOp();
} }
/// Select an operator from the operators present here /// Select an operator from the operators present here
@ -109,70 +109,70 @@ private :
/* Implementation of longish functions defined above */ /* Implementation of longish functions defined above */
template <class EOT> 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;
eoGeneralOp<EOT>* op;
if (_op.getType() == eoOp<EOT>::general)
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 // 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 // and keep it on a list to delete them afterwards
// will use auto_ptr when they're readily available // 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()) iterator result = find(begin(), end(), (eoGeneralOp<EOT>*) 0); // search for nullpointer
{
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
if (result == end()) if (result == end())
{ {
push_back(op); push_back(op);
rates.push_back(_arg); rates.push_back(_arg);
return size(); return size();
} }
// else // else
*result = op; *result = op;
ID id = result - begin(); ID id = result - begin();
rates[id] = _arg; rates[id] = _arg;
return id; return id;
} }
template <class EOT> template <class EOT>
inline void eoGOpSelector<EOT>::deleteOp( ID _id ) inline void eoGOpSelector<EOT>::deleteOp( ID _id )
{ {
eoGeneralOp<EOT>* op = operator[](_id); eoGeneralOp<EOT>* op = operator[](_id);
operator[](_id) = 0; operator[](_id) = 0;
rates[_id] = 0.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);
} }
} }

View file

@ -35,29 +35,29 @@
template <class EOT> template <class EOT>
class eoSequentialGOpSel : public eoGOpSelector<EOT> class eoSequentialGOpSel : public eoGOpSelector<EOT>
{ {
public : public :
virtual ~eoSequentialGOpSel(void) {} virtual ~eoSequentialGOpSel(void) {}
virtual eoGeneralOp<EOT>& selectOp() virtual eoGeneralOp<EOT>& selectOp()
{ {
combined.clear(); combined.clear();
for (int i = 0; i < size(); ++i) for (unsigned i = 0; i < size(); ++i)
{ {
if (operator[](i) == 0) if (operator[](i) == 0)
continue; continue;
if (rng.flip(getRates()[i])) if (rng.flip(getRates()[i]))
combined.addOp(operator[](i)); combined.addOp(operator[](i));
} }
return combined; return combined;
} }
private : private :
eoCombinedOp<EOT> combined; eoCombinedOp<EOT> combined;
}; };
#endif #endif

View file

@ -40,12 +40,13 @@
template <class EOT> template <class EOT>
class eoSteadyStateInserter : public eoPopInserter<EOT> class eoSteadyStateInserter : public eoPopInserter<EOT>
{ {
public : public :
eoSteadyStateInserter(eoEvalFunc<EOT>& _eval) : eval(_eval) , eoPopInserter<EOT>() {} eoSteadyStateInserter(eoEvalFunc<EOT>& _eval):
eoPopInserter<EOT>(),
protected : eval(_eval) {}
eoEvalFunc<EOT>& eval; protected :
eoEvalFunc<EOT>& eval;
}; };

View file

@ -41,35 +41,36 @@
template <class EOT> template <class EOT>
class eoStochTournamentInserter : public eoSteadyStateInserter<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 >= 1.0)
{ {
if (t_rate < 0.5) t_rate = 0.99; // 1.0 would mean deterministic tournament
{ // warning, error? }
t_rate = 0.55; }
}
if (t_rate >= 1.0)
{
t_rate = 0.99; // 1.0 would mean deterministic tournament
}
}
eoInserter<EOT>& operator()(const EOT& _eot) eoInserter<EOT>& operator()(const EOT& _eot)
{ {
EOT& eo = inverse_stochastic_tournament<EOT>(pop(), t_rate); EOT& eo = inverse_stochastic_tournament<EOT>(pop(), t_rate);
eo = _eot; // overwrite loser of tournament eo = _eot; // overwrite loser of tournament
eo.invalidate(); eo.invalidate();
eval(eo); // Evaluate after insert eval(eo); // Evaluate after insert
return *this; return *this;
} }
string className(void) const { return "eoStochTournamentInserter"; } string className(void) const { return "eoStochTournamentInserter"; }
private : private :
double t_rate; double t_rate;
}; };
#endif #endif

View file

@ -47,7 +47,6 @@ int the_main(int argc, char **argv)
eoParser parser(argc, argv); eoParser parser(argc, argv);
// Define Parameters // 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> rate(0.01, "mutationRatePerBit", "Initial value for mutation rate per bit");
eoValueParam<double> factor(0.99, "mutationFactor", "Decrease factor for mutation rate"); eoValueParam<double> factor(0.99, "mutationFactor", "Decrease factor for mutation rate");
eoValueParam<uint32> seed(time(0), "seed", "Random number seed"); eoValueParam<uint32> seed(time(0), "seed", "Random number seed");
@ -183,4 +182,4 @@ int main(int argc, char **argv)
} }
return 1; return 1;
} }

View file

@ -2,9 +2,10 @@
// t-eoEasyEA.cpp // t-eoEasyEA.cpp
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#ifndef __GNUG__
// to avoid long name warnings // to avoid long name warnings
#pragma warning(disable:4786) #pragma warning(disable:4786)
#endif // __GNUG__
#include <eo> #include <eo>

View file

@ -110,7 +110,7 @@ int main()
eoExternalBinOp<FitnessType, External> cross1(UserDefBinCrossover); eoExternalBinOp<FitnessType, External> cross1(UserDefBinCrossover);
eoExternalQuadraticOp<FitnessType, External> cross2(UserDefQuadCrossover); eoExternalQuadraticOp<FitnessType, External> cross2(UserDefQuadCrossover);
eoExternalEvalFunc<FitnessType, External> eval(UserDefEvalFunc); // eoExternalEvalFunc<FitnessType, External> eval(UserDefEvalFunc);
EoType eo1 = init(); EoType eo1 = init();
EoType eo2 = init(); EoType eo2 = init();
@ -124,4 +124,4 @@ int main()
cross2(eo1,eo2); cross2(eo1,eo2);
return 1; return 1;
}; };

View file

@ -25,8 +25,10 @@
//-----------------------------------------------------------------------------// //-----------------------------------------------------------------------------//
#ifndef __GNUG__
// to avoid long name warnings // to avoid long name warnings
#pragma warning(disable:4786) #pragma warning(disable:4786)
#endif // __GNUG__
#include <iostream> #include <iostream>

View file

@ -41,7 +41,6 @@ int the_main(int argc, char **argv)
eoParser parser(argc, argv); eoParser parser(argc, argv);
// Define Parameters // 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> rate(0.01, "mutationRatePerBit", "Initial value for mutation rate per bit");
eoValueParam<double> factor(0.99, "mutationFactor", "Decrease factor for mutation rate"); eoValueParam<double> factor(0.99, "mutationFactor", "Decrease factor for mutation rate");
eoValueParam<uint32> seed(time(0), "seed", "Random number seed"); eoValueParam<uint32> seed(time(0), "seed", "Random number seed");
@ -120,4 +119,4 @@ int main(int argc, char **argv)
} }
return 1; return 1;
} }

View file

@ -24,8 +24,10 @@
*/ */
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#ifndef __GNUG__
// to avoid long name warnings // to avoid long name warnings
#pragma warning(disable:4786) #pragma warning(disable:4786)
#endif // __GNUG__
#include <ga/eoBin.h> // eoBin, eoPop, eoBreeder #include <ga/eoBin.h> // eoBin, eoPop, eoBreeder
#include <eoPop.h> #include <eoPop.h>

View file

@ -24,8 +24,10 @@
*/ */
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#ifndef __GNUG__
// to avoid long name warnings // to avoid long name warnings
#pragma warning(disable:4786) #pragma warning(disable:4786)
#endif // __GNUG__
#include <ga/eoBin.h> // eoBin, eoPop, eoBreeder #include <ga/eoBin.h> // eoBin, eoPop, eoBreeder
#include <eoPop.h> #include <eoPop.h>