资源简介
最优化算法的无约束算法程序,包括单纯形法等
代码片段和文件信息
#include
#include
int const n=2;
double fun(double x[n]);
void compare(double x[n+1][n]double LGH[3][n]double LGH_tap[3]);//在调用之前LGH先给x[n+1]赋值
double H(double x[n+1][n]double LGH[3][n]double c);//判别准则
void zx(double x[n+1][n]double LGH[3][n]double LGH_tap[3]double xn_1[n]double xn_2[n]);
void main()
{
double x[n+1][n]={0};
double c=0.001;
double a=2;
double b=0.75;
double LGH[3][n]={0};
double LGH_tap[3]={0};
double xn_1[n]={0};
double xn_2[n]={0};
double xn_3[n]={0};
double xn_4[n]={0};
int ijtap=0;
//给出一个初始点X0X1X2
x[0][0]=8;x[0][1]=9;
x[1][0]=10;x[1][1]=9;
x[2][0]=8;x[2][1]=11;
cout<<“初始点:“< for(i=0;i {
cout<<“x[“< for(j=0;j {
cout< if(j!=n-1)
cout<<““;
}
cout<<“)“< }
compare(xLGHLGH_tap);//返回XlXhXg及它们在x[n+1][n]中的下标
zx(xLGHLGH_tapxn_1xn_2);//返回中心X(n+1)和反射点X(n+2)
while(H(xLGHc)==0)
{
if(fun(xn_2) {
for(i=0;i {
xn_3[i]=xn_1[i]+a*(xn_2[i]-xn_1[i]);//扩张
}
if(fun(xn_3) {
for(i=0;i {
x[int(LGH_tap[2])][i]=LGH[2][i]=xn_3[i];
}
//goto step 2;
}
else
{
for(i=0;i {
x[int(LGH_tap[2])][i]=LGH[2][i]=xn_2[i];
}
//goto step 2;
}
}
else
{
if(fun(xn_2) {
for(i=0;i {
xn_4[i]=xn_1[i]+b*(xn_2[i]-xn_1[i]);//压缩
}
//goto step 2;
}
else
{
for(i=0;i {
xn_4[i]=xn_1[i]-b*(xn_2[i]-xn_1[i]);//压缩
}
}
if(fun(xn_4) {
for(i=0;i {
x[int(LGH_tap[2])][i]=LGH[2][i]=xn_4[i];
}
}
else//缩边
{
cout<<“进行缩边。“< for(i=0;i {
if(i==LGH_tap[0])
continue;
for(j=0;j {
x[i][j]=(LGH[0][j]+x[i][j])/2;
}
}
}
}
compare(xLGH
- 上一篇:USB 通讯 libusb-win32
- 下一篇:UTF8-GBK编码互转(C)
评论
共有 条评论