Sort() public method

public Sort ( ) : void
return void
Esempio n. 1
0
 public NeuralGeneticAlgorithm(BasicNetwork network, IRandomizer randomizer, ICalculateScore calculateScore, int populationSize, double mutationPercent, double percentToMate)
     : base(TrainingImplementationType.Iterative)
 {
     NeuralGeneticAlgorithmHelper helper;
     Label_012F:
     helper = new NeuralGeneticAlgorithmHelper();
     helper.CalculateScore = new GeneticScoreAdapter(calculateScore);
     this.Genetic = helper;
     IPopulation population = new BasicPopulation(populationSize);
     this.Genetic.MutationPercent = mutationPercent;
     this.Genetic.MatingPopulation = percentToMate * 2.0;
     this.Genetic.PercentToMate = percentToMate;
     this.Genetic.Crossover = new Splice(network.Structure.CalculateSize() / 3);
     this.Genetic.Mutate = new MutatePerturb(4.0);
     this.Genetic.Population = population;
     int num = 0;
     while (true)
     {
         NeuralGenome genome2;
         if (num < population.PopulationSize)
         {
             BasicNetwork network2 = (BasicNetwork) network.Clone();
             randomizer.Randomize(network2);
             if ((((uint) percentToMate) + ((uint) populationSize)) >= 0)
             {
                 genome2 = new NeuralGenome(network2) {
                     GA = this.Genetic
                 };
             }
         }
         else
         {
             population.Sort();
             if (((uint) populationSize) <= uint.MaxValue)
             {
                 return;
             }
             goto Label_012F;
         }
         if ((((uint) num) + ((uint) populationSize)) >= 0)
         {
             NeuralGenome g = genome2;
             this.Genetic.PerformCalculateScore(g);
             if (((uint) populationSize) > uint.MaxValue)
             {
                 goto Label_012F;
             }
             this.Genetic.Population.Add(g);
             num++;
         }
     }
 }
        /// <summary>
        /// Construct a neural genetic algorithm.
        /// </summary>
        ///
        /// <param name="network">The network to base this on.</param>
        /// <param name="randomizer">The randomizer used to create this initial population.</param>
        /// <param name="calculateScore">The score calculation object.</param>
        /// <param name="populationSize">The population size.</param>
        /// <param name="mutationPercent">The percent of offspring to mutate.</param>
        /// <param name="percentToMate">The percent of the population allowed to mate.</param>
        public NeuralGeneticAlgorithm(BasicNetwork network,
            IRandomizer randomizer, ICalculateScore calculateScore,
            int populationSize, double mutationPercent,
            double percentToMate)
            : base(TrainingImplementationType.Iterative)
        {
            Genetic = new NeuralGeneticAlgorithmHelper
                           {
                               CalculateScore = new GeneticScoreAdapter(calculateScore)
                           };
            IPopulation population = new BasicPopulation(populationSize);
            Genetic.MutationPercent = mutationPercent;
            Genetic.MatingPopulation = percentToMate*2;
            Genetic.PercentToMate = percentToMate;
            Genetic.Crossover = new Splice(network.Structure.CalculateSize()/3);
            Genetic.Mutate = new MutatePerturb(4.0d);
            Genetic.Population = population;
            for (int i = 0; i < population.PopulationSize; i++)
            {
                var chromosomeNetwork = (BasicNetwork) (network
                                                           .Clone());
                randomizer.Randomize(chromosomeNetwork);

                var genome = new NeuralGenome(chromosomeNetwork) {GA = Genetic};
                Genetic.PerformCalculateScore(genome);
                Genetic.Population.Add(genome);
            }
            population.Sort();
        }
        private void initPopulation(GeneticAlgorithm ga)
        {
            ICalculateGenomeScore score = new TSPScore(cities);
            ga.CalculateScore = score;
            IPopulation population = new BasicPopulation(POPULATION_SIZE);
            ga.Population = population;

            for (int i = 0; i < POPULATION_SIZE; i++)
            {
                var genome = new TSPGenome(ga, cities);
                ga.Population.Genomes.Add(genome);
                ga.PerformCalculateScore(genome);
            }
            population.Sort();
        }