Extreme cleanup, see src/obsolete for details

This commit is contained in:
mac 2000-08-10 14:18:34 +00:00
commit 6d8e3a6504
141 changed files with 3937 additions and 1815 deletions

View file

@ -27,7 +27,8 @@
#include <iostream> // ostream, istream
#include <functional> // bind2nd
#include <string> // string
#include <eoVector.h> // EO
#include <eoFixedLength.h>
/**
\defgroup bitstring
@ -38,9 +39,9 @@
/** eoBin: implementation of binary chromosome.
\class eoBin eoBin.h ga/eoBin.h
\ingroup bitstring
* based on STL's bit_vector (vector<bool>).
* based on STL's vector<bool> specialization.
*/
template <class F> class eoBin: public eoVector<bool, F>
template <class F> class eoBin: public eoFixedLength<F, bool>
{
public:
@ -49,21 +50,8 @@ template <class F> class eoBin: public eoVector<bool, F>
* @param size Size of the binary string.
*/
eoBin(unsigned size = 0, bool value = false):
eoVector<bool,F>(size, value) {}
/**
* Constructor.
* @param size Size of the binary string.
*/
eoBin(unsigned size, const eoRnd<bool>& rnd): eoVector<bool,F>(size)
{
generate(begin(), end(), rnd);
}
/** Constructor from istream.
@param is The istream to read from.*/
eoBin(istream& _is):eoVector<bool,F>(_is){};
eoFixedLength<F, bool>(size, value) {}
/// My class name.
string className() const
{
@ -76,6 +64,7 @@ template <class F> class eoBin: public eoVector<bool, F>
*/
void printOn(ostream& os) const
{
os << size() << ' ';
copy(begin(), end(), ostream_iterator<bool>(os));
}
@ -98,4 +87,4 @@ template <class F> class eoBin: public eoVector<bool, F>
//-----------------------------------------------------------------------------
#endif eoBin_h
#endif //eoBin_h

View file

@ -9,45 +9,8 @@
#include <algorithm> // swap_ranges
#include <utils/eoRNG.h>
#include <ga/eoBin.h> // eoBin
#include <eoOp.h> // eoMonOp
/** @name BitWise Genetic operators
\class eoBinRandom eoBitOp.h ga/eoBitOp.h
\ingroup bitstring
Even as these operators might seem general, they are particular versions of genetic
operators useful only for binary operators. As any set of genetic operators, it must
have a factory that knows how to build them from a description
@author GeNeura Team
@version 0.1
@see eoBin
@see eoBitOpFactory
*/
//@{
/** eoBinRandom --> mofify a chromosome in a random way */
template<class Chrom> class eoBinRandom: public eoMonOp<Chrom>
{
public:
/// The class name.
string className() const { return "eoBinRandom"; }
/**
* Randomizes a cromosome.
* @param chrom The cromosome to be randomize.
*/
void operator()(Chrom& chrom) const
{
for (unsigned i = 0; i < chrom.size(); i++)
chrom[i] = rng.flip(0.5) ? false : true;
}
};
#include <eoInit.h> // eoMonOp
#include <ga/eoBin.h>
/** eoBinBitFlip --> changes a bit
\class eoBinBitFlip eoBitOp.h ga/eoBitOp.h
@ -64,8 +27,9 @@ template<class Chrom> class eoBinBitFlip: public eoMonOp<Chrom>
* Change one bit.
* @param chrom The cromosome which one bit is going to be changed.
*/
void operator()(Chrom& chrom) const
void operator()(Chrom& chrom)
{
chrom.invalidate();
unsigned i = rng.random(chrom.size());
chrom[i] = (chrom[i]) ? false : true;
}
@ -93,11 +57,18 @@ template<class Chrom> class eoBinMutation: public eoMonOp<Chrom>
* Mutate a chromosome.
* @param chrom The chromosome to be mutated.
*/
void operator()(Chrom& chrom) const
void operator()(Chrom& chrom)
{
bool changed_something = false;
for (unsigned i = 0; i < chrom.size(); i++)
if (rng.flip(rate))
chrom[i] = !chrom[i];
if (rng.flip(rate))
{
chrom[i] = !chrom[i];
changed_something = true;
}
if (changed_something)
chrom.invalidate();
}
private:
@ -120,7 +91,7 @@ template<class Chrom> class eoBinInversion: public eoMonOp<Chrom>
* Inverts a range of bits in a binary chromosome.
* @param chrom The chromosome whos bits are going to be inverted (a range).
*/
void operator()(Chrom& chrom) const
void operator()(Chrom& chrom)
{
unsigned u1 = rng.random(chrom.size() + 1) , u2;
@ -128,6 +99,7 @@ template<class Chrom> class eoBinInversion: public eoMonOp<Chrom>
unsigned r1 = min(u1, u2), r2 = max(u1, u2);
reverse(chrom.begin() + r1, chrom.begin() + r2);
chrom.invalidate();
}
};
@ -147,7 +119,7 @@ template<class Chrom> class eoBinNext: public eoMonOp<Chrom>
* Change the bit string x to be x+1.
* @param chrom The chromosome to be added one.
*/
void operator()(Chrom& chrom) const
void operator()(Chrom& chrom)
{
for (int i = chrom.size() - 1; i >= 0; i--)
if (chrom[i])
@ -160,6 +132,8 @@ template<class Chrom> class eoBinNext: public eoMonOp<Chrom>
chrom[i] = 1;
break;
}
chrom.invalidate();
}
};
@ -179,7 +153,7 @@ template<class Chrom> class eoBinPrev: public eoMonOp<Chrom>
* Change the bit string x to be x-1.
* @param chrom The chromosome to be substracted one.
*/
void operator()(Chrom& chrom) const
void operator()(Chrom& chrom)
{
for (int i = chrom.size() - 1; i >= 0; i--)
if (chrom[i])
@ -192,6 +166,8 @@ template<class Chrom> class eoBinPrev: public eoMonOp<Chrom>
chrom[i] = 1;
continue;
}
chrom.invalidate();
}
};
@ -212,10 +188,19 @@ template<class Chrom> class eoBinCrossover: public eoQuadraticOp<Chrom>
* @param chrom1 The first chromosome.
* @param chrom2 The first chromosome.
*/
void operator()(Chrom& chrom1, Chrom& chrom2) const
void operator()(Chrom& chrom1, Chrom& chrom2)
{
swap_ranges(chrom1.begin(), chrom1.begin() + rng.random(min(chrom1.size(), chrom2.size())), chrom2.begin());
}
unsigned site = rng.random(min(chrom1.size(), chrom2.size()));
if (std::equal(chrom1.begin(), chrom1.begin()+site, chrom2.begin()))
{
swap_ranges(chrom1.begin(), chrom1.begin() + site, chrom2.begin());
chrom1.invalidate();
chrom2.invalidate();
}
}
};
@ -242,7 +227,7 @@ template<class Chrom> class eoBinNxOver: public eoQuadraticOp<Chrom>
* @param chrom1 The first chromosome.
* @param chrom2 The first chromosome.
*/
void operator()(Chrom& chrom1, Chrom& chrom2) const
void operator()(Chrom& chrom1, Chrom& chrom2)
{
unsigned max_size = min(chrom1.size(), chrom2.size());
unsigned max_points = min(max_size - 1, num_points);
@ -272,6 +257,9 @@ template<class Chrom> class eoBinNxOver: public eoQuadraticOp<Chrom>
if (change)
swap(chrom1[bit], chrom2[bit]);
}
chrom1.invalidate();
chrom2.invalidate();
}
private:
@ -305,7 +293,7 @@ template<class Chrom> class eoBinGxOver: public eoQuadraticOp<Chrom>
* @param chrom1 The first chromosome.
* @param chrom2 The first chromosome.
*/
void operator()(Chrom& chrom1, Chrom& chrom2) const
void operator()(Chrom& chrom1, Chrom& chrom2)
{
unsigned max_genes = min(chrom1.size(), chrom2.size()) / gene_size;
unsigned cut_genes = min(max_genes, num_points);
@ -330,7 +318,10 @@ template<class Chrom> class eoBinGxOver: public eoQuadraticOp<Chrom>
swap_ranges(chrom1.begin() + i * gene_size,
chrom1.begin() + i * gene_size + gene_size,
chrom2.begin() + i * gene_size);
}
chrom1.invalidate();
chrom2.invalidate();
}
private:
unsigned gene_size;

View file

@ -36,7 +36,8 @@ 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 eoOpFactory<EOT>
{
public:
@ -59,7 +60,8 @@ public:
@param _is an stream from where a single line will be read
@throw runtime_exception if the object type is not known
*/
virtual eoOp<EOT>* make(istream& _is) {
virtual eoOp<EOT>* make(istream& _is)
{
eoOp<EOT> * opPtr = NULL;
try {
opPtr = eoOpFactory<EOT>::make( _is );