int GA2DBinaryStringGenome::read(STD_ISTREAM & is) { static char c; unsigned int i=0, j=0; while(!is.fail() && !is.eof() && j < ny) { is >> c; if(isdigit(c)){ gene(i, j, ((c == '0') ? 0 : 1)); if(++i >= nx){ // ready for next row i=0; j++; } } } _evaluated = gaFalse; if(is.eof() && ((j < ny) || // didn't get some lines (i < nx && i != 0))){ // stopped early on a row GAErr(GA_LOC, className(), "read", gaErrUnexpectedEOF); is.clear(STD_IOS_BADBIT | is.rdstate()); return 1; } return 0; }
// The read specialization takes in each number and stuffs it into the array. template <> int GA1DArrayAlleleGenome<float>::read(STD_ISTREAM & is) { unsigned int i=0; float val; do{ is >> val; if(!is.fail()) gene(i++, val); } while(!is.fail() && !is.eof() && i < nx); if(is.eof() && i < nx){ GAErr(GA_LOC, className(), "read", gaErrUnexpectedEOF); is.clear(STD_IOS_BADBIT | is.rdstate()); return 1; } return 0; }
// We read data from a stream as a series of 1's and 0's. We want a continuous // stream (ie no spaces) but if there are spaces then we can handle them. We // ignore all whitespace. We ignore anything that is not a digit. If it is a // zero then we set to zero. Anything else is a 1. int GA1DBinaryStringGenome::read(STD_ISTREAM & is) { static char c; unsigned int i=0; while(!is.fail() && !is.eof() && i<nx) { is >> c; if(isdigit(c)) gene(i++, ((c == '0') ? 0 : 1)); } _evaluated = gaFalse; if(is.eof() && i < nx){ GAErr(GA_LOC, className(), "read", gaErrUnexpectedEOF); is.clear(STD_IOS_BADBIT | is.rdstate()); return 1; } return 0; }