コード例 #1
0
        private void ExecAlgo()
        {
            // Remove precedent generation
            Dispatcher.Invoke(() =>
            {
                foreach (Line l in roadLines)
                {
                    canvasMap.Children.Remove(l);
                }
                roadLines.RemoveRange(0, roadLines.Count);
            });

            this.SaveParams();
            var generations = Algo.Launch(new List <City>(this.cities),
                                          this.NbRoadsPerGeneration, this.NbMutations, this.NbXovers, this.NbElites);

            int           indexGen = 0;
            StringBuilder sb       = new StringBuilder();

            foreach (Generation g in generations)
            {
                sb.Append("Generation " + indexGen++ + " : ---------------------------------------------");
                sb.Append("\n");
                sb.Append(g);
                sb.Append("\n");
            }
            Dispatcher.Invoke(() =>
            {
                UpdateConsole(sb);
                //display best road
                PrintRoad(generations[generations.Count - 1].Roads[0]);
            });
        }
コード例 #2
0
ファイル: Algo.cs プロジェクト: Soliman13/DarwinProject
        private static Generation GetNextGeneration(Generation genN,
                                                    int mutationsPercentage, int xoverPercentage, int elitesPercentage)
        {
            var xovers    = Algo.GenerateXOver(genN, xoverPercentage);
            var mutations = Algo.GenerateMutations(genN, mutationsPercentage);
            var elites    = genN.GetBestRoad(elitesPercentage);

            var genPrimeRoad = new List <Road>(mutations);

            genPrimeRoad.AddRange(elites);
            genPrimeRoad.AddRange(xovers);

            var genPrime = new Generation(genPrimeRoad).GetBestRoad(genN.Roads.Count);

            return(new Generation(genPrime));
        }