日期:2014-05-20  浏览次数:20647 次

我用java写的遗传算法的严重问题,程序没错,但不知道为什么结果总和预想的不同,实在是困惑,请帮忙啊!!!!(三)

      void   mutate()   {
                int   i,   j;
                double   lbound,   hbound;
                double   x;

                for   (i   =   0;   i   <   POPSIZE;   i++)   {
                        for   (j   =   0;   j   <   NVARS;   j++)   {
                                x   =   java.lang.Math.random();
                                if   (x   <   PMUTATION)   {
                                        /*   find   the   bounds   on   the   variable   to   be   mutated   */
                                        lbound   =   population[i].lower[j];
                                        hbound   =   population[i].upper[j];
                                        population[i].gene[j]   =   randval(lbound,   hbound);
                                }
                        }

                }
        }
      void   report()   {
                int   i;
                double   best_val;   /*   best   population   fitness   */
                double   avg;   /*   avg   population   fitness   */
                double   stddev;   /*   std.   deviation   of   population   fitness   */
                double   sum_square;   /*   sum   of   square   for   std.   calc   */
                double   square_sum;   /*   square   of   sum   for   std.   calc   */
                double   sum;   /*   total   population   fitness   */
                sum   =   0.0;
                sum_square   =   0.0;
                for   (i   =   0;   i   <   POPSIZE;   i++)   {
                        sum   +=   population[i].fitness;