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.
string fitness_str;
int pos = _is.tellg();
_is >> fitness_str;
if (fitness_str == "INVALID")
{
invalidFitness = true;
}
else else
throw runtime_error("EO(istream&): can't read valid eo from istream"); {
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 :-) // the latest version of the code. Very similar to the old code
// A random value would so be printed. if (invalid()) {
// Even a non-evaluated EO is also serializable ... _os << "INVALID ";
}
// From now on instead of printing an invalid fitness value
// a default value is printed (for paradisEO)
if (invalid())
_os << Fitness() << ' ';
else else
_os << repFitness << ' '; // trailing space to make reading in that much easier {
_os << repFitness << ' ';
}
} }
//@} //@}