void tAgent::setupRandomAgent(int nucleotides){ int i; genome.resize(nucleotides); for(i=0;i<nucleotides;i++) genome[i]=127;//rand()&255; ampUpStartCodons(); setupPhenotype(); }
void tAgent::loadAgent(char* filename){ FILE *f=fopen(filename,"r+t"); int i; genome.clear(); while(!(feof(f))){ fscanf(f,"%i ",&i); genome.push_back((unsigned char)(i&255)); } setupPhenotype(); }
void tAgent::loadAgentWithTrailer(char* filename){ #ifdef useANN ANN=new tANN; ANN->load(filename); #else FILE *f=fopen(filename,"r+t"); int i; genome.clear(); fscanf(f,"%i ",&i); while(!(feof(f))){ fscanf(f,"%i ",&i); genome.push_back((unsigned char)(i&255)); } setupPhenotype(); #endif }
void tAgent::inherit(tAgent *from,double mutationRate,int theTime){ int i,s,o,w; int nucleotides; vector<unsigned char> buffer; born=theTime; dormancyPeriod = from->dormancyPeriod; if (randDouble < 0.05) { dormancyPeriod += (int)(randDouble * 20.0) - 10; dormancyPeriod = max(dormancyPeriod, 0); } ancestor=from; from->nrPointingAtMe++; nucleotides=(int)from->genome.size(); genome.clear(); genome.resize(nucleotides); for(i=0;i<nucleotides;i++) if(randDouble<mutationRate) genome[i]=rand()&255; else genome[i]=from->genome[i]; if((randDouble<0.05)&&(genome.size()<20000)){ //duplication w=15+rand()&511; s=rand()%((int)genome.size()-w); o=rand()%(int)genome.size(); buffer.clear(); buffer.insert(buffer.begin(),genome.begin()+s,genome.begin()+s+w); genome.insert(genome.begin()+o,buffer.begin(),buffer.end()); } if((randDouble<0.02)&&(genome.size()>1000)){ //deletion w=15+rand()&511; s=rand()%((int)genome.size()-w); genome.erase(genome.begin()+s,genome.begin()+s+w); } setupPhenotype(); fitness=0.0; }
void tAgent::inherit(tAgent *from,double mutationRate,int theTime){ int nucleotides=from->genome.size(); int i,s,o,w; double localMutationRate=4.0/from->genome.size(); vector<unsigned char> buffer; born=theTime; ancestor=from; from->nrPointingAtMe++; from->nrOfOffspring++; genome.clear(); genome.resize(from->genome.size()); for(i=0;i<nucleotides;i++) if(((double)rand()/(double)RAND_MAX)<mutationRate) genome[i]=rand()&255; else genome[i]=from->genome[i]; if((((double)rand()/(double)RAND_MAX)<0.05)&&(genome.size()<20000)){ //duplication w=15+rand()&511; s=rand()%(genome.size()-w); o=rand()%genome.size(); buffer.clear(); buffer.insert(buffer.begin(),genome.begin()+s,genome.begin()+s+w); genome.insert(genome.begin()+o,buffer.begin(),buffer.end()); } if((((double)rand()/(double)RAND_MAX)<0.02)&&(genome.size()>1000)){ //deletion w=15+rand()&511; s=rand()%(genome.size()-w); genome.erase(genome.begin()+s,genome.begin()+s+w); } setupPhenotype(); fitness=0.0; #ifdef useANN ANN->inherit(ancestor->ANN,mutationRate); #endif }