A new readFrom & printOn function for EO.h

Now it CAN handle VALID/INVALID fitnesses.

The problems are over at last
This commit is contained in:
jeggermo 2002-09-18 12:40:46 +00:00
commit eca6dcef8e

View file

@ -103,11 +103,26 @@ public:
* @throw runtime_exception If a valid object can't be read. * @throw runtime_exception If a valid object can't be read.
*/ */
virtual void readFrom(istream& _is) { virtual void readFrom(istream& _is) {
_is >> repFitness;
if (_is) // the new version of the reafFrom function.
invalidFitness = false; // It can distinguish between valid and invalid fitness values.
else string fitness_str;
throw runtime_error("EO(istream&): can't read valid eo from istream"); int pos = _is.tellg();
_is >> fitness_str;
if (fitness_str == "INVALID")
{
invalidFitness = true;
}
else
{
invalidFitness = false;
_is.seekg(pos); // rewind
_is >> repFitness;
}
} }
/** /**
@ -116,22 +131,16 @@ public:
*/ */
virtual void printOn(ostream& _os) const { virtual void printOn(ostream& _os) const {
//if (invalid())
// _os << "INVALID ";
//else
// From now on, no special case for invalid fitnesses :-)
// A random value would so be printed.
// Even a non-evaluated EO is also serializable ...
// the latest version of the code. Very similar to the old code
// From now on instead of printing an invalid fitness value if (invalid()) {
// a default value is printed (for paradisEO) _os << "INVALID ";
}
if (invalid()) else
_os << Fitness() << ' '; {
else _os << repFitness << ' ';
_os << repFitness << ' '; // trailing space to make reading in that much easier }
} }
//@} //@}