コード例 #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);
        }
コード例 #2
0
 public void RouletteWheelSelectorStochasticAcceptanceTest4()
 {
     IRandom rand = new Rand();
     this.TestSelector(new RouletteWheelSelectorStochasticAcceptance(rand), 2, Enumerable.Range(0, 100).Select(i => i / 100.0).ToArray());
 }
コード例 #3
0
 public void RouletteWheelSelectorStochasticAcceptanceTest1()
 {
     IRandom rand = new Rand();
     this.TestSelector(new RouletteWheelSelectorStochasticAcceptance(rand), 5, 10, 20, 30, 40);
 }
コード例 #4
0
 public void RouletteWheelSelectorStochasticAcceptanceTest2()
 {
     IRandom rand = new Rand();
     this.TestSelector(new RouletteWheelSelectorStochasticAcceptance(rand), 5, 0.1, 0.2, 0.3, 0.4);
 }
コード例 #5
0
 public void RouletteWheelSelectionTest2()
 {
     IRandom rand = new Rand();
     this.TestSelector(new RouletteWheelSelector(rand), 5, 0.1, 0.2, 0.3, 0.4);
 }
コード例 #6
0
 public void RouletteWheelSelectionTest3()
 {
     IRandom rand = new Rand();
     this.TestSelector(new RouletteWheelSelector(rand), 2, Enumerable.Range(0, 100).Select(i => Convert.ToDouble(i)).ToArray());
 }
コード例 #7
0
 public void LinearRankSelectorTest1()
 {
     IRandom rand = new Rand();
     this.TestSelector(new LinearRankingSelector(rand), 5, 2, 16000, 33000, 50000);
 }
コード例 #8
0
 public void RouletteWheelSelectionTest1()
 {
     IRandom rand = new Rand();
     this.TestSelector(new RouletteWheelSelector(rand), 5, 10, 20, 30, 40);
 }
コード例 #9
0
 public void ExponentialRankSelectorTest1()
 {
     IRandom rand = new Rand();
     this.TestSelector(new ExponentialRankingSelector(rand), 5, 10000, 10001, 10002, 10003);
 }
コード例 #10
0
 public void StochasticUniversalSamplingTest4()
 {
     IRandom rand = new Rand();
     this.TestSelector(new StochasticUniversalSampling(rand), 2, Enumerable.Range(0, 100).Select(i => i / 100.0).ToArray());
 }
コード例 #11
0
 public void StochasticUniversalSamplingTest2()
 {
     IRandom rand = new Rand();
     this.TestSelector(new StochasticUniversalSampling(rand), 5, 0.1, 0.2, 0.3, 0.4);
 }
コード例 #12
0
 public void StochasticUniversalSamplingTest1()
 {
     IRandom rand = new Rand();
     this.TestSelector(new StochasticUniversalSampling(rand), 5, 10, 20, 30, 40);
 }
コード例 #13
0
        public void MutatorTest4()
        {
            Organism organism = new Organism();
            organism.Chromosomes.Add(new Chromosome(1, "10"));

            int runCount = 100000;
            double mutationProbability = 0;

            MutationCounter mutator = new MutationCounter();
            IRandom rand = new Rand();
            Mutator mutationManager = new Mutator(rand, mutationProbability);
            mutationManager.AddMutator(mutator);
            for (int i = 0; i <= runCount - 1; i++) {
                mutationManager.Mutate(organism);
            }

            Assert.AreEqual(0, mutator.MutationCount);
            Assert.AreEqual("10", organism.Chromosomes[0].ToString());
        }