コード例 #1
0
 private void RefreshList()
 {
     currentPopulation[0] = initialCityListOne;
     currentPopulation[1] = initialCityListTwo;
     currentPopulation[2] = initialCityListThree;
     currentPopulation[3] = initialCityListFour;
     currentDistances[0]  = DistanceHelper.TotalDistance(initialCityListOne);
     currentDistances[1]  = DistanceHelper.TotalDistance(initialCityListTwo);
     currentDistances[2]  = DistanceHelper.TotalDistance(initialCityListThree);
     currentDistances[3]  = DistanceHelper.TotalDistance(initialCityListFour);
     RefreshPicBox(initialCityListOne);
 }
コード例 #2
0
        public static void Evolution(ref List <CityInfo>[] previousPopulation, ref float[] previousDistances, int crossoverSelection, float mutationPossibility)
        {
            float[]           fitnesses      = Fitness(previousDistances);
            List <CityInfo>[] selected       = Selection(previousPopulation, fitnesses);
            List <CityInfo>[] nextPopulation = Crossover(selected, crossoverSelection);
            Mutation(ref nextPopulation, mutationPossibility);

            float[] nextDistances = new float[4];
            for (int i = 0; i < nextPopulation.Count(); i++)
            {
                nextDistances[i] = DistanceHelper.TotalDistance(nextPopulation[i]);
            }

            Elimination(ref previousDistances, ref nextDistances, ref previousPopulation, ref nextPopulation);
            previousPopulation = nextPopulation;
            previousDistances  = nextDistances;
        }