欢迎来到天天文库
浏览记录
ID:40809475
大小:36.50 KB
页数:6页
时间:2019-08-08
《内点惩罚函数法子程序》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、#include"stdio.h"#include"stdlib.h"#include"math.h"constintkkg=3;doubler0;doublef(doublex[]){doubleff;ff=pow((x[0]-8),2)+pow((x[1]-8),2);return(ff);}/*约束条件子程序*/voidstrain(doublex[],doubleg[]){g[0]=x[0]-1;g[1]=x[1]-1;g[2]=11-x[0]-x[1];}/*惩罚函数子程序*/doubleobjf(doublep[]
2、){inti;doubleff,sg,*g;g=(double*)malloc(kkg*sizeof(double));sg=0;strain(p,g);for(i=0;i0)sg=sg+r0/(*(g+i));elsesg=sg+r0*(1e+10);}free(g);ff=f(p)+sg;return(ff);}/*进退函数*/voidjtf(doublex0[],doubleh0,doubles[],intn,doublea[],doubleb[]){inti;double*xx[
3、3],h,f1,f2,f3;for(i=0;i<3;i++)xx[i]=(double*)malloc(n*sizeof(double));h=h0;for(i=0;i=f1){h=-h0;for(i=0;i4、0]+i)=*(xx[1]+i);*(xx[1]+i)=*(xx[2]+i);}f1=f2;f2=f3;}for(;;){h=2.0*h;for(i=0;i5、[i]=*(xx[0]+i);}elsefor(i=0;i6、++){*(xx[0]+i)=a[i]+0.618*(b[i]-a[i]);*(xx[1]+i)=a[i]+0.382*(b[i]-a[i]);}f1=objf(xx[0]);f2=objf(xx[1]);do{if(f1>f2){for(i=0;i7、a[i]=*(xx[1]+i);*(xx[1]+i)=*(xx[0]+i);}f2=f1;for(i=0;ieps);for(i=0;i8、ff);}doubleoneoptim(doublex0[],doubles[],doubleh0,doubleepsg,intn,doublex[]){doubleff,*a,*b;a=(double*)malloc(n*sizeof(double));b=(double*
4、0]+i)=*(xx[1]+i);*(xx[1]+i)=*(xx[2]+i);}f1=f2;f2=f3;}for(;;){h=2.0*h;for(i=0;i5、[i]=*(xx[0]+i);}elsefor(i=0;i6、++){*(xx[0]+i)=a[i]+0.618*(b[i]-a[i]);*(xx[1]+i)=a[i]+0.382*(b[i]-a[i]);}f1=objf(xx[0]);f2=objf(xx[1]);do{if(f1>f2){for(i=0;i7、a[i]=*(xx[1]+i);*(xx[1]+i)=*(xx[0]+i);}f2=f1;for(i=0;ieps);for(i=0;i8、ff);}doubleoneoptim(doublex0[],doubles[],doubleh0,doubleepsg,intn,doublex[]){doubleff,*a,*b;a=(double*)malloc(n*sizeof(double));b=(double*
5、[i]=*(xx[0]+i);}elsefor(i=0;i6、++){*(xx[0]+i)=a[i]+0.618*(b[i]-a[i]);*(xx[1]+i)=a[i]+0.382*(b[i]-a[i]);}f1=objf(xx[0]);f2=objf(xx[1]);do{if(f1>f2){for(i=0;i7、a[i]=*(xx[1]+i);*(xx[1]+i)=*(xx[0]+i);}f2=f1;for(i=0;ieps);for(i=0;i8、ff);}doubleoneoptim(doublex0[],doubles[],doubleh0,doubleepsg,intn,doublex[]){doubleff,*a,*b;a=(double*)malloc(n*sizeof(double));b=(double*
6、++){*(xx[0]+i)=a[i]+0.618*(b[i]-a[i]);*(xx[1]+i)=a[i]+0.382*(b[i]-a[i]);}f1=objf(xx[0]);f2=objf(xx[1]);do{if(f1>f2){for(i=0;i7、a[i]=*(xx[1]+i);*(xx[1]+i)=*(xx[0]+i);}f2=f1;for(i=0;ieps);for(i=0;i8、ff);}doubleoneoptim(doublex0[],doubles[],doubleh0,doubleepsg,intn,doublex[]){doubleff,*a,*b;a=(double*)malloc(n*sizeof(double));b=(double*
7、a[i]=*(xx[1]+i);*(xx[1]+i)=*(xx[0]+i);}f2=f1;for(i=0;ieps);for(i=0;i8、ff);}doubleoneoptim(doublex0[],doubles[],doubleh0,doubleepsg,intn,doublex[]){doubleff,*a,*b;a=(double*)malloc(n*sizeof(double));b=(double*
8、ff);}doubleoneoptim(doublex0[],doubles[],doubleh0,doubleepsg,intn,doublex[]){doubleff,*a,*b;a=(double*)malloc(n*sizeof(double));b=(double*
此文档下载收益归作者所有