icantgetno
YaBB Newbies
Offline
Posts: 7
Re: calculations slowing down
Reply #3 - Jan 30th , 2010, 4:23am
Code: void draw() { for(int k=0;k<NumberOfSpecimen;k++) UsefulnessArray[k]=func(population3d[k], msx,msy,msz); //filling an array of target function values strr=strongest(UsefulnessArray); //selecting the maximum value out of the array strongestnumber=strr[NumberOfSpecimen-1]; fvalue=func(population3d[strongestnumber], msx,msy,msz); //target function value of the best specimen in a population background(#FFFFFF); if(viewchange!=3) DrawSpecimen(population3d[strongestnumber]); //all the stuff with pushmatrix and popmatrix and visualisation stroke(#000000); fill(#000000); hour_passed=int((time-begintime)/3600); minute_passed=int((time-begintime-3600*hour_passed)/60); second_passed=time-begintime-60*minute_passed-3600*hour_passed; time = hour()*3600+minute()*60+second(); if(time-t_end>19) { t_start=t_end; t_end=time; f_start=f_end; f_end=fvalue; } text ((f_end-f_start)*3+"/min", 500,600); //target function value per minutes output text(fvalue, 50,600); //target function value output text(generations+" generations", 50,650); //generations counter output text (hour_passed+" "+minute_passed+" "+second_passed,500,650); //time passed output begingen++; //viewchange variable is controlled by mouse clicks if(viewchange==1) { fov=int(dist(width/2,height/2,mouseX,mouseY))-300; text("zoom",100,50); } if (viewchange==2) { transparency=int(dist(width/2,height/2,mouseX,mouseY)); text("see through "+ColorTransparencySettings[1],100,50); } if(StopProcess==0) { for(int k=0;k<NumberOfSpecimen/2;k=k+2) //Main part of the algoryrhm. genetic variation. all the calculations that are heavy on memory //Functions child1(),child2(),mutation(),average() include some local variables and arrays. //Is it possible that these variables are not cleared from memory when the function ends? { population3d[strr[k]]=child1(population3d[strr[NumberOfSpecimen/2+k]],population3d[strr[NumberOfSpecimen/2+1+k]]); population3d[strr[k]]=mutation(population3d[strr[k]]); population3d[strr[k+1]]=child2(population3d[strr[NumberOfSpecimen/2+k]],population3d[strr[NumberOfSpecimen/2+1+k]]); population3d[strr[k+1]]=average(mutation(population3d[strr[k+1]])); //population3d[strr[k+1]]=mutation(population3d[strr[k+1]]); } generations++; } }