Added support for printing vector<T> as a fitness

This commit is contained in:
maartenkeijzer 2001-03-14 10:13:27 +00:00
commit 3798b665d4
2 changed files with 11 additions and 4 deletions

View file

@ -27,10 +27,11 @@
//-----------------------------------------------------------------------------
#include <stdexcept> // runtime_error
#include <stdexcept> // runtime_error
#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)
{
@ -39,18 +40,21 @@ ostream& print_fitness(ostream& _os, const std::vector<T>& vec)
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)
{
@ -65,6 +69,7 @@ istream& read_fitness(istream& _is, vector<T>& vec)
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)
{
@ -72,6 +77,8 @@ istream& read_fitness(istream& _is, pair<T, U>& pair)
_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)
{

View file

@ -183,8 +183,8 @@ class eoDominanceMap : public eoUF<const eoPop<EoType>&, void>, public std::vect
{
for (unsigned j = 0; j < size(); ++j)
{
if (operator[](i)[j])
result[i]++;
if (operator[](i)[j]) // i dominates j
result[j]++;
}
}
@ -205,7 +205,7 @@ class eoDominanceMap : public eoUF<const eoPop<EoType>&, void>, public std::vect
{
for (unsigned j = 0; j < size(); ++j)
{
if (operator[](j)[i])
if (operator[](i)[j]) // i dominates j
result[i]++;
}
}