コード例 #1
0
ファイル: Population.cs プロジェクト: olorloser/TSP
        public Population CreateOffspring(double MutationProbability, double CrossOverProbability, Random random)
        {
            Population result = new Population(this.amountOfSpecimen, this.data);
            double     randomChance;

            for (int i = 0; i < this.amountOfSpecimen; i++)
            {
                randomChance = random.NextDouble();
                if (randomChance < MutationProbability)
                {
                    result.specimen[i] = Genetics.InversionMutation(this.specimen[i], random);
                }
                else if (randomChance > MutationProbability && randomChance < MutationProbability + CrossOverProbability && i + 1 < this.amountOfSpecimen)
                {
                    result.specimen[i]     = Genetics.OXCrossOver(this.specimen[i], this.specimen[i + 1], random);
                    result.specimen[i + 1] = Genetics.OXCrossOver(this.specimen[i + 1], this.specimen[i], random);
                    i++;
                }
                else //Nic nie rób
                {
                    result.specimen[i] = this.specimen[i];
                }
            }
            return(result);
        }
コード例 #2
0
ファイル: Population.cs プロジェクト: olorloser/TSP
        public void CrossOver(double CrossoverProbability, Random random)
        {
            double randomChance;

            for (int i = 0; i < this.amountOfSpecimen; i++)
            {
                randomChance = random.NextDouble();
                if (randomChance < CrossoverProbability && i + 1 != this.amountOfSpecimen)
                {
                    this.specimen[i]     = Genetics.OXCrossOver(this.specimen[i], this.specimen[i + 1], random);
                    this.specimen[i + 1] = Genetics.OXCrossOver(this.specimen[i + 1], this.specimen[i], random);
                    this.specimen[i].rateSelf();
                    this.specimen[i + 1].rateSelf();
                }
            }
            getPopulationRate();
        }
コード例 #3
0
ファイル: Population.cs プロジェクト: olorloser/TSP
        public void Mutate(double MutationProbability, Random random)
        {
            double randomChance;

            //int oldRate = 0;
            //int newRate = 0;
            for (int i = 0; i < this.amountOfSpecimen; i++)
            {
                randomChance = random.NextDouble();
                if (randomChance < MutationProbability)
                {
                    //oldRate = this.specimen[i].rate;
                    this.specimen[i] = Genetics.InversionMutation(this.specimen[i], random);
                    this.specimen[i].rateSelf();
                    //Do debugowania
                    //newRate = this.specimen[i].rateSelf();
                    //System.Console.WriteLine("zmutowano osobnika o ocenie:{0}, na ocenę: {1}", oldRate, newRate);
                    //System.Console.WriteLine("zmienne: amountofspecimen: {0}, randomchance: {1}, i: {2}", this.amountOfSpecimen, randomChance, i);
                }
            }

            getPopulationRate();
        }