// just a function which converts integers to strings // and pads with zeros; for saving photos... func string f(int i, int len){ string ss = i; int nn = ss.length; for(int i=0;ioptv){ // if this configuration is better then advance xx = xx+epst*ar1; yy = yy+epst*ar2; optv = ev[0]; if(makemovie==1){ // if makemovie then save each figure in png format string nh = nhole; string photo = "holes"+nh+"_"+f(iter,4)+".png"; plot(eV[0],fill=true,wait=true,ShowAxes = 0,ps = photo); } else{ // else just plot the figure plot(eV[0],fill=true,wait=true,ShowAxes = 0,value =true ); } cout << iter << " " << epst << " " << ev[0] << endl; epst = 1.2*epst; if(epst>0.01) epst = 0.01; iter = iter+1; } else{ // else decrease the step size epst = epst*0.8; if(epst<1e-10) break; // perturb values a bit to avoid local minima xx = xx+epst/1000*ar1; yy = yy+epst/1000*ar2; optv = ev[0]; } }