Exemple #1
0
        public void TravellingSalesmanTest()
        {
            int     populationSize = 100;
            IRandom rand           = new Rand();

            this.geneLength = 6;
            this.cityInfo   = this.BuildCityInfo();
            Population candidates = RandomPopulationGenerator.GeneratePopulation(rand, populationSize, 1, geneLength, this.cityInfo.Count, this.cityInfo.Count, new List <Chromosome>(), new List <Chromosome>(), CorrectEncoding);

            GeneticAlgorithm ga = new GeneticAlgorithm(rand, candidates, CalculateFitness);

            ga.encodingCorrector = CorrectEncoding;


            IOrganism solution      = ga.FindSolution();
            string    path          = WritePath(solution);
            double    totalDistance = 1 / CalculateFitness(solution);

            Assert.IsTrue(totalDistance <= 25000);
        }
 public WhenGeneratingASeedPopulation()
 {
     _generator = new RandomPopulationGenerator(new RandomBitGenerator(new Randomizer()));
 }