| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 331 人关注过本帖
标题:徐士良 算法书第二版 单纯形调优法 他给的例题JJSIM0.C和光盘上的JJSIM.C怎 ...
只看楼主 加入收藏
机械男
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2012-2-21
结帖率:0
收藏
 问题点数:0 回复次数:0 
徐士良 算法书第二版 单纯形调优法 他给的例题JJSIM0.C和光盘上的JJSIM.C怎么用啊?
JJSIM0.C是:
#include "math.h"
#include "stdio.c"
#include "jjsim.c"
main()
{
    int i;
    double d,u,v,eps,x[3],xx[2][3],f[3];
    d=1.0;u=1.6;v=0.4;eps=1.0e-30;
    i=jjsim(2,d,u,v,x,eps,200,xx,f);
    printf("\n");
    printf("i=%3d\n",i);
    printf("\n");
    for(i=0;i<=2;i++)
        printf("x(0)=%e x(1)=%e f=%e\n",xx[0][i],xx[1][i],f[i]);
    printf("\n");
    for(i=0;i<=1;i++)
        printf("x(%2d)=%e\n",i,x[i]);
    printf("j=%e\n",x[2]);
     printf("\n");

    }
double jjsimf(x,n)
int n;
double x[];
{
    double y;
    n=n;
    y=x[1]-x[0]*x[0];
    y=100.0*y*y;
    y=y+(1.0-x[0])*(1.0-x[0]);
    return(y);
}

JJSIM.C是:

  #include "stdlib.h"
  #include "math.h"
  int jjsim(n,d,u,v,x,eps,k,xx,f)
  int n,k;
  double d,u,v,x[],eps,xx[],f[];
  { int r,g,i,j,l,kk;
    double nn,fe,fr,fl,fg,ft,ff,fs;
    double *xt,*xf,*xe;
    extern double jjsimf();
    xt=malloc(n*sizeof(double));
    xf=malloc(n*sizeof(double));
    xe=malloc(n*sizeof(double));
    kk=0; nn=1.0*n;
    fr=sqrt(nn+1.0);
    fl=d*(fr-1.0)/(1.414*nn);
    fg=d*(fr+nn-1.0)/(1.414*nn);
    for(i=0; i<=n-1; i++)
    for(j=0; j<=n; j++)
       xx[i*(n+1)+j]=0.0;
    for(i=1; i<=n; i++)
    for(j=0; j<=n-1; j++)
       xx[j*(n+1)+i]=fl;
    for(i=1; i<=n; i++)
       xx[(i-1)*(n+1)+i]=fg;
    for(i=0; i<=n; i++)
      { for(j=0; j<=n-1; j++)
           { xt[j]=xx[j*(n+1)+i]; }
        f[i]=jjsimf(xt,n);
      }
    ft=1.0+eps;
    while ((kk<k)&&(ft>eps))
      { kk=kk+1;
        fr=f[0]; fl=f[0]; r=0; l=0;
        for (i=1; i<=n; i++)
          { if (f[i]>fr) { r=i; fr=f[i];}
            if (f[i]<fl) { l=i; fl=f[i];}
          }
        g=0; fg=f[0];
        j=0;
        if (r==0) { g=1; fg=f[1]; j=1;}
        for (i=j+1; i<=n; i++)
          if ((i!=r)&&(f[i]>fg))
            { g=i; fg=f[i];}
        for (j=0; j<=n-1; j++)
          { xf[j]=0.0;
            for (i=0; i<=n; i++)
              if (i!=r)
                xf[j]=xf[j]+xx[j*(n+1)+i]/nn;
            xt[j]=2.0*xf[j]-xx[j*(n+1)+r];
          }
        ft=jjsimf(xt,n);
        if (ft<f[l])
          { for (j=0; j<=n-1; j++)
              xf[j]=(1.0+u)*xt[j]-u*xf[j];
            ff=jjsimf(xf,n);
            if (ff<f[l])
              { for (j=0; j<=n-1; j++)
                  xx[j*(n+1)+r]=xf[j];
                f[r]=ff;
              }
            else
              { for (j=0; j<=n-1; j++)
                  xx[j*(n+1)+r]=xt[j];
                f[r]=ft;
              }
          }
        else
          { if (ft<=f[g])
              { for (j=0; j<=n-1; j++)
                  xx[j*(n+1)+r]=xt[j];
                f[r]=ft;
              }
            else
              { if (ft<=f[r])
                  { for (j=0; j<=n-1; j++)
                      xx[j*(n+1)+r]=xt[j];
                    f[r]=ft;
                  }
                for (j=0; j<=n-1; j++)
                  xf[j]=v*xx[j*(n+1)+r]+(1.0-v)*xf[j];
                ff=jjsimf(xf,n);
                if (ff>f[r])
                  for (i=0; i<=n; i++)
                    { for (j=0; j<=n-1; j++)
                        { xx[j*(n+1)+i]=(xx[j*(n+1)+i]+
                    xx[j*(n+1)+l])/2.0;
                          x[j]=xx[j*(n+1)+i]; xe[j]=x[j];
                        }
                      fe=jjsimf(xe,n); f[i]=fe;
                    }
                else
                  { for (j=0; j<=n-1; j++)
                      xx[j*(n+1)+r]=xf[j];
                    f[r]=ff;
                  }
              }
          }
        ff=0.0; ft=0.0;
        for (i=0; i<=n; i++)
          { ff=ff+f[i]/(1.0+nn);
            ft=ft+f[i]*f[i];
          }
        ft=(ft-(1.0+n)*ff*ff)/nn;
      }
    for (j=0; j<=n-1; j++)
      { x[j]=0.0;
        for (i=0; i<=n; i++)
          x[j]=x[j]+xx[j*(n+1)+i]/(1.0+nn);
        xe[j]=x[j];
      }
    fe=jjsimf(xe,n); x[n]=fe;
    free(xt); free(xf); free(xe);
    return(kk);
  }


搜索更多相关主题的帖子: eps include 
2012-03-07 09:38
快速回复:徐士良 算法书第二版 单纯形调优法 他给的例题JJSIM0.C和光盘上的JJSI ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017773 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved