标题:代码错误主要是在if else 之中,当第一次迭代的时候, previous_populatio ...
只看楼主
米粒大小3
Rank: 1
等 级:新手上路
帖 子:40
专家分:7
注 册:2015-10-25
结帖率:66.67%
 问题点数:0 回复次数:1 
代码错误主要是在if else 之中,当第一次迭代的时候, previous_population , previous_fitness 等明明已经计算出来的
代码错误主要是在if else 之中,当第一次迭代的时候,  previous_population , previous_fitness 等明明已经计算出来的,但在进行第二次迭代的时候,这些都为空了,不知道为什么,以前没有碰到过类似的问题,恳请路过的留下指导意见,感激不尽了
while (Iteration < Max_iteration)
            {
                int Flame_no = Convert.ToInt16(System.Math.Round((double)Max_iteration / (Iteration + Max_iteration / N)));
                double[,] Moth_fitness = new double[1, population];
                Moth_fitness = fitness(Moth_pos, ub, lb);
                double[,] fitness_sorted = new double[1, population];
                int[] I = new int[population];
                double[,] sorted_population = new double[population, dim];
                double[,] best_flames = new double[population, dim];
                double[,] best_flame_fitness = new double[1, population];
                double[,] previous_population = new double[population, dim];
                double[,] previous_fitness = new double[1, population];
                double[,] double_population = new double[2 * population, dim];
                double[,] double_fitness = new double[1, 2 * population];
                double[,] double_fitness_sorted=new double[1,2*population];
                double[,] double_sorted_population = new double[2 * population, dim];
                int[] II=new int[2*population];
               /* previous_population = Moth_pos;
                previous_fitness = Moth_fitness;*/
                if (Iteration == 1)
                {
                    Sort(Moth_fitness, out fitness_sorted, out I);
                    for (int i = 0; i < population; i++)
                    {
                        for (int j = 0; j < dim; j++)
                        {
                            sorted_population[i, j] = Moth_pos[I[i], j];
                        }
                    }
                   /* best_flames = sorted_population;
                    best_flame_fitness = fitness_sorted;*/
                }               
                else
                {
                    JuZhenHangHeBing(previous_population, best_flames,out double_population);
                    JuZhenLieHebing(previous_fitness, best_flame_fitness, out double_fitness);

                    Sort(double_fitness, out double_fitness_sorted, out II);
                    for (int i = 0; i < 2*population; i++)
                    {
                        for (int j = 0; j < dim; j++)
                        {
                            double_sorted_population[i, j] = double_population[II[i], j];
                        }
                    }
                    for (int i = 0; i < N; i++)
                    {
                        for (int j = 0; j < dim; j++)
                        {
                            sorted_population[i, j] = double_sorted_population[i, j];
                        }
                    }
                    for (int i = 0; i < N; i++)
                    {
                        fitness_sorted[0, i] = double_fitness_sorted[0, i];
                    }

                    best_flames = sorted_population;
                    best_flame_fitness = fitness_sorted;

                }
                best_flames = sorted_population;
                best_flame_fitness = fitness_sorted;
                //Update the position best flame obtained so far
                Best_flame_score = fitness_sorted[0, 0];
                for (int i = 0; i < dim; i++)
                {
                    Best_flame_pos[0,i] = sorted_population[0, i];
                }
                previous_population = Moth_pos;
                previous_fitness = Moth_fitness;
搜索更多相关主题的帖子: int double new dim for 
2017-07-25 07:39
yhlvht
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:36
帖 子:707
专家分:4405
注 册:2011-9-30
得分:0 
  double[,] previous_population = new double[population, dim];
  double[,] previous_fitness = new double[1, population];
不是每一次都new了新的么
2017-07-25 19:51



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-479596-1-1.html




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

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