求高手修改错误
#include "stdio.h"#include "math.h"
#include "time.h"
#include "stdlib.h"
#define P 4500 //功率
#define N1 30 //小齿轮转速
#define I 3.2 //传动比
#define ZJJHE 90 //两齿轮轴间的夹角和
#define popsum 100 //定义种群数量
#define loopmax 500 //定义循环次数
#define PI 3.1415 //定义π
#define R1 0.7 //
#define R2 0.8
#define G 0.2 //润滑油粘度
#define A 0.3 //润滑油的粘压系数
#define E 3.21 //综合弹性模量
#define O_F 200 //许用弯曲应力
#define O_H 150 //许用接触应力
#define Ka 1 //使用系数
#define K1 2.39 //计算kv系数
#define K2 0.0087
#define v1 2 //计算Ze参数
#define v2 3
#define E1 100.0
#define E2 100.0
#define CJ 7 //定义齿轮精度
#define CP 0.4 //定义交叉概率
#define MP 0.04 //定义变异概率
#define error 0.01
float geti_result[loopmax];
float m[8]={2,2.5,3,4,5,6,8,10};
struct geti
{
int z; //定义变量小齿轮齿数
float m; //定义变量模数
float ckxs; //定义变量齿款系数
float fitness; //适应度函数值
}getiold[popsum], //父代个体组
getinew[popsum], //子代个体组
getiresult; //记录最优个体
void chushihua(); //声明初始化函数
void pinggu(); //声明评估函数
void cross(); //声明交叉函数
void bianyi(); //声明变异函数
int record(int t);
void showresult(int flag); //声明显示结果函数
int randsign();
//主函数//
main()
{
int i,t;
int flag=0;
chushihua();
pinggu();
for(i=1;i<=loopmax;i++)
{
cross();
bianyi();
pinggu();
record((int) t);
if(flag=(t==1)?1:0) break; //判断是否终止
}
showresult((int)flag);
}
//初始化函数//
void chushihua()
{
int a,b,c=0;
double e;
a=13+rand()%23; //随机取13到36之间的整数齿数
b=0+rand()%7; //随机取0到7之间的整数
e=0.25+(0.35-0.25)*rand()/32768.0; //随机取0.25到0.35之间的小数为齿宽系数
for(c=0;c<popsum;c++)
{
getiold[c].z=a;
getiold[c].m=m[b];
getiold[c].ckxs=e;
getiold[c].fitness=0;
}
} //以上初始化
//评估函数//
void pinggu()
{
int i,j,t;
int flag=0;
struct geti *getip;
if(flag==0)
{ getip=getiold;
getiresult.fitness=getiold[0].fitness;
for(i=0;i<popsum;i++)
{
if(getiresult.fitness<getiold[i].fitness)
getiresult.fitness=getiold[i].fitness;
}
}
else
getip=getinew;
getiresult.fitness=getinew[0].fitness;
for(i=0;i<popsum;i++)
{
if(getiresult.fitness<getinew[i].fitness)
getiresult.fitness=getinew[i].fitness;
}
getiresult.m=getip->m;
getiresult.z=getip->z;
getiresult.ckxs=getip->ckxs;
geti_result[t++]=getiresult.fitness;
for(j=0;j<popsum;j++)
{
double v,ru,hmin,Wl,Lm,H,J,K,L,Ft,b,T1; //定义体积,膜厚比,最小油膜厚度,单位接触宽度上的载荷,节锥长,HJKL为计算方便设计,齿轮圆周力,齿宽,小齿轮传递的最大转矩
double Kv,Kf1,Kf2,Kh1,Kh2,o_f,YsaYfa,o_h,jiao1,aim,cfx1,cfx2;
double Ze,Zh,x1,x2,Ea;
int Zv;
aim=v+x1*(1/ru)+x2*(cfx1+cfx2); //计算目标函数
v=PI*(1/I)*((1/I)+1)*(getip->m)*(getip->m)*(getip->m)*(getip->z)*(getip->z)*(getip->z)*(1-(getip->ckxs)+(getip->ckxs)/3); //计算体积
ru=hmin/sqrt(R1*R1+R2*R2); //计算膜厚比
hmin=H*J*K*L; //计算hmin分解为H,J,K,L四个参数乘积
H=2.65*pow(A,0.54)/(pow(E,10.03)*pow(Wl,0.13));
Wl=Ft/b*cos(20*PI/180); //计算单位接触宽度上的载荷
Ft=2*T1/((getip->m)*(1-0.5*(getip->ckxs))*(getip->z)); //计算圆周力
b=getip->m*getip->z*getip->ckxs*sqrt(1/(I*I)+1)/2; //计算齿宽
T1=95.5*100000*P/N1; //计算小齿轮的转矩
J=pow(PI*N1*G/30,0.7);
K=pow(Lm*sin(20*PI/180),1.13);
Lm=getip->m*getip->z*sqrt(1/(I*I)+1)/2-b; //节锥长
L=pow(I,0.27)/pow((I*I+1),0.43);
//以下判断是否满足约束条件
o_f=Ka*Kv*Kf1*Kf2*Ft*YsaYfa/(b*getip->m*(1-0.5*getip->ckxs)); //计算弯曲应力
Kv=1+(K1/(Ka*Ft/b)+K2)*getip->z*PI*getip->m*getip->z*N1/60/100*sqrt(1/I/I/(1/(I*I)+1)); //动载荷系数
Kf2=1+(CJ-5)*(Ea-1)/4; //计算齿间载荷分配系数和齿向载荷分布系数(F)
Kf1=Kf2;
Ea=1.88-3.2*(1/getip->z+1/(I*getip->z)); //端面重合度
Zv=getip->z/cos(jiao1)+1; //当量齿数
jiao1=acot(1/I);
if((Zv>=17)&&(Zv<=23)) //计算应力校正系数和齿形系数的乘积
YsaYfa=8.16-1.276*log((double)Zv);
else
YsaYfa=4.85-0.224*log((double)Zv);
o_h=Ze*Zh*sqrt(4*Ka*Kv*Kh1*Kh2*T1/((getip->ckxs)*(1-0.5*(getip->ckxs))*(1-0.5*(getip->ckxs))*pow((getip->m)*(getip->z),3)*1/I));
Ze=sqrt(1.0/(PI*(1-v1*v1)/E1+PI*(1-v2*v2)/E2));
Zh=2*pow(1/sin(2*20*PI/180),0.5); //
Kh1=1.0; //计算齿间载荷分配系数和齿向载荷分布系数(H)
Kh2=1.0;
if(o_f<=O_F)
cfx1=0;
else
cfx1=o_f-O_F;
if(o_h<=O_H)
cfx2=0;
else
cfx2=o_h-O_H;
getip->fitness=1.0/aim;
}
//交叉函数//
void cross()
{
int i,j,k=0;
do
{
i=1+rand()%(popsum-1);
j=1+rand()%(popsum-1);
}while(i!=j);
if(randkign(CP)==1)
{
float x;
x=rand(0,100)/100.0;
getinew[k].z=x*getiold[i].z+(1-x)*getiold[j].z;
getinew[k+1].z=(1-x)*getiold[i].z+x*getiold[j].z;
getinew[k].m=x*getiold[i].m+(1-x)*getiold[j].m;
getinew[k+1].m=(1-x)*getiold[i].m+x*getiold[j].m;
getinew[k].ckxs=x*getiold[i].ckxs+(1-x)*getiold[j].ckxs;
getinew[k+1].ckxs=(1-x)*getiold[i].ckxs+x*getiold[j].ckxs;
k=k+2;
}
else
{
getinew[k]=getiold[i];
getinew[k+1]=getiold[j];
k=k+2;
}
}
//变异函数
void bianyi()
{
int i,j,k,l;
float cmp;
cmp=1-pow(1-MP,3);
for(i=0;i<popsum;i++)
{
if(randsign(cmp)==1)
{
j=0+rand()%popsum;
k=0+rand()%2;
if(k=0)
getinew[j].z=+(rand()%(36-getinew[j].z));
else
if(k=1)
{ do
l=0+rand()%7;
while(getinew[j].m!=m[l]);
getinew[j].m=m[l];
}
else
getinew[j].ckxs=+((0.35-getinew[j].ckxs)*rand()/32768.0);
}
}
}
int record(int t)
{ int flag=0;
float x=geti_result[t-1]-geti_result[t-2];
if(abs(x)<error)
{
flag++;
if(flag>=loopmax)
return 1;
}
else
flag=0;
return 0;
}
//显示结果函数
void showresult(int flag)
{
int i,j;
if(flag==0)
printf("已到最大搜索次数,搜索失败!");
else
printf("最优齿数为%d\n",getiresult.z);
printf("最优模数为%f\n",getiresult.m);
printf("最优齿宽系数为%f\n",getiresult.ckxs);
printf("最优适应度函数值为%f\n",getiresult.fitness);
}
randsign(float p)
{
if(rand()>(p*32768))
return 0;
else return 1;
}
--------------------Configuration: lb - Win32 Debug--------------------
Compiling...
lb.c
D:\Program Files\Microsoft Visual Studio\MyProjects\基于弹流润滑的锥齿轮多目标优化设计\lb.c(77) : warning C4244: '=' : conversion from 'double ' to 'float ', possible loss of data
D:\Program Files\Microsoft Visual Studio\MyProjects\基于弹流润滑的锥齿轮多目标优化设计\lb.c(133) : warning C4244: '=' : conversion from 'double ' to 'int ', possible loss of data
D:\Program Files\Microsoft Visual Studio\MyProjects\基于弹流润滑的锥齿轮多目标优化设计\lb.c(134) : warning C4013: 'acot' undefined; assuming extern returning int
D:\Program Files\Microsoft Visual Studio\MyProjects\基于弹流润滑的锥齿轮多目标优化设计\lb.c(152) : warning C4244: '=' : conversion from 'double ' to 'float ', possible loss of data
D:\Program Files\Microsoft Visual Studio\MyProjects\基于弹流润滑的锥齿轮多目标优化设计\lb.c(155) : error C2143: syntax error : missing ';' before 'type'
D:\Program Files\Microsoft Visual Studio\MyProjects\基于弹流润滑的锥齿轮多目标优化设计\lb.c(163) : warning C4013: 'randkign' undefined; assuming extern returning int
D:\Program Files\Microsoft Visual Studio\MyProjects\基于弹流润滑的锥齿轮多目标优化设计\lb.c(166) : warning C4087: 'rand' : declared with 'void' parameter list
D:\Program Files\Microsoft Visual Studio\MyProjects\基于弹流润滑的锥齿轮多目标优化设计\lb.c(166) : warning C4244: '=' : conversion from 'double ' to 'float ', possible loss of data
D:\Program Files\Microsoft Visual Studio\MyProjects\基于弹流润滑的锥齿轮多目标优化设计\lb.c(167) : error C2065: 'k' : undeclared identifier
D:\Program Files\Microsoft Visual Studio\MyProjects\基于弹流润滑的锥齿轮多目标优化设计\lb.c(167) : warning C4244: '=' : conversion from 'float ' to 'int ', possible loss of data
D:\Program Files\Microsoft Visual Studio\MyProjects\基于弹流润滑的锥齿轮多目标优化设计\lb.c(168) : warning C4244: '=' : conversion from 'float ' to 'int ', possible loss of data
D:\Program Files\Microsoft Visual Studio\MyProjects\基于弹流润滑的锥齿轮多目标优化设计\lb.c(187) : warning C4244: '=' : conversion from 'double ' to 'float ', possible loss of data
D:\Program Files\Microsoft Visual Studio\MyProjects\基于弹流润滑的锥齿轮多目标优化设计\lb.c(204) : warning C4244: '=' : conversion from 'double ' to 'float ', possible loss of data
D:\Program Files\Microsoft Visual Studio\MyProjects\基于弹流润滑的锥齿轮多目标优化设计\lb.c(211) : warning C4244: 'function' : conversion from 'float ' to 'int ', possible loss of data
执行 cl.exe 时出错.
lb.obj - 1 error(s), 0 warning(s)