Exemplo n.º 1
0
        public void CompatibilityDistanceTest_ToCopyOfSelf_Expected_0()
        {
            float      epsilon = 0.0001f;
            Simulation tmpSim  = new Simulation(r, gen1, 1);

            gen1.ParentSimulation = tmpSim;

            Genome genCopy = gen1.Copy();

            genCopy.ParentSimulation = tmpSim;

            Assert.IsTrue(gen1.CompatibilityDistance(genCopy) < epsilon);
            Assert.IsTrue(genCopy.CompatibilityDistance(gen1) < epsilon);
        }
Exemplo n.º 2
0
        public void CompatibilityDistanceTest_EmptyGenomes_Expected_0()
        {
            Genome gen1 = new Genome(r);
            Genome gen2 = new Genome(r);

            Simulation tmpSim = new Simulation(r, gen1, 1);

            gen1.ParentSimulation = tmpSim;
            gen2.ParentSimulation = tmpSim;

            float epsilon = 0.0001f;

            Assert.IsTrue(gen1.CompatibilityDistance(gen2) < epsilon);
            Assert.IsTrue(gen2.CompatibilityDistance(gen1) < epsilon);
        }
Exemplo n.º 3
0
        public void TestCrossover()
        {
            Simulation tmpSim = new Simulation(r, gen1, 1);

            gen1.ParentSimulation = tmpSim;
            gen2.ParentSimulation = tmpSim;

            float epsilon = 0.0001f;

            Assert.IsTrue(Math.Abs(gen1.CompatibilityDistance(gen2) - 5.04) < epsilon);
            Assert.AreEqual(5, Genome.MatchingGenesCount(gen1, gen2));
            Assert.AreEqual(2, Genome.ExcessGenesCount(gen1, gen2));
            Assert.AreEqual(3, Genome.DisjointGenesCount(gen1, gen2));
            Assert.IsTrue(Math.Abs(Genome.GetAverageWeightDifference(gen1, gen2) - 0.1) < epsilon);


            Console.WriteLine("\n\nCrossover:");
            gen1.Crossover(gen2, r).DebugPrint();
        }