Ok, made an eoParetoFitness class, which meant that I could roll back a few changes in EO.h (phew).

Also changed eoSelectFromWorth etc.
This commit is contained in:
maartenkeijzer 2001-03-16 12:08:26 +00:00
commit d09c216b61
11 changed files with 215 additions and 110 deletions

View file

@ -3,7 +3,7 @@
//-----------------------------------------------------------------------------
// EO.h
// (c) 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
@ -31,61 +31,6 @@
#include <eoObject.h> // eoObject
#include <eoPersistent.h> // eoPersistent
/// Functions for reading and writing non-scalar fitnesses, should probably go to seperate file
template <class T>
ostream& print_fitness(ostream& _os, const std::vector<T>& vec)
{
_os << vec.size() << ' ';
std::copy(vec.begin(), vec.end(), ostream_iterator<T>(_os));
return _os;
}
/// Functions for reading and writing non-scalar fitnesses, should probably go to seperate file
template <class T, class U>
ostream& print_fitness(ostream& _os, const std::pair<T, U>& pair)
{
return _os << pair.first << ' ' << pair.second;
}
/// Functions for reading and writing non-scalar fitnesses, should probably go to seperate file
template <class T>
ostream& print_fitness(ostream& _os, const T& t)
{ // general, try operator<<
return _os << t;
}
/// Functions for reading and writing non-scalar fitnesses, should probably go to seperate file
template <class T>
istream& read_fitness(istream& _is, vector<T>& vec)
{
unsigned sz;
_is >> sz;
vec.resize(sz);
for (unsigned i = 0; i < vec.size(); ++i)
{
_is >> vec[i];
}
return _is;
}
/// Functions for reading and writing non-scalar fitnesses, should probably go to seperate file
template <class T, class U>
istream& read_fitness(istream& _is, pair<T, U>& pair)
{
_is >> pair.first;
_is >> pair.second;
return _is;
}
/// Functions for reading and writing non-scalar fitnesses, should probably go to seperate file
template <class T>
istream& read_fitness(istream& _is, T& t)
{
_is >> t;
return _is;
}
//-----------------------------------------------------------------------------
/** EO is a base class for evolvable objects, that is, the subjects of
evolution. EOs have only got a fitness, which at the same time needs to be
@ -158,7 +103,7 @@ public:
* @throw runtime_exception If a valid object can't be read.
*/
virtual void readFrom(istream& _is) {
read_fitness(_is, repFitness);
_is >> repFitness;
if (_is)
invalidFitness = false;
else
@ -173,7 +118,7 @@ public:
if (invalid())
_os << "INVALID ";
else
print_fitness(_os, repFitness) << ' '; // trailing space to make reading in that much easier
_os << repFitness << ' '; // trailing space to make reading in that much easier
}
//@}
@ -186,4 +131,3 @@ private:
//-----------------------------------------------------------------------------
#endif EO_H