资源描述:
《投影寻踪蛙跳程序》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
投影寻踪蛙跳程序(c++)(Projectionpursuitleapfrogprocedure(c++))#包括Vstdio.h>#包括《时间。”#包括《窗口。”#包括<<数学。”#包括<<程序。"#定义1/**/试验次数ttdefineG100/*混合迭代次数*/#定义P100/**/个体总数#定义m10/**/族群数#定义我10/**/10因此,一个族群中的个体数是#定义V10/**/个体维数#定义N10/**/族群内更新次数#定义最大1
1#定义通用12#定义GNV//双DMAX=10;/*蛙跳的最大值*///双drain=0.4;/*蛙跳的最大值*/intII、12、13、14,II,III,IA,16,17,国旗;int伟志[P];//分组时起始位置;intbanj=l;〃邻域半径;doublenongchangtgm][gn]={209.99,7264769,52.054525,3793349,905658,11799682,227.94,3757344,34595.786,1166437,18.59,1441043,16.75009,536807,85190,3938662,23.79,180016,77517.106,156845,21.41,1592999,11.232336,396336,19779,3997471,16.40,193343,74404.437,186566,49.39,1623252,27.720342,564935,42154,2885713,29.48,400505,32866.005,276422,125.23,1344442,45.918827,690033,74544,969431,44.55,587015,10735.782,177721,102.89,1425515,39.685307,619805,81930,587346,29.88,324571,13854.748,106836,
251.63,767347,39.581571,285020,33270,426575,20.80,283468,14862.425,81257,49.63,600216,44.138443,429643,70154,309739,16,12,269275,12093.814,78590,36.42,626843,48.930274,415354,78681,195783,26.90,263852,17211.505,85776,34.51,585226,36.474114,434168,39537,473480,14.68,198431,16958.157,65928,46.57,224369,48.286974,161042,33019,105294,11.60,126341,4817.8871,58150,54.77,251990,56.305806,234607,2400,20767,16.43,107011,4600.8764,39027};//doublenongchang[gm][gn]={0.156,0.133,0.146,//0.157,0.123,0.123,//0.159,0,163,0.033};双TYZLGM]={0,0,0};双市泰泽=0;
3doubleyueshul=10;双nongchanggy[通用][肾炎];双nongchangmax[GN];双nongchangmin[GN];在E=0;〃电荷;intb=0;〃电荷:doubleD=MAX/10;/*蛙跳的最大值*/doubleC5=0.0;〃随机分组intEl=0;〃是否自适应求惯性及自学习因子doubleC3=0.0;〃惯性学习参数doubleC4=0.0;〃自学习参数doublePrecision=5;〃达优精度intE2=0;〃是否轮转1转0不转intlzcs=3;〃轮转层次;双C1—2.05;
4双C2=1;〃基本算法参数doubleXM;双XD;国际try_number=0;〃最差例子自学习次数//双C=1;〃加速因子国际trymax=5;doublehelih=0.0;双stepmax=最大/16;双步;doublestepmin=0.002;#定义R((双)(rand()%randmax)/randmax)//1/randmax0T之间的随机数,精度为//#定义RIrandO%100/100静态int;双n=3.14159265358979;双公差=00000000000000001//收敛精度;双C3=0.03;〃扰动幅度双£=2.718281828459;〃自然对数底数
5int=5;intbz=O;〃扰动因子标志双AW[V];intfztop[M];〃统计极值来自分组的情况国际randpop[M][我];〃随机流行typedefstruct{双D[V];双适应;int型;}个人;typedefstruct{双H[V];}合力;typedefstruct{intTF;
6在CS;愉;dydayouLS];每个PW[M];/**/族群中个体最差位置每个铅[M];/**/族群中个体最好位置Individalpx;/*全体中历史最好位置*/个人全体中最好位置PX1;/**/个人全体中最坏位置PW0;/**/每个个体[P];/**/全部个体Individalindividualrz[P];/*个体历史最优值*/个人单独[P];/**/邻域历史最优值每个流行[M][我];/**/排序后的群组个人临时[P];每个寺庙[P];个人临时性[M].;
7Individaltempi[I];单个的TEM;个人把;个体、X-[的];/**/计算标准差合力FW;/**/合力/*归一化处理*/无效guiyi()(intpmax,pmin,i,j;对于(j=0;j8if(nongchangLpmin][j]>nongchangLi][j])pmin=i;)nongchangmax[J]nongchangPmax=[][J];nongchangmin[J]nongchangPmin=[][J];)对于(i=0;i<;GM;++)对于(j=0;j9");
10)getchar();*/)选择测试函数为球/**/双适应(双[口])Iinti,j,堤;双和=0;双语=0;双S1=0,Hl=1,H2=0;双XI[V+1];doublerij;双酪氨酸;对于(i=0;i<v;++){
11[我];)为(i=0;i〈通用;i++)TYZ[我]=0;对于(i=0;i<;GM;++)I对于(j=0;jv;j+)TYZ[我]=TYZ[我]+XI[J]*nongchanggy[我][J];)对于(i=0;i<;GM;++)金额=金额+TYZ[我];市泰泽=金额/总经理;//printf("%。4f**
12",getchar()总和);//printf(u%o4f**
13",市泰泽TYZ[0]);getchar();//printf("%.4f**,%.4f**,%.4f**
14",tyze,tyz[O],tyz[l])jgetchar0;对于(i=0;i<;GM;++)
15语=语+战俘((TYZ[我]-市泰泽),2);tysz=SQRT(战俘(suml,2)/(GM-1));Tyr=0.1*tysz;sum=0.0;suml=0.0;对于(i=0;i<;GM;++)I总和=0;对于(j=0;j;(rij=fabs(tyz[i]-tyz[j]);if((tyr-rij)<0)堤=0;其他的堤二1;sum=sum+(tyr-rij)*tyi;
16)语语+笔=;)//printf(u%o4f**
17",getchar()语);returntysz*suml;//(i—0;i;〃求和;//printf(X3f
18%.3f
19%.3f
20%.3f
21%.3faaaaaaaaaaaaaaaaaa",xl[0],xl[1],xl⑵,xl[3],xl[4],sum);getchar();/返回总和;)对每一个个体初始化/**/无效()int,j;doublesum4=0.0;srand((unsigned)时间(空));对于(i=0;i
22(对于(j=0;jv;j+){个人的[我],[J]=R*(MAX-MIN)+min;}sum4=0;对于(j=0;jv;j+)sum4=sum4+个人[我],[J]*个人[我]和[J];sum4=SQRT(sum4);对于(j=0;jv;j个人的[我],[J]=个人[我],[J]/sum4;个体[我];个人[我]RZ=我;temp[i],rz=i;寺庙[我]RZ=我;
23//printf(//%.8f%.8f%.8f%.8f
24”,individual[i].d[0],individual[i].d[l],individual[i].d[2],individual[i].fitness);getchar();)为(i=0;i
25对于(j=0;j〈i;j++)if(weizhi[i]==weizhi[j])(伟志[我]=(int)(RM);J=l;对于(i=0;i
26");)//getchar();}voidsort()
27iint,j,k;对于(i=1;i
28//printf(“%d”,威志);对于(i=0;i
29PW[我]=流行[我][•];))随机交换若干分组同一级别的青蛙/**/对某个群组中的个体进行重新排序/**/无效sortpop(b)int,j;对于(i=l;i
30群组内更新/**/无效update(){int,j,k,1,n;双A;双B;doublesum4=0.0;XM-C1+C1;XD=2/晶圆厂(2-xm-sqrt(战俘(XM,2)-4XXm));如果(El=l)IC3=0.4+(0.9-0.4)*((双)(g)-(双)(12))/(双)(G);C4=0.4+(0.9-0.4)*((double)(G)-(double)(i2))/(double)(G);对于(n=0;n31对于(i=0;i;m;i+)a=0;b=0;对于(j=0;jv;j+)(temp[pw[i].rz].d[j]=B*aw[j]+C3*R*tempi[pw[i].rz].d[j]+C2*R*(pb[i].d[j]-pw[i].d[j])+C4*R*(individuallyLi].d[j]-pw[i].d[j]);)对于(j=0;jv;j+)【PW模板[我]。制],[J]=温度[密码[我]。制]D[J];对于(j=0;jv;j+)!临时[密码[我]。制],[J]+=PW[我]和[J];if(temp[pwLi],rz].d[j]<0)tempLpw[i].rz].d[j]==0;sum4=0.0;对于(j=0;jv;j+)sum4=sum4+温度[密码[我]。RZ]D[J]*温度[密码[我制]D[J];
32sum4=SQRT(sum4);对于(j=0;jv;j+)临时[密码[我]。制],[J]=温度[密码[我]。制],[J]/sum4;//printf("%。If%oIf%oIf%oIF",温度[密码[我]。制],[0],[我][私服温度。制],[1],[我][私服温度。制],[2],临时[密码[我]。制]和[3]);//printf("%.If”,temp[pw[i].rz].D[4]);getchar();//printfC%.3fandtemp[pw[i].rz].dL0]*temp[pw[i].rz].dL0]+tempLpw[i].rz].d[1]*temp[pw[i].rz].d[l]+tempLpw[i].rz].d[2]*temp[pw[i].rz].d[2]+temp[pw[i].rz].d[3]*temp[pw[i].rz].d[3]+temp[pw[i].rz].d[4]*temp[pw[i].rz].d[4]);(getchar);A=fitness(tempLpw[i].rz].d);//printf("a%.3f",a);(getchar);TempEpwLi].rz].fitness=a;If(a>pw[i].fitness)IPop[i]Ll-1]=temp[pw[i].rz];
33SortPop(I);Pb[i]=pop[i][0];Pw[i]=pop[i][1-1];)Else//logoIFor(k=0;k34”,temp[pw[i].rz].d[O]*temp[pw[i].rz].d[O]+temp[pw[i].rz].d[1]*temp[pw[i].rz].d[l]+temp[pw[i].rz].d⑵*temp[pw[i].rz].d[2]+temp[pw[i].rz].d[3]*temp[pw[i].rz].d[3]+temp[pw[i].rz].d[41*tempLpw[i].rz].d[4]);(getchar);For(j=0;j35Tempi[pw[i].rz].d[j]=temp[pw[i].rz].d[j];For(j=0;jpw[i].fitness){
36Pop[i][I-l]=temp[pw[i].rz];SortPop(I);Pb[i]=pop[i][0];Pw[i]=pop[i][1-1];)Else{//////Flag-0;
37If(flag==O)For(1=0;138sortpop(我);PB[POP][我]0;PW[我]=流行[我][•];))}//////})三=0;对于(ii=0;;ii;m;ii++)I如果(PB)。三=II;如果(健身)
39PX=PB[iii];fztop[III]=fztop[III]+1;}如果(PXlo健身〈铅[HI]。健身)[PX1=铅[皿;/*将流行[M][我]复制到个人*/无效copy()[inti,j,JI,K;我=0;对于(j=0;j;m;j++)
40对于(k=0;k
41为(i=1;i42
43",px.fitness);fprintf(f,"试验最好值为%.3f
44”,px.fitness);fprintf(F,“投影向量是
45");
46为(i=0;iprintf(“%3f
47”,px.d[i]);fprintf(F,“%。6楼”,PX。D[我]);}(i=0;i48");//printf("和是%。3f
49
50”,PX。健身);//printf("和是%。3f
51",2);为(i=0;i〈通用;i++)TYZ[我]=0;对于(i=0;i<;GM;++)I对于(j=0;jv;j+)TYZ[我]=TYZ[我]+PXoD[J]*nongchanggy[我][J];printf("第%d个是机3f
52”,我+1,TYZ[我]);fprintf(F,“%。6楼",TYZ[我]);双sigma()
53IntJ;双f=O;doublefitness_avg=O.0;对于(j=0;jS;j++)I//printf("极值e为%16f
54”,temx[j].fitness);fitness_avg=fitness_avg+temx[j].fitness;}fitness_avg=fitness_avg/s;printf("平均值为%.16f
55”,fitness_avg);//printfC%d极值e为%.16f
56”,j,temx[j].fitness);for(j=0,j
57",(f);f=sqrt(f/(s-1));
58returnf;)voidmain(){clock_tstartthan;doubletj[s+1][g+1];doubletj2[s+1];doubleave,avel,sigmax;intdymin,dymax,dycount=0,dysum=0,dyes=0;for(i=0;0
59//fprintf(f,"迭代0次试验30次平均极值为%.16f
60",avel/s);for(i2=0;p61ave=ave+px.fitness;)ave=ave/s;than=clock();//固定次数printf("**************************xlxslzslz\a[[)sigmax=sigma();//printf("平均极值为
62%.16f
63completed!,z,ave);printf("30次试验标准差为%.16e
64”,sigmax);printf(“30次试验平均运行时间=%.2fseconds
65”(double)(start)/(s*(double)clocks_per_sec));printf("30次试验的平均极值为的16e
66",ave);for(ia=0;ia67//fprintf(f,"30次试验平均极值为%.6e
68",ave);//fprintf(f,“30次试验标准差为%.6e
69",sigmax);//fprintf(f,“30次试验平均运行时间=%.2fseconds
70"(double)(start)/(s*(double)clocks_per_sec));getchar();//固定次数//进化曲线printf(〃**************************avel=0.0;for(i7-0;i7
71%.32f
72",avel/s);for(i2-0;p73ave=ave/s;printf("迭代%d次试验30次平均极值为
74%.32f
75”,i2+1,ave);//if(p==1350)getchar();//fprintf(f,32f
76",ave);}//进化曲线/*//达优率printf("**************************xlzxlzxlzxlz'a[])for(i=0;0
77{if(dayou[dymax].csdayou[il].cs)dymin=i1;dysum=dysum+dayou[il].cs;dycount=dycount+1;}}printf(“达优率为%r%%
78”(double)(dyes)/(double)(s)*100);printf("最大达优次数为:%d
79”,dayou[dymax].cs);printf("最小达优次数为:%d
80”,dayou[dymin].cs);printf("平均达优次数为:%d
81",dysum/dycount);fprintf(f,“达优率为%r%%
82z/(double)(dyes)/(double)(s)*100);fprintf(f,"30次试验平均达优次数为%d
83",dysum/dycount);fprintf(f,"30次试验最小达优次数为%d
84",dayou[dymin].cs);fprintf(f,"30次试验最大达优次数为%d
85",dayou[dymax].cs);//达优率