コード例 #1
0
 private void computeFitness(ref List <MoChromosome> F1)
 {
     for (int i = 0; i < F1.Count; i++)
     {
         F1[i].fitnessValue = Tool.ArraySum(TranObj(F1[i]));
     }
 }
コード例 #2
0
        protected void EnviromentSelection(List <MoChromosome> pop)
        {
            for (int i = 0; i < pop.Count; i++)
            {
                pop[i].fpr = Tool.ArraySum(TranObj(pop[i]));
            }

            List <double[]> shareMatrix = ShareMatrix(pop);

            for (int i = 0; i < pop.Count; i++)
            {
                pop[i].fcd = Math.Pow(Tool.ArraySum(shareMatrix[i]), 0.5);
            }

            List <MoChromosome>         result        = new List <MoChromosome>();
            List <List <MoChromosome> > dominatedSet0 = BiGEfastNonDominatedSort(pop);

            int cnt = 0;

            while (result.Count() + dominatedSet0[cnt].Count() < this.popsize)
            {
                for (int r = 0; r < dominatedSet0[cnt].Count(); r++)
                {
                    dominatedSet0[cnt][r].selected = true;
                }

                result.AddRange(dominatedSet0[cnt]);
                cnt++;
            }

            Boolean[] flag = new Boolean[dominatedSet0[cnt].Count];
            for (int i = 0; i < flag.Length; i++)
            {
                flag[i] = false;
            }
            while (result.Count < this.popsize)
            {
                int rnd = random.Next() % flag.Length;
                if (flag[rnd] == false)
                {
                    result.Add(dominatedSet0[cnt][rnd]);
                    flag[rnd] = true;
                }
            }

            mainpop.Clear();
            mainpop.AddRange(result);
            return;
        }